Centos7 under mysql5.7-mmm High availability cluster MMM introduction
MMM (Master-master Replication Manager for MySQL, MySQL primary master replication Manager)
is a set of scripts that support dual-master failover and dual-master daily management. MMM is developed using the Perl language, which is mainly used to monitor and manage MYSQL Master-master (dual master) replication, although it is called dual master replication, but only one master is allowed to write at the same time in the business, and the other master provides a partial read service to speed up the preheating of the alternate host during the main master switchover. Can say mmm this script program on the one hand to achieve the function of failover
On the other hand, its internal additional tool scripts can also implement read load balancing for multiple slave.
Experiment Preparation
4 devices for installing mysql5.7 services
1 sets of CENTOS7 equipment for installing MMM
Experimental steps to turn off firewall self-booting, as well as related features and enhanced security features
systemctl stop firewalld.service setenforce 0
Configure the Ali cloud Source, and then install the epel-release source.
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repoyum -y install epel-releaseyum clean all && yum makecache
Modify the configuration file for the MySQL server
vim /etc/my.cnf修改mysqld下面的内容[mysqld]log_error=/var/lib/mysql/mysql.errlog=/var/lib/mysql/mysql_log.loglog_slow_queries=/var/lib/mysql_slow_queris.logbinlog-ignore-db=mysql,information_schemacharacter_set_server=utf8log_bin=mysql_binserver_id=1log_slave_updates=truesync_binlog=1auto_increment_increment=2auto_increment_offset=1systemctl restart mysqld-------没有问题后,把配置文件复制到其它3台数据库服务器上并启动服务器-----scp /etc/my.cnf [email protected]:/etc/scp /etc/my.cnf [email protected]:/etc/scp /etc/my.cnf [email protected]:/etc/-----注意:配置文件中的server_id 要修改-----
Configure primary master replication, where two primary servers replicate with one another
Show master status; +-------------------+----------+--------------+------------------+| File | Position | binlog_do_db | binlog_ignore_db |+-------------------+----------+--------------+------------------+| master-bin.000002 | 339 | | |+-------------------+----------+--------------+------------------+1 row in Set (0.00 sec) # #记录日志文件名称和 position value, viewed by two masters. ----Grant M2 permission from the M1 on the M2, also grant the permission from the M1 on the grant replication slave on * * to ' replication ' @ ' 192.168.100.% ' identified by ' 123456 '; # #两台主服务器都执行, from the server does not need 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;-----Note that the log file name on the M1 is specified on the M2, and the positional parameters-----on M2 are reversed. Start slave;show slave status; Slave_io_running:yes slave_sql_running:yes-------In another Lord do----to specify M1 log and positional parameters---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
Configuring Master-slave replication
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
Install MMM
Install-----on all servers Note that the Epel source should be configured well
yum -y install mysql-mmm*
Configure MMM
Cd/etc/mysql-mmm/vi mmm_common.conf # #所有主机上都要配置, copy multiple copies directly
Test关掉主1 的mysql服务systemctl stop mysqldmmm_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)
At this point, complete MySQL high-availability cluster through MMMCentos7 under mysql5.7-mmm high Availability cluster