ansible搭建mysql主主模式
連結:https://pan.baidu.com/s/18vdKcYUHxdOnZjayle_Fkw
提取碼:bmvo
複製這段內容後開啟百度網盤手機App,操作更方便哦
[
---
- hosts: web
tasks:
- name: 安裝mysql服務
yum: name={{ item }} state=installed
with_items:
- mysql
- mysql-server
- name: 分發配置檔案 主
copy: src=/root/my.cnf dest=/etc/my.cnf
when: ansible_machine_id == "0db24cc9ab3462952a8ded4f0000000c"
- name: 分發配置檔案 從
copy: src=/opt/my.cnf dest=/etc/my.cnf
when: ansible_machine_id == "a3a0f053e7d25013af92585f00000011"
- name: 啟動mysql
service: name=mysqld state=started
- name: 授權使用者
shell: mysql -e "grant all on *.* to 'tom'@'%' identified by '123'"
- name: 重新整理許可權
shell: mysql -e "flush privileges"
- name: 重置日誌
shell: mysql -e "reset master"
- name: 停止slave
shell: mysql -e "stop slave"
- name: 編寫日誌'152
shell: mysql -e"change master to master_host='192.168.220.169',
master_user='tom',master_password='123',
master_log_file='mysql-bin.000001',master_log_pos=106;"
when: ansible_machine_id == "a3a0f053e7d25013af92585f00000011" #判斷條件
- name: 編寫日誌'169
shell: mysql -e"change master to master_host='192.168.220.152',
master_user='tom',master_password='123',
master_log_file='mysql-bin.000001',master_log_pos=106;"
when: ansible_machine_id == "0db24cc9ab3462952a8ded4f0000000c" #判斷條件
- name: 停止slave
shell: mysql -e "start slave"
- name: 重啟msyql
service: name=mysqld state=restarted
- name: 關閉防火牆
service: name=iptables state=stopped
希望看到這篇文章的小夥伴給小編一個贊, (#^.^#)