MMM high availability architecture

MMM high availability architecture

MMM (Master-Master replication manager for MySQL) is a set of master failover support for dual dual master script and daily management. MMM use Perl language development, is mainly used to monitor and manage MySQL Master-Master (double master) copy, it can be said to mysql master-master replication manager. Although called a dual-master replication, but on the same time services allow only one master write, to provide services on another portion of the read main Alternatively, to accelerate the switching of the main preheating time in the main main Alternatively, it can be said that MMM set of scripts on the one hand to achieve a failover capabilities, on the other hand inside additional tool scripts can also be achieved read load balancing of multiple slave. About mysql master-master replication configuration monitoring, failover and management of a scalable suite script (only one node can be written at any time), the kit can also be from any number of configurations from the standard of living in the home read server load balancing, so you can use it to a group of servers in virtual ip start living copy, in addition, it has achieved a script re-synchronization of backup data between the nodes.


 MMM提供了自动和手动两种方式移除一组服务器中复制延迟较高的服务器的虚拟ip,同时它还可以备份数据,实现两节点之间的数据同步等。由于MMM无法完全的保证数据一致性,所以MMM适用于对数据的一致性要求不是很高,但是又想最大程度的保证业务可用性的场景。MySQL本身没有提供replication failover的解决方案,通过MMM方案能实现服务器的故障转移,从而实现mysql的高可用。对于那些对数据的一致性要求很高的业务,非常不建议采用MMM这种高可用架构。

MMM Chart:

MMM high availability architecture

MMM this mode, master, slaver die easily controlled, two to two
MHA mode, high scalability, a dual standby master, a zone. A dual standby master and then expanded, a region
required to install node

First, we opened five virtual machines, do the planning

1 192.168.136.191 db1 master server
the master server 2 192.168.136.168 db2
from the server 1 192.168.136.185 db3
from the server 2 192.168.136.184 db4
monitoring server 192.168.136.135

Configuring Ali cloud sources. Each server must be installed

wget -O /etc/yum.repos.d/CentOS-Base.repo httP://mirrors.aliyun.com/repo/Centos-7.repo

Installation epel-release source, each server must be installed

yum -y install epel-release

yum clean all && yum makecache

YUM build local sources, all servers to be fitted, in addition to monitoring server


yum install mariadb-server mariadb -y`

Modifying the master configuration file, the other four out monitoring server must be modified. Copy and paste on the line.

vim /etc/my.cnf

9dd

[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queries.log
binlog-ignore-db=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

Each server must be shut firewall, enhanced functions, open database

systemctl stop firewalld.service 
setenforce 0
systemctl start mariadb.service 
[root@localhost ~]# mysql #进入M1数据库

 进入M1服务器查看日志文件的名称和位置值
MariaDB [(none)]> show master status; #查看日志文件的名称和位置值
+------------------+----------+--------------+--------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000003 |      245 |              | mysql,information_schema |
+------------------+----------+--------------+--------------------------+

M2 server view into the log file name and location value

MariaDB [(none)]> show master status;
+------------------+----------+--------------+--------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000003 |      245 |              | mysql,information_schema |
+------------------+----------+--------------+--------------------------+

Two masters perform, give permission

grant replication slave on *.* to 'replication'@'192.168.136.%' identified by '123456';`

M1 M2 server to the server address, the log file name, location parameters


change master to master_host='192.168.136.168',master_user='relication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;

M1 M2 server to the server address, the log file name, location parameters

change master to master_host='192.168.136.167',master_user='relication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
#两台服务器都执行开启同步数据
MariaDB [(none)]> slave start;

#两台主服务器都执行,查看同步数据的状态
MariaDB [(none)]> show slave status\G;
#看到下面的IO线程和状态都是YES就是正确了
 Slave_IO_Running: Yes
 Slave_SQL_Running: Yes
#我们测试一下两个主服务器是否能同步数据
M1创建数据一个数据库
MariaDB [(none)]> create database myschool;
Query OK, 1 row affected (0.00 sec)

M2
MariaDB [(none)]> show databases; 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myschool           |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

------------------------------------------ synchronize data from the server ---- -----------------------------------

#s1和s2从服务器
[root@localhost ~]# mysql
#都指向M1主服务器的地址,日志文件和参数
MariaDB [(none)]> change master to master_host='192.168.136.191',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245;
#在M1创建一个数据库
MariaDB [(none)]> create database school;
Query OK, 1 row affected (0.00 sec)
#其他三台服务器都有这个数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| school             |
| test               |
+--------------------+

#所有服务器都要装
yum -y install mysql-mmm*

#到第一台主服务器开始配置
[root@localhost ~]# cd /etc/mysql-mmm/
[root@localhost mysql-mmm]# ls
mmm_agent.conf  mmm_common.conf  mmm_mon.conf  mmm_mon_log.conf  mmm_tools.conf
[root@localhost mysql-mmm]# vim mmm_common.conf 

<host default>
    cluster_interface       ens33
    pid_path                /run/mysql-mmm-agent.pid
    bin_path                /usr/libexec/mysql-mmm/
    replication_user        replication
    replication_password    123456
    agent_user              mmm_agent
    agent_password          123456
</host>

<host db1>
    ip      192.168.136.191
    mode    master
    peer    db2
</host>

<host db2>
    ip      192.168.136.168
    mode    master
    peer    db1
</host>

<host db3>
    ip      192.168.136.185
    mode    slave
</host>

<host db4>
    ip      192.168.136.184
    mode    slave
</host>

<role writer>
    hosts   db1, db2
    ips     192.168.136.200 #虚拟地址
    mode    exclusive
</role>

