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

MySQL+MMM High availability Cluster deployment (2)

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

Share

Shulou(Shulou.com)06/01 Report--

In the previous issue, we have deployed the master-slave synchronization of MySQL. Next, we will begin to deploy the core of this issue-MMM high availability cluster.

IV. MMM highly available cluster deployment

1. Install the dependency package

Because mmm is a script written in Perl, you need to install perl and perl-CPAN on five servers

[root@cluster-mysqlb ~] # yum-y install perl perl-CPAN

2. Yum install mmm

A. Install mysql-mmm-agent in 4 MySQL servers

[root@cluster-mysqla ~] # yum-y install gcc gcc-c++ mysql-mmm-agent

B. Install mysql-mmm-monitor in the monitor server

[root@cluster-proxy ~] # yum-y install gcc gcc-c++ mysql-mmm-monitor

3. Configure mmm

The configuration file for mysql-mmm is in the / etc/mysql-mmm directory. Enter that directory.

Mysql-mmm-agent profile

Mysql-mmm-monitor profile

As shown in the figure, there are only two configuration files for mysql-mmm-agent, mmm_agent.conf and mmm_common.conf, while there are four configuration files for mysql-mmm-monitor, which was originally three. Because I installed mysql-mmm-tools here, there is an extra mmm_tools.conf.

A. Modify the public configuration file mmm_common.conf

[root@cluster-mysqla mysql-mmm] # vim mmm_common.conf

As shown in the figure:

(1), field interpretation

Active_master_role writer # active master role indicates that all database servers need to enable the read_only parameter, while for Write servers, the monitoring server will automatically turn off the read_only property, that is, set its value to 1

Cluster_interface eth0 # Cluster Network Interface

Pid_path / run/mysql-mmm-agent.pid # mmm-agent process pid file path

Bin_path / usr/libexec/mysql-mmm/ # executable file path

Replication_user slaveuser # replicating users

Replication_password 123456 # copy the user's password

Agent_user mmmagent # proxy user

Password of agent_password 123456 # proxy user

# write the host name of mastera here

IP address of ip 192.168.20.134 # mastera

Mode master # role mode: master represents the main library

Peer masterb # the host name of the main library equivalent to mastera, that is, the host name of the database that synchronizes data to mastera, so it is masterb

# the attributes here are the same as mastera

Ip 192.168.20.128

Mode master

Peer mastera

# Host name of slave library

Ip 192.168.20.129 # IP address of the slave library

Mode slave # role mode: this host is the slave database of masterb, so it is slave

# the attributes here are the same as slavea

Mode slave

# Write role configuration

Hosts mastera and masterb # have host names for write operations. The configuration here can write either single or multiple. When writing a single, you can avoid switching Write when the network delay is too large. But when master fails, write cannot be performed and only read operations can be provided.

Ips 192.168.20.254 # Virtual IP address for external write operations

Mode exclusive # mode, exclusive means that only one master database is allowed, that is, only one virtual IP address can be written

# read role configuration

Hosts slavea, slaveb # the name of the host of the server that provides read operation. You can also write master here. When written in, master also provides read operation to the outside.

Ips 192.168.20.253, 192.168.20.252 # provide virtual IP addresses for read operations. In order to achieve load balancing, the virtual IP addresses here should be at least the same as the number of read database servers.

Mode balanced # mode, balanced represents load balancer

(2). Mmm_common.conf configuration file modification

If you have multiple network cards in the server, you need to specify the name of the network card in the cluster_interface field

Modify the common configuration file according to the above format, and copy it to the other 4 servers

Scp / etc/mysql-mmm/mmm_common.conf root@192.168.20.128:/etc/mysql-mmm

Scp / etc/mysql-mmm/mmm_common.conf root@192.168.20.129:/etc/mysql-mmm

Scp / etc/mysql-mmm/mmm_common.conf root@192.168.20.130:/etc/mysql-mmm

Scp / etc/mysql-mmm/mmm_common.conf root@192.168.20.131:/etc/mysql-mmm

(3). Mmm_agent.conf configuration file modification

[root@cluster-mysqla mysql-mmm] # vim mmm_agent.conf

As shown in the figure, you only need to modify the marked part of the configuration file, so if the server is mastera, change it to this mastera, if the server is masterb, change it to this masterb, and so on.

(4) modify mysql-mmm-monitor configuration file mmm_mon.conf

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

As shown in the figure above, the field is explained

Include mmm_common.conf # calls mmm_common.conf configuration file

Ip 192.168.20.131 # Monitoring host IP address

Pid_path / run/mysql-mmm-monitor.pid # Monitoring process pid file directory

Bin_path / usr/libexec/mysql-mmm # executable directory

Status_path / var/lib/mysql-mmm/mmm_mond.status

Ping_ips 192.168.20.134,192.168.20.128,192.168.20.129,192.168.20.130 # write the IP addresses of four database servers here

Auto_set_online 60

# The kill_host_bin does not exist by default, though the monitor will

# throw a warning about it missing. See the section 5.10 "Kill Host

# Functionality "in the PDF documentation.

#

# kill_host_bin / usr/libexec/mysql-mmm/monitor/kill_host

#

Monitor_user monitor # Monitoring users

Monitor_password 123456 # Monitoring user password

Debug 0

Configure mmm_mond.conf according to the above format

B. Start mmm service

Start the mysql-mmm-agent service in 4 MySQL servers

