ansible搭建mysql主主模式
ansible是新出現的自動化運維工具,基於Python開發,集合了眾多運維工具(puppet、cfengine、chef、func、fabric)等優點,實現了批量系統配置、批量程式部署、批量執行命令等功能。
ansible是基於模組工作的,本身沒有批量部署的能力。真正具有批量部署的是ansible所執行的模組,ansible只是提供一種框架。主要包括:
(1)、連線外掛connection plugins:負責和被監控端實現通訊;
(2)、host inventory:指定操作的主機,是一個配置檔案裡面定義監控的主機;
(3)、各種模組核心模組、command模組、自定義模組;
(4)、藉助於外掛完成記錄日誌郵件等功能;
(5)、playbook:劇本執行多個任務時,非必需可以讓節點一次性執行多個任務。
連結:https://pan.baidu.com/s/18vdKcYUHxdOnZjayle_Fkw
提取碼:bmvo
複製這段內容後開啟百度網盤手機App,操作更方便哦
基於centos7上的yum安裝ansible
基於centos6上安裝的SQL/">MySQL
接下來的時間我們編寫指令碼吧!!!!!!!!!!!!
my.cnf配置如下】
[mysqld]
server-id=1
log_bin=mysql-bin
relay_log=mysql-relay
儲存退出
/opt/my.cnf配置如下】】
[mysqld]
server-id=2
log_bin=mysql-bin
relay_log=mysql-relay
儲存退出
[root@localhost ~]# vim mysql.yaml
---
- 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
希望看到這篇文章的小夥伴給小編一個贊, (#^.^#)