Ansible-playbook automatic deployment of MySQL master-slave copy read/write separation

Source: Internet
Author: User

Directory Structure:ansible-mysql-replication├── group_vars│   ├── all│   ├──  mysql-proxy│   └── mysql-slave├── hosts├── mysql-replication.retry├──  mysql-replication.yml└── roles    ├── amoeba    │    ├── files    │   │   ├──  amoeba-mysql-3.0.5-rc-distribution.zip    │   │   └──  Jdk-7u79-linux-x64.tar.gz    │   ├── handlers    │    ├── tasks    │   │   ├──  Jdk-7u79-linux-x64.tar.gz    │   │   └── main.yaml     │   └── templates    │      ├── amoeba.xml    │     ├── dbservers.xml    │      ├── jvm.properties    │     └── profile     ├── base    │   ├── files    │    │   ├── epel-release-6-8.noarch.rpm    │    │   ├── epel-release-latest-7.noarch.rpm    │   │    └── remi-release-6.rpm    │   └── tasks     │       └── main.yaml    ├──  chpass    │   └── tasks    │        └── main.yaml    ├── mysql-master     │   ├── handlers    │   │   └── main.yaml     │   ├── tasks    │   │   └──  main.yaml    │   └── templates    │        └── server.cnf.j2    └── mysql-slave         ├── handlers        │    └── main.yaml        ├── tasks         │   └── main.yml         └── templates            └──  SERVER.CNF.J2MYSQL-REPLICATION.YML---- name: Base All Server  hosts:  All  remote_user: root  tags: base  roles:    - base- name:  install mysql-master and configure mysqlmaster  hosts: mysql-master   remote_user: root  tags: mysql-master  roles:    -  mysql-master- name: Install mysql-slave and start mysqlslave   Hosts: mysql-slave  remote_user: root  tags: mysql-slave  roles:     - mysql-slave- name: Install Amoeba and configure   hosts: mysql-proxy  remote_user: root  tags: mysql-proxy   roles:    - amoeba- name: chnage mysql root pass   hosts: mysql-master,mysql-slave  remote_user: root  tags: chpass   roles:  &nbsP; - MYSQL-CONFROLES/AMOEBA/TASKS/MAIN.YML---- name: install unzip  yum:  name=unzip state=installed- name: unzip Amobea and Jave Package   unarchive: src={{ item }} dest=/usr/local/  with_items:     - amoeba-mysql-3.0.5-rc-distribution.zip    - jdk-7u79-linux-x64.tar.gz   tags: unzip- name: copy  profile  template: src=profile  dest=/etc/profile  tags: copy- name: source profile  shell:  source /etc/profile- name: Copy Amoeba Template Configure File   template: src={{ item }} dest=/usr/local/amoeba-mysql-3.0.5-rc/conf/  with _items:    - dbservers.xml    - amoeba.xml- name:  copy amoeba jvm&nbsp configure file  template: src=jvm.properties dest=/usr/local/amoeba-mysql-3.0.5-rc/ jvm.properties- name: start amoeba  shell: /usr/local/amoeba-mysql-3.0.5-rc/bin/ Launcher &roles\base\tasks\main.yaml--- name: copy centos6&&crntos7 epel   copy: src={{ item }} dest=/opt/  with_items:   -  epel-release-6-8.noarch.rpm   - remi-release-6.rpm   -  Epel-release-latest-7.noarch.rpm- name: install elep for centos6  yum:  name=/opt/{{ item }} state=installed  with_items:   -  Epel-release-6-8.noarch.rpm   - remi-release-6.rpm  when: ansible_ distribution_major_version ==  "6"- name: install elep for centos6   yum: name=/opt/epel-release-latest-7.noarch.rpm state=installed  when: ansible_distribution_major_version ==  "7"-  name: install mariadb package  yum: name={{ item }} state= installed  with_items:    - mariadb-server    -  mysql    - mysql-python- name: create mariadb log file   file: path=/var/log/mysqld.log state=touch owner=mysql group=mysql mode=0755-  name: Create MariaDB PID directory  file: path=/var/run/mysqld  state=directory owner=mysql group=mysql mode=0755- name: start mariadb   service: name=mariadb state=started enabled=yes  when: ansible_ distribution_major_version ==  "7"- name: start mariadb  service: name= mysql state=started enabled=yes  when: ansible_distribution_major_version ==  "6"   roles\ Mysql-master\tasks\main.yaml- name: create mysql configure file  template:  src=server.cnf.j2 dest=/etc/my.cnf.d/server.cnf  notify:    -  restart mariadb#- name: change root login_password#  shell: /usr/bin/ mysqladmin -uroot  password  "MySQL"- name: create replication user   mysql_user: name={{ dbuser }} password={{ dbuserpass }}   priv=*.*:all host={{ item }} state=present  with_items:    -   '% '     -  ' localhost ' roles\mysql-master\handlers\main.yaml---- name:  Restart mariadb  service: name=mariadb state=started enabled=yes  when :  ansible_distribution_major_version ==  "7"- name: restart mariadb  service: name=mysql  state=started enabled=yes  when: ansible_distribution_major_version ==  "6" roles\ Mysql-slave\handlers\main.yaml---- NAME: RESTART MARIADB  SERVICE: NAME=MARIADB  state=started enabled=yes  when: ansible_distribution_major_version ==  "7" - name: restart mariadb  service: name=mysql state=started enabled=yes   when: ansible_distribution_major_version ==  "6" roles\mysql-slave\tasks\main.yml----  name: Create mysql configure file  template: src=server.cnf.j2  dest={{ mycnf_pwd }}  notify:    - restart mariadb-  name: get mysql-master status  mysql_replication: mode=getmaster   delegate_to:  "{{ master_host }} "   register: master- name: configure replication on the slave.   mysql_replication:        mode=changemaster         master_host={{ master_host }}         master_user={{ dbuser }}        master_ password={{ dbuserpass }}        master_log_file={{  Master. File }}        master_log_pos={{ master. position }}- name: start slave  mysql_replication:         mode=startslave        roles\mysql-conf\tasks\ main.yaml    --- name: create mysql-proxy user  mysql_user:  name={{ mysqluser }} password={{ mysqlpass }} priv=*.*:all,grant host={{ item }}  state=present  with_items:    -  '% '     -  ' localhost '  - name: Change master&slave mysql root password   shell: /usr/bin/mysqladmin -uroot  password  "{{ root_pass }}"      host:[mysql-master]172.17.0.2[mysql-slave]172.17.0.6[mysql-proxy]172.17.0.8 define the MySQL master server in the host file. From the server, as well as the forwarding server IP in templates put the profile template ansible-playbook -i host mysql-replication.yml complete script please visit https:// Github.com/chulinx/ansible-playbook/tree/master/ansible-mysql-replication


This article is from the "Technology House private Space" blog, please be sure to keep this source http://chulinx.blog.51cto.com/4098114/1842061

Ansible-playbook automatic deployment of MySQL master-slave copy read/write separation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.