[root@cluster-mysqla mysql-mmm] # mmm_agentd start

Drive mysql-mmm-monitor service in monitoring server

[root@cluster-proxy mysql-mmm] # mmm_mond start

C. Check the status of the other 4 servers on the monitor server

[root@cluster-proxy mysql-mmm] # mmm_control show

As shown in the figure above, 4 database servers are configured with mmm configuration OK.

D. Test whether the virtual IP address can be ping connected.

If ping is available, mysql-mmm deployment is successful. If ping is not available, the virtual IP address on the host is not set successfully. In this case, we need to execute the following command on five database servers

[root@cluster-mysqla mysql-mmm] # perl-MCPAN-e shell

As shown in the figure:

Cpan [1] > install Net::ARP

If you are executing perl-MCPAN-e shell, this command is wrong Can't locate CPAN.pm in @ INC (@ INC contains: / usr/local/lib/perl5 / usr/local/share/perl5 / usr/lib/perl5/vendor_perl / usr/share/perl5/vendor_perl / usr/lib/perl5/ usr/share/perl5.).

Note: we don't have perl-CPAN installed, just install it with yum.

After executing the above command, execute the following command on each of the four servers

Mastera

[root@cluster-mysqla mysql-mmm] # / usr/libexec/mysql-mmm/agent/configure_ip / etc/mysql-mmm/mmm_common.conf ens33 192.168.20.254

Masterb

[root@cluster-mysqlb mysql-mmm] # / usr/libexec/mysql-mmm/agent/configure_ip / etc/mysql-mmm/mmm_common.conf ens33 192.168.20.254

Slavea

[root@cluster-mysqlc mysql-mmm] # / usr/libexec/mysql-mmm/agent/configure_ip / etc/mysql-mmm/mmm_common.conf ens33 192.168.20.253

Slaveb

[root@cluster-mysqld mysql-mmm] # / usr/libexec/mysql-mmm/agent/configure_ip / etc/mysql-mmm/mmm_common.conf ens33 192.168.20.252

After executing the above command, in the ping virtual IP address, ping test OK, can ping

Finally, check the status of the four database servers

[root@cluster-proxy mysql-mmm] # mmm_control checks all

As shown in the figure:

If it is all OK, it means that our mysql-mmm service is deployed successfully

The two columns above mean:

Ping:ping test, you can ping Tencent OK, otherwise, please follow the above operation to check

OK when mysql:mysql server is online, otherwise, check whether mysql server is stopped

Rep_threadh: OK when the replication thread is running, otherwise troubleshoot the reason why the replication thread is not running, the common possible reasons are: 1, the user name and password used for monitoring and replication are wrong; 2, the master-slave synchronization fails

Rep_backlog: OK when few logs are copied and squeezed, otherwise the processing speed of the server may be too slow or the amount of data may be too large

Explanation of e and mmm_control nouns

As shown in the figure:

Check: view the specified status or all status of the specified host or all hosts

Show: view current cluster status

Set_online: restore the state of host from AWAITING_RECOVERY or ADMIN_OFFLINE to ONLINE

Set_offline: manually sets the status of host to ADMIN_OFFLINE and stops mysql replication

Mode: print the running mode of the current monitor

Set_active: switch the monitor process to active mode

Set_passive: switch the monitor process to passive mode

Set_manual: switch the monitor process to manual mode

Move_role: switch the write role to another host

F. Test whether mysql-mmm can switch automatically in case of service failure. Here the value provides a method.

The test method is:

Stop the mysql service of mastera, check whether writer (192.168.20.254) can switch to masterb, then turn on the mysql service of mastera, stop the mysql service of masterb manually, and check whether writer (192.168.20.254) can switch to mastera. If both, it means that our mysql-mmm cluster deployment is OK. If not, please check if there is any error in the mmm_common.conf configuration file. Of course, there are other testing ideas, which will not be listed here.

Connect to the MMM cluster

After deploying the mysql-mmm cluster, we can't wait to connect with our existing application services.

First, we create a new MySQL account in mastera, game.

Mysql > grant all privileges on *. * to game@ "%" identified by "123456"

Mysql > flush privileges

Then we connect to the virtual IP (192.168.20.254, 192.168.20.253, 192.168.20.252) on our application server

A. Connect to 192.168.20.254 to create a database

[root@weba] # mysql-h292.168.20.254-ugame-p123456

MySQL [(none)] > create database web

B. Connect 192.168.20.253 and 192.168.20.252 to see if the database you just created exists

[root@webb] # mysql-h292.168.20.253-ugame-p123456

[root@webb] # mysql-h292.168.20.252-ugame-p123456

As can be seen in the picture, we connect to the database created by 192.168.20.254, and we can also see it after connecting 192.168.20.253 and 192.168.20.252, which shows all the OK

Note: when connecting to 192.168.20.254, it is best to switch between mastera and masterb to test the connection database. During this period, the following error may occur:

1209-The MySQL server is running with the-read-only option so it cannot execute this statement

The reason for this error is that mmm sets the main database to read-only mode, so we only need to execute set global read_only=0;

So far, our MySQL master-slave synchronization + MMM highly available cluster deployment has been completed, and we have also listed some holes that may be stepped into in the process of deployment. However, in online deployment, specific problems need to be analyzed, so in the future, I will grow up with the bosses.

For the above deployment process, if you have any questions, you can refer to the official installation documentation.

At the end of this section.

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