MMM Cluster Architecture Overview
MMM (Master-Master replication managerfor Mysql, Mysql master-master replication manager) is a flexible set of scripts, perl based implementation that is used to monitor mysql replication and failover, and can manage the configuration mysql Master-Master replication ( only one node is writable).
MMM high availability architecture description
mmm_mond: monitoring process, is responsible for monitoring all work, decisions and deal with all nodes active role. This script needs to be run on the supervisor.
mmm_agentd: agent process running on each server mysql to complete the probe and perform simple work of monitoring distal service settings. This script needs to be run on a regulated machine.
mmm_control: a simple script, provide commands to manage mmm_mond process.
Regulated mysql-mmm end would provide a plurality of virtual IP (the VIP), the VIP comprises a writable, readable plurality of the VIP, by managing regulation, which is available on the IP binds mysql, when a station mysql dang when the machine, VIP regulators will migrate to other mysql.
Throughout the regulatory process, we need to add the relevant authorized user in mysql, mysql so that supervision can support the maintenance of machines. Authorized users include a user and a mmm_agent mmm_monitor user.
MMM advantages and disadvantages
Advantages: high availability, scalability, fault automatic switching occurs, the main primary synchronization, the database provides a write operation only at the same time, to ensure data consistency.
Disadvantage: Monitor node is a single point, may be combined Keepalived highly available, the host of the number required by the need to achieve separate read and write, the program is a challenge.
Test environment deployment
服务器角色 IP地址 代理名称 虚拟IP
主服务器1 192.168.142.131 db1 vip192.168.142.130
(master1)
主服务器2 192.168.142.134 db2
(master2)
从服务器1 192.168.142.130 db3 vip192.168.142.251,
192.168.142.252
(slave1)
从服务器2 192.168.142.135 db4
(slave2)
监控服务器 192.168.142.136
(monitor)
The first step: on four servers need to install the MySQL database
Configuring ALI cloud source, and then install epel-release source
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum clean all && yum makecache
2. Set up the local yum source
#安装数据库
[root@localhost ~]# yum -y install mariadb-server mariadb
#关闭防火墙和安全功能
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
#开启数据库
[root@localhost ~]# systemctl start mariadb.service
3. Modify the main configuration file ml
[root@localhost ~]# vim /etc/my.cnf
#删除前9行,添加以下内容
[mysqld]
log_error=/var/lib/mysql/mysql.err #错误日志的文件位置
log=/var/lib/mysql/mysql_log.log #访问日志的文件位置
log_slow_queries=/var/lib/mysql_slow_queris.log #man日志的文件位置
binlog-ignore-db=mysql,information_schema #mysql,information_schema不生成二进制日志文件
character_set_server=utf8 #字符集
log_bin=mysql_bin #二进制日志文件功能开启
server_id=1 #不同主机id不同
log_slave_updates=true #授权同步
sync_binlog=1 #二进制日志文件功能开启
auto_increment_increment=2 #自增量
auto_increment_offset=1 #起始值
[root@localhost ~]# systemctl restart mariadb.service
[root@localhost ~]# netstat -natp | grep 3306
4. Copy the configuration file to the other three database servers, pay attention to modify server_id
[root@localhost ~]# scp /etc/my.cnf [email protected]:etc/
5. access to the database, and view the log file information
[root@localhost ~]# mysql
#查看记录日志文件名称和位置值
MariaDB [(none)]> 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)
6. On the authority granted access to the m1 and m2 each other, and to authorize the synchronization log
#在m1和m2上互相授予访问的权限
MariaDB [(none)]> grant replication slave on *.* to 'replication'@'192.168.142.%' identified by '123456';
#在m1上指定m2的日志文件名和位置参数
MariaDB [(none)]> change master to master_host='192.168.142.134',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=245;
#在m2上指定m1的日志文件名和位置参数
MariaDB [(none)]> change master to master_host='192.168.142.131',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=245;
7. Turn sync on m1
MariaDB [(none)]> start slave;
8. View the synchronization status, two masters should see Yes
MariaDB [(none)]> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
9. Create a database on m1
MariaDB [(none)]> create database school;
10. Check the synchronization database on m2
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| test |
+--------------------+
5 rows in set (0.00 sec)
11. From the two do - pay attention to the log file and location parameters change (point m1)
MariaDB [(none)]> change master to master_host='192.168.142.131',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=245;
12. Turn sync
MariaDB [(none)]> start slave;
#在从服务器上查看同步数据信息
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| test |
+--------------------+
5 rows in set (0.00 sec)
13. MMM install software on four servers
[root@localhost ~]# yum -y install mysql-mmm*
14. The profile configuration mmm_common.conf
[root@localhost ~]# vim /etc/mysql-mmm/mmm_common.conf
<host default>
#修改网卡为ens33
cluster_interface ens33
pid_path /run/mysql-mmm-agent.pid
bin_path /usr/libexec/mysql-mmm/
replication_user replicantion
#修改授权密码
replication_password 123456
agent_user mmm_agent
#修改代理授权密码
agent_password 123456
</host>
#指定四台服务器的角色与IP地址
<host db1>
ip 192.168.142.131
mode master
peer db2
</host>
<host db2>
ip 192.168.142.134
mode master
peer db1
</host>
<host db3>
ip 192.168.142.130
mode slave
</host>
<host db4>
ip 192.168.142.135
mode slave
</host>
#设定主服务器虚拟IP
<role writer>
hosts db1, db2
ips 192.168.142.250
mode exclusive
</role>
#设定从服务器虚拟IP
<role reader>
hosts db3, db4
ips 192.168.142.251, 192.168.142.252
mode balanced
</role>
15. Copy the configuration file from the top to three other servers m1
[root@localhost ~]# scp mmm_common.conf/mmm_common.conf [email protected]:/etc/mysql-mmm/mmm_common.conf
[root@localhost ~]# scp mmm_common.conf/mmm_common.conf [email protected]:/etc/mysql-mmm/mmm_common.conf
[root@localhost ~]# scp mmm_common.conf/mmm_common.conf [email protected]:/etc/mysql-mmm/mmm_common.conf
Step Two: Configure monitor server monitor
1. Installation epel-release source associated software and MMM
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum clean all && yum makecache
[root@localhost ~]# yum -y install mysql-mmm*
2. Copy the configuration file from the top to the monitoring server m1
[root@localhost ~]# scp mmm_common.conf [email protected]:/etc/mysql-mmm/
3. Configure mmm_common.conf profile
[root@localhost ~]# vim /etc/mysql-mmm/mmm_mon.conf
<monitor>
ip 127.0.0.1
pid_path /run/mysql-mmm-monitor.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
#指向四台服务器的IP地址
ping_ips 192.168.142.131,192.168.142.134,192.168.142.130,192.168.142.135
auto_set_online 10
4. mmm_agent authorization on all the database server
MariaDB [(none)]> grant super, replication client, process on *.* to 'mmm_agent'@'192.168.142.%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
5. On all database servers authorized to mmm_moniter
MariaDB [(none)]> grant replication client on *.* to 'mmm_monitor'@'192.168.18.%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)
6. Refresh Database
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.02 sec)
7. Set agent name on all database servers
[root@localhost ~]# vim /etc/mysql-mmm/mmm_agent.conf #修改代理配置文件
#m1中默认名称
this db1
#m2中名称
this db2
#s1中名称
this db3
#s2中名称
this db4
8. Boot Agent feature on all database servers and set the boot from the start
#启动代理功能
[root@localhost ~]# systemctl start mysql-mmm-agent.service
#设置开机自启动
[root@localhost ~]# systemctl enable mysql-mmm-agent.service
9. Turn on the monitor server monitoring service
[root@localhost mysql-mmm]# systemctl start mysql-mmm-monitor.service
10. See the case where each node
[root@localhost ~]# mmm_control show
db1(192.168.142.131) master/ONLINE. Roles: writer(192.168.142.250)
db2(192.168.142.134) master/ONLINE. Roles:
db3(192.168.142.130) slave/ONLINE. Roles: reader(192.168.142.252)
db4(192.168.142.135) slave/ONLINE. Roles: reader(192.168.142.251)
11. All server status detection
[root@localhost ~]# mmm_control checks all
db4 ping [last change: 2019/11/25 18:23:03] OK
db4 mysql [last change: 2019/11/25 18:23:03] OK
db4 rep_threads [last change: 2019/11/25 18:23:03] OK
db4 rep_backlog [last change: 2019/11/25 18:23:03] OK: Backlog is null
db2 ping [last change: 2019/11/25 18:23:03] OK
db2 mysql [last change: 2019/11/25 18:59:01] OK
db2 rep_threads [last change: 2019/11/25 18:59:01] OK
db2 rep_backlog [last change: 2019/11/25 18:59:01] OK: Backlog is null
db3 ping [last change: 2019/11/25 18:23:03] OK
db3 mysql [last change: 2019/11/25 18:59:01] OK
db3 rep_threads [last change: 2019/11/25 18:59:01] OK
db3 rep_backlog [last change: 2019/11/25 18:59:01] OK: Backlog is null
db1 ping [last change: 2019/11/25 18:23:03] OK
db1 mysql [last change: 2019/11/25 18:59:01] OK
db1 rep_threads [last change: 2019/11/25 18:59:01] OK
db1 rep_backlog [last change: 2019/11/25 18:59:01] OK: Backlog is null
The third step: Failure Test
1. Analog m1 server goes down, stop the service
[root@localhost ~]# systemctl stop mariadb.service
2. When the server is down m1, m2 receive a virtual IP continue to provide services
[root@localhost ~]# mmm_control show
db1(192.168.142.131) master/ONLINE. Roles:
db2(192.168.142.134) master/ONLINE. Roles: writer(192.168.142.250)
db3(192.168.142.130) slave/ONLINE. Roles: reader(192.168.142.252)
db4(192.168.142.135) slave/ONLINE. Roles: reader(192.168.142.251)
3. Analog s1 server goes down, stop the service
[root@localhost ~]# systemctl stop mariadb.service
4. When the server is down s1, s2 continue to provide services received virtual IP
[root@localhost ~]# mmm_control show db1(192.168.142.131) master/ONLINE. Roles: writer(192.168.142.250)
db2(192.168.142.134) master/ONLINE. Roles:
db3(192.168.142.130) slave/HARD_OFFLINE. Roles:
db4(192.168.142.135) slave/ONLINE. Roles: reader(192.168.142.251), reader(192.168.142.252
5. On the m1 unauthorized access to server monitoring server address
MariaDB [(none)]> grant all on *.* to 'root'@'192.168.142.136' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
6. Install the database client on the Monitoring Server
[root@localhost ~]# yum -y install mariadb
7. Use a user logs into the database on the monitor server and create data
[root@localhost ~]# mysql -u root -p -h 192.168.142.250
Enter password:
#输入密码即可
#创建一个数据库
MariaDB [(none)]> create database BDQN;
Query OK, 1 row affected (0.01 sec)
8. synchronized in time to be able to view the data on all database information
MariaDB [(none)]> show databases; #查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| BDQN | #同步到的BDQN数据库
| mysql |
| performance_schema |
| school |
| test |
+--------------------+
6 rows in set (0.00 sec)