- 配置主主複製(m1和m2兩台主伺服器互相同步)
查看對方的記錄檔名稱和位移值
mysql> show master status;
主伺服器互相提升存取權限(m1、m2伺服器分別執行)
# mysql-m1grant replication slave on *.* to ‘replication‘@‘172.168.100.%‘ identified by ‘123456‘;# 使用賬戶為replication 密碼為123456change master to master_host=‘172.168.100.201‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000003‘,master_log_pos=245;# 當在MariaDB-m1上執行時,master_host地址為MariaDB-m2地址···# mysql-m2grant replication slave on *.* to ‘replication‘@‘172.168.100.%‘ identified by ‘123456‘;change master to master_host=‘172.168.100.200‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000003‘,master_log_pos=245;# 當在MariaDB-m2上執行時,master_host地址為MariaDB-m1地址
開啟同步,查看伺服器的主從狀態
start slave;show slave status\G;# Slave_IO_Running: Yes# Slave_SQL_Running: Yes
配置m3、m4伺服器作為從伺服器
show master status;# 查看m1伺服器的記錄檔以及位移值(注意記錄檔和位移值的改變)# m1和m2互相同步,在此只需執行m1即可change master to master_host=‘172.168.100.200‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000004‘,master_log_pos=245;# m3和m4上分別執行
分別查看m3和m4的主從狀態
start slave;show slave status\G;# Slave_IO_Running: Yes# Slave_SQL_Running: Yes
安裝配置MMM架構
前面我們使用wget配置了ALI雲源並簡易安裝 MariaDB 來代替 MySQL ,並搭建了主主同步,主從複製以便完成實驗,現在我們來完成MMM架構
安裝mysql-mmm,修改設定檔(五台主機配置相同)
# yum -y install mysql-mmm* //前面我們配置了epel源,直接yum安裝# vim /etc/mysql-mmm/mmm_common.conf //配置如下active_master_role writer<host default>cluster_interface ens33pid_path /run/mysql-mmm-agent.pidbin_path /usr/libexec/mysql-mmm/replication_user replicationreplication_password 123456agent_user mmm_agentagent_password 123456</host><host db1>ip 172.168.100.200mode masterpeer db2</host><host db2>ip 172.168.100.201mode masterpeer db1</host><host db3>ip 172.168.100.202mode slave</host><host db4>ip 172.168.100.203mode slave</host><role writer>hosts db1, db2ips 172.168.100.100mode exclusive</role><role reader>hosts db3, db4ips 172.168.100.101, 172.168.100.102mode balanced</role>
快速為其他主機修改設定檔
scp mmm_common.conf [email protected]:/etc/mysql-mmm/scp mmm_common.conf [email protected]:/etc/mysql-mmm/scp mmm_common.conf [email protected]:/etc/mysql-mmm/scp mmm_common.conf [email protected]:/etc/mysql-mmm/
在主機上修改mmm_agent.conf檔案的名稱
# vim /etc/mysql-mmm/mmm_agent.confthis db1 //按照規劃分別修改為db1、db2、db3、db4
在所有主機上對mmm_agent、mmm_moniter進行授權
mysql> grant super, replication client, process on *.* to ‘mmm_agent‘@‘192.168.100.%‘ identified by ‘123456‘;mysql> grant replication client on *.* to ‘mmm_monitor‘@‘192.168.100.%‘ identified by ‘123456‘;# flush privileges; //重新載入許可權表
配置監控主機(在mysql-monitor上配置)
# vim /etc/mysql-mmm/mmm_mon.confinclude mmm_common.conf<monitor>ip 127.0.0.1pid_path /run/mysql-mmm-monitor.pidbin_path /usr/libexec/mysql-mmmstatus_path /var/lib/mysql-mmm/mmm_mond.statusping_ips 172.168.100.200,172.168.100.201,172.168.100.202,172.168.100.203auto_set_online 10 #上線時間修改為10s# The kill_host_bin does not exist by default, though the monitor will# throw a warning about it missing. See the section 5.10 "Kill Host# Functionality" in the PDF documentation.## kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host#</monitor><host default>monitor_user mmm_monitormonitor_password 123456</host>debug 0
關閉防火牆及增強×××
systemctl disable firewalld.servicesystemctl stop firewalld.servicesetenforce 0
- 啟動服務,查看各節點狀態
systemctl start mysql-mmm-monitor.service# ERROR: Can‘t connect to monitor daemon!,如若出現報錯,可嘗試重啟服務解決mmm_control check all# 檢查監控伺服器對所有主機的監控是否完善# 檢查結果全部OK,則部署完成
至此,MySQL-MMM已經部署成功,進一步的話,我們可以結合Amoeba實現讀寫分離,Writer 的虛擬VIP可以寫入資料庫,而 Reader 可以用來讀取資料。並通過Keepalived對 monitor 伺服器進行雙機熱備。