Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy MySQL-MMM highly available clusters

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

How to deploy MySQL-MMM high-availability clusters, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Brief introduction

MMM (Master-Master replication manager for MySQL) is a set of scripts that support dual-master failover and dual-master daily management. MMM is developed in Perl language, which is mainly used to monitor and manage MySQL Master-Master (double master) replication. Although it is called double master replication, only one master is allowed to write to one master at the same time, and the other alternative master provides partial read service to speed up the warm-up of the backup master at the time of master-master switch. it can be said that the script program MMM realizes the function of failover on the one hand. On the other hand, the additional tool scripts can also achieve read load balancing of multiple slave.

MMM provides both automatic and manual ways to remove the virtual ip of servers with high replication latency in a group of servers. At the same time, it can also back up data and achieve data synchronization between the two nodes. Because MMM cannot completely guarantee data consistency, MMM is suitable for scenarios where data consistency is not very high, but you want to maximize business availability. For those businesses that require high data consistency, a highly available architecture such as MMM is not recommended.

Experimental topology diagram

Experimental goal

Build a mysql high availability cluster

Experimental environment

Turn off the firewall on 5 servers for security

Setenforce 0

Systemctl stop firewalld.service

Experimental procedure

Configuration of 5 mysql servers for master01, master02, slave01, slave02 and monitor

1. Configure all Cloud Source (yum Source)

Wget-O / etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo`

two。 Configure epel source (latest version)

Yum-y install epel-release

3. Load metadata cache

Yum clean all & & yum Makecache`

4. Install mariadb database and mysql-mmm software package

Yum install mariadb-sever mariadb mysql-mmm*-y

5. Modify the mariadb database master configuration file

Vim / etc/my.cnf

[mysqld]

Log_error=/var/lib/mysql/mysql.err # error log

Log=/var/lib/mysql/mysql_log.log # access Log

Log_slow_queries=/var/lib/mysql_slow_queris.log # slow log

Binlog-ignore-db=mysql,information_schema # does not generate binary log files

Character_set_server=utf8 # character set

Log_bin=mysql_bin # Open binaries

The server_id=1 # id number is unique

Log_slave_updates=true # synchronously enabled

Sync_binlog=1 # synchronizes binary logs, 1 is set to a safe value

Auto_increment_increment=2 # increment column with a starting point of 1 and an increment of 2

Auto_increment_offset=1

Note: modify the configuration file server_id parameters of master02, slave01 and slave02 respectively

6. Start the mariadb service

Systemctl enable mariadb # Boot self-starting mariadbsystemctl start mariadb.service # start the mariadb service

Second, master and master replication (master servers replicate each other)

1. Log in to mariadb and authorize on the primary server master1

Mysqlgrant replication slave on *. * to 'replication'@'192.168.65.%' identified by' 123456'

two。 Specify log and location parameters for master2 on master1

Change master to master_host='192.168.65.142',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245

3. Turn on synchronization

Start slave

4. Authorization on the primary server master2

Mysqlgrant replication slave on *. * to 'replication'@'192.168.65.%' identified by' 123456'

5. Specify log and location parameters for master1 on master2

Change master to master_host='192.168.65.159',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245

6. Turn on synchronization

Start slave;show slave status\ G

7. Synchronize master from slave server (both slave servers point to the same master server)

The two slave servers operate the same:

Mysqlchange master to master_host='192.168.65.159',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=245; (# pay attention to changes in location parameters of the master server) start slave; # enable synchronization

8. Test: all four sets are synchronized

Configure the mysql-MMM server (all 5 servers are configured)

1. Edit the configuration file for mysql-mmm

Vim mmm_common.conf # all hosts need to be configured Copy cluster_interface ens33 # modify the network card to ens33 pid_path / run/mysql-mmm-agent.pid bin_path / usr/libexec/mysql-mmm/ replication_user replicantion replication_password 123456 # modify the user password granted by Mariadb agent_user mmm_agent agent_password 123456 # repair Change agent client agent user password # specify first database ip 192.168.65.159 # specify IP address mode master # mode primary server peer db2 # switch with db2 # specify second database ip 192.168.65.142 # specify IP address mode master # mode primary server peer db1 # and db1 Switch # specify second database ip 192.168.65.165 # specify IP address mode slave # mode specify second database ip 192.168.65.152 # specify IP address mode slave # mode specify write server hosts db1 for slave server Db2 # specify db1,db2 as write server ips 192.168.65.100 # specify write virtual ip address mode exclusive # mode as separate (only one) # specify read server hosts db3, db4 # specify db1,db2 as write server ips 192.168.65.101, 192.168.100.65.102 # specify read virtual ip address mode balanced # mode as load balancer Read operations will be performed from db3 and db4 hosts

two。 Transfer the configuration file to the other 4 database servers

Scp mmm_common.conf root@192.168.65.142:/etc/mysql-mmm/scp mmm_common.conf root@192.168.65.152:/etc/mysql-mmm/scp mmm_common.conf root@192.168.65.165:/etc/mysql-mmm/scp mmm_common.conf root@192.168.65.164:/etc/mysql-mmm/

Note: be sure to go to the other 4 servers to confirm that it has been modified!

3.monitor configuration

Change cd / etc/mysql-mmm/vim mmm_mon.conf # password ping_ips 192.168.65.159192.168.65.142192.168.65.152192.168.65.165 auto_set_online 10 # to 10 seconds online. Omit part of the content monitor_user mmm_monitor # monitor user name monitor_password 123456 # modify password

4. Authorize mmm_agent on all databases

Grant super,replication client,process on *. * to 'mmm_agent'@'192.168.65.%' identified by' 123456'

6 authorize mmm_monitor on all databases

Grant replication client on *. * to 'mmm_monitor'@'192.168.65.%' identified by' 123456 refresh takes effect

7. Modify mmm_agent.conf on 4 databases respectively

Vim mmm_agent.conf this is db1/2/3/4 # modify each of the four databases

8 start mysql-mmm-agent

Systemctl restart mysql-mmm-agent.servicesystemctl enable mysql-mmm-agent.service

9. Start mysql-mmm-monitor

Systemctl start mysql-mmm-monitor.service # start the service

10. Check all options

Mmm_control show # View the status of each node mmm_control checks all

11. You can switch the primary server manually

Mmm_control move_role writer db2

Fourth, simulated failure

1. Stop db1,db3 first

Systemctl stop mariadb

two。 Check the mysql-mmm server status again

Mmm_control show

3. Resume db1,db3 launch

4. Check the mysql-mmm server status again

Mmm_control show

5. When the db1 server recovers, it does not preempt the vip address, but waits as a standby

When db2 is offline, check it again.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report