This article describes the principles and program structures MMM MMM architecture. MMM scheme does not apply to data consistency demanding business. Following up learning to learn.
Let's look at the specific architecture topology, as follows:
among them,
Roles | Hosts | IP addresses | Application Properties | VIP |
---|---|---|---|---|
master1 | master | 192.168.142.135 | write | 192.168.142.188 |
master2 | backup | 192.168.142.132 | write|read | 192.168.142.188 |
slave1 | slave | 192.168.142.136 | read | 192.168.142.200, 192.168.142.210 |
slave2 | slave | 192.168.142.137 | read | 192.168.142.200, 192.168.142.210 |
monitor | monitor | 192.168.142.143 | moitor | No VIP |
The configuration procedure
First, the test environment configuration
ALI source cloud configuration (if installed skippable)
Here master1 to a demonstration of the actual need to install all five
[root@master1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@master1 ~]# yum -y install epel-release
[root@master1 ~]# yum clean all && yum makecache
To all the main MySQL installation from the server, and configure
[root@master1 ~]# yum install mysql -y
[root@master1 ~]# vim /etc/my.cnf #修改配置文件
##server id不能一样
server-id =
log-bin = zhu-bin
log-slave-updates = ture ##开启主从同步
sync_binlog = 1 ##二进制文件立即写入
auto_increment_increment=2 ###增量为2
auto_increment_offset=1 ###### 起始值为1
[root@master1 ~]# systemctl restart mysqld
[root@master1 ~]# systemctl enable mysqld
Second, the configuration of the main primary synchronization (two master copy each other, each flat stage)
m1 m2 to give permission from the rights from m1, m2
[root@master1 ~]# mysql -u root -p
grant replication slave on *.* to 'myslave'@'192.168.142.%' identified by 'asd123';
#允许从服务器使用myslave账户在主服务器上进行复制操作(两台主均要授权)
show master status;
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000001 | 245 | | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
#查看作为主服务器的信息,关键点为position号码
change master to master_host='主服务器地址',master_user='myslave',master_password='asd123',master_log_file='File',master_log_pos=position号码;
##授予权限(m1为m2的主,m2为m1的主)
start slave;
show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
#查看作为从服务器的信息,是否同步开启
Third, the master-slave synchronization (both refer to the same station from the master station a)
Two points from a server configuration master1
[root@slave1 ~]# vim /etc/my.cnf
server-id = 6 #不能有相同的
log-bin=mysql-bin
log-slave-updates=ture
sync_binlog = 1
[root@slave1 ~]# systemctl restart mysqld
[root@slave1 ~]# netstat -atnp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 38831/mysqld
#提权,指向master1(两台从操作相同!!!!!)
[root@slave1 ~]# mysql -uroot -p
change master to master_host='主服务器地址',master_user='myslave',master_password='asd123',master_log_file='主服务器查看到的信息',master_log_pos=号码;
##授予权限(slave1、slave2为master1的从)
start slave;
show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
#查看作为从服务器的信息,是否同步开启
Fourth, all the servers installed and configured MMM
Mmm_common modify configuration files
[root@master1 ~]# yum -y install mysql-mmm*
#修改MMM配置文件
[root@master1 ~]# vim /etc/mysql-mmm/mmm_common.conf
cluster_interface ens33
......
replication_user myslave #从服务器访问主服务器账户
replication_password asd123
agent_user mmm_user #MMM用户账户
agent_password 123123
<host db1>
ip 192.168.142.135 #master1的IP地址
mode master
peer db2
</host>
<host db2>
ip 192.168.142.132 #master2的IP地址
mode master
peer db1
</host>
<host db3>
ip 192.168.142.136 #slave1的IP地址
mode slave
</host>
<host db4>
ip 192.168.142.137 #slave2的IP地址
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.142.188 ###VIP虚拟IP地址
mode exclusive
</role>
<role reader>
hosts db3, db4
ips 192.168.142.200, 192.168.142.210 ###VIP虚拟IP地址
mode balanced
</role>
#scp远程复制,将配置远程推送
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf [email protected]:/etc/mysql-mmm/
Mmm_monitor modify configuration files (monitor monitor end only)
[root@localhost ~]# vim /etc/mysql-mmm/mmm_mon.conf
<monitor>
......
ping_ips 192.168.142.135,192.168.142.132,192.168.142.136,192.168.142.137 #所有主从服务器IP地址
auto_set_online 5
#等待上线时间
<host default>
monitor_user mmm_monitor ##创建监控用户
monitor_password 123123
</host>
For lifting weights from the database (MMM user, user monitoring) in all primary
[root@master1 ~]# mysql -u root -p
grant super,replication client,process on *.* to 'mmm_user'@'192.168.142.%' identified by '123123';
grant replication client on *.* to 'mmm_monitor'@'192.168.142.%' identified by '123123';
flush privileges
##每台主从都要提权
Agant modify the configuration file (from each of the main modifications to be)
position:/etc/mysql-mmm/mmm_agent.conf
[root@master1 ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db1(对应的角色)
Fifth, open service
All the main services from a server to open mmm_agant
[root@master1 ~]# systemctl start mysql-mmm-agent.service
[root@master1 ~]# systemctl enable mysql-mmm-agent.service
Monitoring client service open mmm_monitor
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start mysql-mmm-monitor.service
[root@localhost ~]# mmm_control show ##查看监控状态
Sixth, the verification result
[root@localhost mysql-mmm]# mmm_control show
db1(192.168.142.135) master/ONLINE. Roles: writer(192.168.18.250)
db2(192.168.142.132) master/ONLINE. Roles:
db3(192.168.142.136) slave/ONLINE. Roles: reader(192.168.18.251)
db4(192.168.142.137) slave/ONLINE. Roles: reader(192.168.18.252)
//利用命令调整虚拟IP切换至master2:
[root@localhost mysql-mmm]# mmm_control move_role writer db2
OK: Role 'writer' has been moved from 'db1' to 'db2'. Now you can wait some time and check new roles info!
[root@localhost mysql-mmm]# mmm_control show
db1(192.168.142.135) master/ONLINE. Roles:
db2(192.168.142.132) master/ONLINE. Roles: writer(192.168.18.250)
db3(192.168.142.136) slave/ONLINE. Roles: reader(192.168.18.251)
db4(192.168.142.137) slave/ONLINE. Roles: reader(192.168.18.252)
//检测所有状态是否都正常:
[root@localhost mysql-mmm]# mmm_control checks all
db4 ping [last change: 2019/11/25 15:25:54] OK
db4 mysql [last change: 2019/11/25 15:25:54] OK
db4 rep_threads [last change: 2019/11/25 15:25:54] OK
db4 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null
db2 ping [last change: 2019/11/25 15:25:54] OK
db2 mysql [last change: 2019/11/25 15:25:54] OK
db2 rep_threads [last change: 2019/11/25 15:25:54] OK
db2 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null
db3 ping [last change: 2019/11/25 15:25:54] OK
db3 mysql [last change: 2019/11/25 15:25:54] OK
db3 rep_threads [last change: 2019/11/25 15:25:54] OK
db3 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null
db1 ping [last change: 2019/11/25 15:25:54] OK
db1 mysql [last change: 2019/11/25 15:25:54] OK
db1 rep_threads [last change: 2019/11/25 15:25:54] OK
db1 rep_backlog [last change: 2019/11/25 15:25:54] OK: Backlog is null