标签:col img exe 部分 last 配置 slave 恢复db 一致性
简介MMM(Master-Master replication manager for MySQL)是一套支持双主故障切换和双主日常管理的脚本程序。MMM使用Perl语言开发,主要用来监控和管理MySQL Master-Master(双主)复制,虽然叫做双主复制,但是业务上同一时刻只允许对一个主进行写入,另一台备选主上提供部分读服务,以加速在主主切换时刻备选主的预热,可以说MMM这套脚本程序一方面实现了故障切换的功能,另一方面其内部附加的工具脚本也可以实现多个slave的read负载均衡。
MMM提供了自动和手动两种方式移除一组服务器中复制延迟较高的服务器的虚拟ip,同时它还可以备份数据,实现两节点之间的数据同步等。由于MMM无法完全的保证数据一致性,所以MMM适用于对数据的一致性要求不是很高,但是又想最大程度的保证业务可用性的场景。对于那些对数据的一致性要求很高的业务,非常不建议采用MMM这种高可用架构。
MMM项目来自 Google:http://code.google.com/p/mysql-master-master
官方网站为:http://mysql-mmm.org
主机名 | 操作系统 | IP地址 | VIP地址 | 角色 |
---|---|---|---|---|
mysql-mmm服务器 | CentOS 7.0 x86_64 | 192.168.96.169 | ||
master01服务器 | CentOS 7.0 x86_64 | 192.168.96.166 | 192.168.96.170 | db1 |
master02服务器 | CentOS 7.0 x86_64 | 192.168.96.165 | 192.168.96.170 | db2 |
slave01服务器 | CentOS 7.0 x86_64 | 192.168.96.167 | 192.168.96.171 | db3 |
slave02服务器 | CentOS 7.0 x86_64 | 192.168.96.168 | 192.168.96.172 | db4 |
systemctl stop firewalld
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
yum -y install mariadb-server mariadb mysql-mmm*
vi /etc/my.cnf
[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
scp /etc/my.cnf root@192.168.96.165:/etc/
scp /etc/my.cnf root@192.168.96.167:/etc/
scp /etc/my.cnf root@192.168.96.168:/etc/
注意:分别修改mysql-master02、mysql-slave01、mysql-slave01的配置文件server_id参数
systemctl enable mariadb
systemctl start mariadb
mysql
show master status;
grant replication slave on *.* to ‘replication‘@‘192.168.96.%‘ identified by ‘123456‘;
change master to master_host=‘192.168.96.166‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=335;
start slave;
show slave status\G;
mysql
show master status;
grant replication slave on *.* to ‘replication‘@‘192.168.96.%‘ identified by ‘123456‘;
change master to master_host=‘192.168.96.165‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000001‘,master_log_pos=335;
start slave;
show slave status\G;
#master01服务器上创建数据库并去master02服务器上检查是否也有了该数据库
create database db_test;
mysql
change master to master_host=‘192.168.96.166‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000002‘,master_log_pos=335;
start slave;
show slave status\G;
slave01从服务器:
slave02从服务器:
#在任意一台主服务器上创建数据库,再去检查其他三台数据库是否同步了
create database db_01;
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
yum -y install mariadb-server mariadb mysql-mmm*
cd /etc/mysql-mmm/
vi mmm_common.conf
1 active_master_role writer
2
3 <host default>
4 cluster_interface ens33
5 pid_path /run/mysql-mmm-agent.pid
6 bin_path /usr/libexec/mysql-mmm/
7 replication_user replication
8 replication_password 123456
9 agent_user mmm_agent
10 agent_password 123456
11 </host>
12
13 <host db1>
14 ip 192.168.96.166
15 mode master
16 peer db2
17 </host>
18
19 <host db2>
20 ip 192.168.96.165
21 mode master
22 peer db1
23 </host>
24
25 <host db3>
26 ip 192.168.96.167
27 mode slave
28 </host>
29
30 <host db4>
31 ip 192.168.96.168
32 mode slave
33 </host>
34
35 <role writer>
36 hosts db1, db2
37 ips 192.168.96.170
38 mode exclusive
39 </role>
40
41 <role reader>
42 hosts db3, db4
43 ips 192.168.100.171, 192.168.100.172
44 mode balanced
45 </role>
scp mmm_common.conf root@192.168.96.165:/etc/mysql-mmm/ #master02服务器
scp mmm_common.conf root@192.168.96.166:/etc/mysql-mmm/ #master01服务器
scp mmm_common.conf root@192.168.96.167:/etc/mysql-mmm/ #slave01服务器
scp mmm_common.conf root@192.168.96.168:/etc/mysql-mmm/ #slave02服务器
cd /etc/mysql-mmm/
vi mmm_mon.conf
......
ping_ips 192.168.96.165, 192.168.96.166, 192.168.96.167, 192.168.96.168 #mysql数据库服务器地址
auto_set_online 10
......
<host default>
monitor_user mmm_monitor #监控机用户名
monitor_password 123456 #密码
</host>
systemctl start mysql-mmm-monitor
grant super, replication client, process on *.* to ‘mmm_agent‘@‘192.168.96.%‘ identified by ‘123456‘;
grant replication client on *.* to ‘mmm_monitor‘@‘192.168.96.%‘ identified by ‘123456‘;
flush privileges;
vi /etc/mysql-mmm/mmm_agent.conf
#重要提醒:按顺序分别修改其他MySQL服务器为db2、db3、db4
this db1
systemctl enable mysql-mmm-agent
systemctl start mysql-mmm-agent
mmm_control show
db1(192.168.96.166) master/ONLINE. Roles: writer(192.168.96.170)
db2(192.168.96.165) master/ONLINE. Roles:
db3(192.168.96.167) slave/ONLINE. Roles: reader(192.168.100.172)
db4(192.168.96.168) slave/ONLINE. Roles: reader(192.168.100.171)
mmm_control checks all
db4 ping [last change: 2018/07/12 00:09:29] OK
db4 mysql [last change: 2018/07/11 22:15:13] OK
db4 rep_threads [last change: 2018/07/11 22:05:28] OK
db4 rep_backlog [last change: 2018/07/11 22:05:28] OK: Backlog is null
db2 ping [last change: 2018/07/11 22:05:28] OK
db2 mysql [last change: 2018/07/11 22:05:28] OK
db2 rep_threads [last change: 2018/07/11 22:05:28] OK
db2 rep_backlog [last change: 2018/07/11 22:05:28] OK: Backlog is null
db3 ping [last change: 2018/07/11 22:05:28] OK
db3 mysql [last change: 2018/07/11 22:13:59] OK
db3 rep_threads [last change: 2018/07/11 22:05:28] OK
db3 rep_backlog [last change: 2018/07/11 22:05:28] OK: Backlog is null
db1 ping [last change: 2018/07/11 22:05:28] OK
db1 mysql [last change: 2018/07/11 22:14:54] OK
db1 rep_threads [last change: 2018/07/11 22:05:28] OK
db1 rep_backlog [last change: 2018/07/11 22:05:28] OK: Backlog is null
mmm_control move_role writer db2
systemctl stop mariadb
mmm_control show
db1(192.168.96.166) master/HARD_OFFLINE. Roles:
db2(192.168.96.165) master/ONLINE. Roles: writer(192.168.96.170)
db3(192.168.96.167) slave/ONLINE. Roles: reader(192.168.100.172)
db4(192.168.96.168) slave/ONLINE. Roles: reader(192.168.100.171)
这里db1的虚拟ip地址已经漂移到 了db2上
systemctl stop mariadb
mmm_control show
db1(192.168.96.166) master/HARD_OFFLINE. Roles:
db2(192.168.96.165) master/ONLINE. Roles: writer(192.168.96.170)
db3(192.168.96.167) slave/HARD_OFFLINE. Roles:
db4(192.168.96.168) slave/ONLINE. Roles: reader(192.168.100.171), reader(192.168.100.172)
mmm_control show
db1(192.168.96.166) master/ONLINE. Roles:
db2(192.168.96.165) master/ONLINE. Roles: writer(192.168.96.170)
db3(192.168.96.167) slave/ONLINE. Roles: reader(192.168.100.171)
db4(192.168.96.168) slave/ONLINE. Roles: reader(192.168.100.172)
这里注意,当db1服务器恢复,并不会抢占vip地址,而是作为备用机在等待着,好了,写到这里结束了。
标签:col img exe 部分 last 配置 slave 恢复db 一致性
原文地址:http://blog.51cto.com/10316297/2141175