<role reader>
    hosts   db3, db4
    ips     192.168.136.210, 192.168.136.220  #虚拟地址
    mode    balanced

With scp the file passed to other servers

scp mmm_common.conf [email protected]:/etc/mysql-mmm/
scp mmm_common.conf [email protected]:/etc/mysql-mmm/
scp mmm_common.conf [email protected]:/etc/mysql-mmm/
scp mmm_common.conf [email protected]:/etc/mysql-mmm/

Configuring Monitoring Server account

[root@localhost mysql-mmm]# vim mmm_mon.conf 

ping_ips            192.168.136.191,192.168.136.168,192.168.136.185,192.168.136.184 输入你所有的地址
    auto_set_online     10  #自带上线时间为10s

monitor_password    123456  #修改密码为123456

在所有数据库给mmm_agent授权

grant super, replication client, process on *.* to 'mmm_agent'@'192.168.136.%' identified by '123456';

grant replication client on *.* to 'mmm_monitor'@'192.168.136.%' identified by '123456';

Corresponding to modify the configuration file (M2, S1, S2)

[root@localhost mysql-mmm]# vim mmm_agent.conf
this db2
this db3
this db4

systemctl start mysql-mmm-agent.service 
systemctl enable mysql-mmm-agent.service

#回到监控服务器
systemctl start mysql-mmm-monitor.service 

View the situation of each node

[root@localhost mysql-mmm]# mmm_control show
  db1(192.168.136.191) master/ONLINE. Roles: writer(192.168.136.200)
  db2(192.168.136.168) master/ONLINE. Roles: 
  db3(192.168.136.185) slave/ONLINE. Roles: reader(192.168.136.220)
  db4(192.168.136.184) slave/ONLINE. Roles: reader(192.168.136.210)

#更改绑定的虚拟地址
[root@localhost mysql-mmm]# mmm_control move_role writer db2
#测试监控服务器功能是否完善

[root@localhost mysql-mmm]# mmm_control checks all
db4  ping         [last change: 2019/11/25 16:38:25]  OK
db4  mysql        [last change: 2019/11/25 16:38:25]  OK
db4  rep_threads  [last change: 2019/11/25 16:38:25]  OK
db4  rep_backlog  [last change: 2019/11/25 16:38:25]  OK: Backlog is null
db2  ping         [last change: 2019/11/25 16:38:25]  OK
db2  mysql        [last change: 2019/11/25 16:38:25]  OK
db2  rep_threads  [last change: 2019/11/25 16:38:25]  OK
db2  rep_backlog  [last change: 2019/11/25 16:38:25]  OK: Backlog is null
db3  ping         [last change: 2019/11/25 16:38:25]  OK
db3  mysql        [last change: 2019/11/25 16:38:25]  OK
db3  rep_threads  [last change: 2019/11/25 16:38:25]  OK
db3  rep_backlog  [last change: 2019/11/25 16:38:25]  OK: Backlog is null
db1  ping         [last change: 2019/11/25 16:38:25]  OK
db1  mysql        [last change: 2019/11/25 16:38:25]  OK
db1  rep_threads  [last change: 2019/11/25 16:38:25]  OK
db1  rep_backlog  [last change: 2019/11/25 16:38:25]  OK: Backlog is null

[root@localhost mysql-mmm]# mmm_control move_role writer db1
OK: Role 'writer' has been moved from 'db2' to 'db1'. Now you can wait some time and check new roles info!
[root@localhost mysql-mmm]# mmm_control show
  db1(192.168.136.191) master/ONLINE. Roles: writer(192.168.136.200)
  db2(192.168.136.168) master/ONLINE. Roles: 
  db3(192.168.136.185) slave/ONLINE. Roles: reader(192.168.136.220)
  db4(192.168.136.184) slave/ONLINE. Roles: reader(192.168.136.210)

#第一台主服务器关闭数据库模拟故障
[root@localhost mysql-mmm]# systemctl stop mariadb.service

#回到监控服务器测试,虚拟网址就变更了
[root@localhost mysql-mmm]# mmm_control show
  db1(192.168.136.191) master/HARD_OFFLINE. Roles: 
  db2(192.168.136.168) master/ONLINE. Roles: writer(192.168.136.200)
  db3(192.168.136.185) slave/ONLINE. Roles: reader(192.168.136.220)
  db4(192.168.136.184) slave/ONLINE. Roles: reader(192.168.136.210)

#再把第一台主服务器开启数据库
[root@localhost mysql-mmm]# systemctl start mariadb.service

#在回到监控服务器查看主服务器状态
[root@localhost mysql-mmm]# mmm_control show
  db1(192.168.136.191) master/ONLINE. Roles: 
  db2(192.168.136.168) master/ONLINE. Roles: writer(192.168.136.200)
  db3(192.168.136.185) slave/ONLINE. Roles: reader(192.168.136.220)
  db4(192.168.136.184) slave/ONLINE. Roles: reader(192.168.136.210)

#监控服务器
[root@localhost mysql-mmm]# yum install mariadb-server mariadb -y

#再M1服务器为监控器地址授权登录

MariaDB [(none)]> grant all on *.* to 'testba'@'192.168.136.135' identified by '123456';

MariaDB [(none)]> flush privileges;

Back to the monitoring server can not log test

mysql -utestdba -p -h 192.168.136.200
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2562
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Create a table to view the data have to go to other servers are not synchronized

MariaDB [(none)]> create database chen;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| chen               |
| mysql              |
| performance_schema |
| school             |
| test               |
+--------------------+
6 rows in set (0.01 sec)

That's all of our content, Thank you for watching

Guess you like

Origin blog.51cto.com/14449524/2453381