您好,登錄后才能下訂單哦!
MMM( Master- Master replication manager for MYSQL, MYSQL主主復制管理器)
是一套支持雙主故障切換和雙主日常管理的腳本程序。MMM使用Perl語言開發,主要用來監控和管理 MYSQL master-master(雙主)復制,雖然叫做雙主復制,但是業務上同一時刻只允許對一個主進行寫入,另一臺備選主上提供部分讀服務,以加速在主主切換時備選主的預熱,可以說MMM這套腳本程序一方面實現了故障切換的功能
另一方面其內部附加的工具腳本也可以實現多個 Slave的read負載均衡。
4臺安裝mysql5.7服務的設備
1臺用來安裝mmm的centos7設備
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下面的內容
[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
-------沒有問題后,把配置文件復制到其它3臺數據庫服務器上并啟動服務器-----
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) ##記錄日志文件名稱和 位置值,在兩臺主上查看。
----在m1上為m2授予從的權限,在m2上也要為m1授予從的權限---
grant replication slave on *.* to 'replication'@'192.168.100.%' identified by '123456'; ##兩臺主服務器都執行,從服務器不需要
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上的日志文件名,和位置參數-----在m2上要反過來。
start slave;
show slave status;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
-------在另一臺主上做----要指定m1的日志和位置參數---
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
在所有服務器上安裝-----注意,epel源要配置好
yum -y install mysql-mmm*
cd /etc/mysql-mmm/
vi mmm_common.conf ##所有主機上都要配置,直接復制多份
<host default>
cluster_interface ens33
……
replication_user replication
replication_password 123456
agent_user mmm_agent
agent_password 123456
<host db1>
ip 192.168.100.100
mode master
peer db2
</host>
<host db2>
ip 192.168.100.101
mode master
peer db1
</host>
<host db3>
ip 192.168.100.102
mode slave
</host>
<host db4>
ip 192.168.100.103
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.100.200
mode exclusive
</role>
<role reader>
hosts db3, db4
ips 192.168.100.201, 192.168.100.202
mode balanced
</role>
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/ ## 復制給mysql服務器
------------------在monitor服務器上配置----
cd /etc/mysql-mmm/ //改密碼
vi mmm_mon.conf
<host default>
monitor_user mmm_monitor
monitor_password 123456
</host>
--------------在所有數據庫上為mmm_agent授權-----
grant super, replication client, process on *.* to 'mmm_agent'@'192.168.100.%' identified by '123456';
--------------在所有數據庫上為mmm_moniter授權-----
grant replication client on *.* to 'mmm_monitor'@'192.168.100.%' identified by '123456';
flush privileges;
---------------修改所有數據庫的mmm_agent.conf----
vi /etc/mysql-mmm/mmm_agent.conf
this db1 ##主1 主2 從1 從2 分別為 db{1,2,3,4}
--------------在所有數據庫服務器上啟動mysql-mmm-agent---
systemctl start mysql-mmm-agent.service
systemctl enable mysql-mmm-agent.service
------------------在monitor服務器上配置------
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 ##數據庫服務器地址
auto_set_online 10
systemctl start mysql-mmm-monitor.service ##啟動mysql-mmm-monitor
mmm_control show ##查看各節點的情況
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 ##手動轉換角色
關掉主1 的mysql服務
systemctl stop mysqld
mmm_control show ##查看各節點的情況
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)
關掉從1的mysql服務
mmm_control show ##查看各節點的情況
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)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。