MMM( Master- Master replication manager for MYSQL, MYSQL主主復(fù)制管理器)
是一套支持雙主故障切換和雙主日常管理的腳本程序。MMM使用Perl語言開發(fā),主要用來監(jiān)控和管理 MYSQL master-master(雙主)復(fù)制,雖然叫做雙主復(fù)制,但是業(yè)務(wù)上同一時(shí)刻只允許對(duì)一個(gè)主進(jìn)行寫入,另一臺(tái)備選主上提供部分讀服務(wù),以加速在主主切換時(shí)備選主的預(yù)熱,可以說MMM這套腳本程序一方面實(shí)現(xiàn)了故障切換的功能
另一方面其內(nèi)部附加的工具腳本也可以實(shí)現(xiàn)多個(gè) Slave的read負(fù)載均衡。
4臺(tái)安裝mysql5.7服務(wù)的設(shè)備
1臺(tái)用來安裝mmm的centos7設(shè)備
systemctl stop firewalld.service
setenforce 0
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release
yum clean all && yum makecache
vim /etc/my.cnf
修改mysqld下面的內(nèi)容
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
systemctl restart mysqld
-------沒有問題后,把配置文件復(fù)制到其它3臺(tái)數(shù)據(jù)庫服務(wù)器上并啟動(dòng)服務(wù)器-----
scp /etc/my.cnf root@192.168.100.101:/etc/
scp /etc/my.cnf root@192.168.100.102:/etc/
scp /etc/my.cnf root@192.168.100.103:/etc/
-----注意:配置文件中的server_id 要修改-----
show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000002 | 339 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec) ##記錄日志文件名稱和 位置值,在兩臺(tái)主上查看。
----在m1上為m2授予從的權(quán)限,在m2上也要為m1授予從的權(quán)限---
grant replication slave on *.* to 'replication'@'192.168.100.%' identified by '123456'; ##兩臺(tái)主服務(wù)器都執(zhí)行,從服務(wù)器不需要
change master to master_host='192.168.100.101',master_user='replication',master_password='123456',master_log_file='mysql_bin.000002',master_log_pos=339;
-----注意,在m1上要指定m2上的日志文件名,和位置參數(shù)-----在m2上要反過來。
start slave;
show slave status;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
-------在另一臺(tái)主上做----要指定m1的日志和位置參數(shù)---
change master to master_host='192.168.100.100',master_user='replication',master_password='123456',master_log_file='mysql_bin.000002',master_log_pos=339;
start slave;
show slave status;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
change master to master_host='192.168.100.100',master_user='replication',master_password='123456',master_log_file='mysql_bin.000002',master_log_pos=339;
start slave;
show slave status;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
在所有服務(wù)器上安裝-----注意,epel源要配置好
yum -y install mysql-mmm*
cd /etc/mysql-mmm/
vi mmm_common.conf ##所有主機(jī)上都要配置,直接復(fù)制多份
cluster_interface ens33
……
replication_user replication
replication_password 123456
agent_user mmm_agent
agent_password 123456
ip 192.168.100.100
mode master
peer db2
ip 192.168.100.101
mode master
peer db1
ip 192.168.100.102
mode slave
ip 192.168.100.103
mode slave
hosts db1, db2
ips 192.168.100.200
mode exclusive
hosts db3, db4
ips 192.168.100.201, 192.168.100.202
mode balanced
scp mmm_common.conf root@192.168.100.100:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.100.101:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.100.102:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.100.103:/etc/mysql-mmm/ ## 復(fù)制給mysql服務(wù)器
------------------在monitor服務(wù)器上配置----
cd /etc/mysql-mmm/ //改密碼
vi mmm_mon.conf
monitor_user mmm_monitor
monitor_password 123456
--------------在所有數(shù)據(jù)庫上為mmm_agent授權(quán)-----
grant super, replication client, process on *.* to 'mmm_agent'@'192.168.100.%' identified by '123456';
--------------在所有數(shù)據(jù)庫上為mmm_moniter授權(quán)-----
grant replication client on *.* to 'mmm_monitor'@'192.168.100.%' identified by '123456';
flush privileges;
---------------修改所有數(shù)據(jù)庫的mmm_agent.conf----
vi /etc/mysql-mmm/mmm_agent.conf
this db1 ##主1 主2 從1 從2 分別為 db{1,2,3,4}
--------------在所有數(shù)據(jù)庫服務(wù)器上啟動(dòng)mysql-mmm-agent---
systemctl start mysql-mmm-agent.service
systemctl enable mysql-mmm-agent.service
------------------在monitor服務(wù)器上配置------
cd /etc/mysql-mmm/
vi mmm_mon.conf
……
ping_ips 192.168.100.100,192.168.100.101,192.168.100.102,192.168.100.103 ##數(shù)據(jù)庫服務(wù)器地址
auto_set_online 10
systemctl start mysql-mmm-monitor.service ##啟動(dòng)mysql-mmm-monitor
mmm_control show ##查看各節(jié)點(diǎn)的情況
db1(192.168.100.100) master/ONLINE. Roles: writer(192.168.100.200)
db2(192.168.100.101) master/ONLINE. Roles:
db3(192.168.100.102) slave/ONLINE. Roles: reader(192.168.100.201)
db4(192.168.100.103) slave/ONLINE. Roles: reader(192.168.100.202)
mmm_control checks all ## 需要各種OK
mmm_control move_role writer db1 ##手動(dòng)轉(zhuǎn)換角色
關(guān)掉主1 的mysql服務(wù)
systemctl stop mysqld
mmm_control show ##查看各節(jié)點(diǎn)的情況
db1(192.168.100.100) master/HARD_OFFLINE. Roles:
db2(192.168.100.101) master/ONLINE. Roles: writer(192.168.100.200)
db3(192.168.100.102) slave/ONLINE. Roles: reader(192.168.100.201)
db4(192.168.100.103) slave/ONLINE. Roles: reader(192.168.100.202)
關(guān)掉從1的mysql服務(wù)
mmm_control show ##查看各節(jié)點(diǎn)的情況
db1(192.168.100.100) master/HARD_OFFLINE. Roles:
db2(192.168.100.101) master/ONLINE. Roles: writer(192.168.100.200)
db3(192.168.100.102) slave/HARD_OFFLINEE. Roles:
db4(192.168.100.103) slave/ONLINE. Roles: reader(192.168.100.201,192.168.100.202)
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。