In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Mysql-mmm how to achieve mysql mutual master and slave copy HA function, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Each mysql server node needs to run mmmd_agent, while running mmmd_mon on another machine [it can be a separate server or a server shared with AppServer]
Mmm uses virtual IP technology, and one network card can use multiple IP.
Therefore, when using mmm, you need 2*n+1 IP,n to be the number of mysql nodes, including slave and master
When the database node fail, mmmd_mon cannot detect the heartbeat of mmmd_agent or the state of the corresponding mysql server
Mmmd_mon will make a decision and order the mmmd_agent of a normal database node to make the mmmd_agent "usurp"
[that is, use the virtual IP of the node of the fail just now, so that the virtual IP points from the fail node to the normal machine at this time]
MMMM requires 5 IP, two nodes using fixed IP, two program reading IP (read only), and one program writing IP (for update).
The last three virtual IP jump between nodes according to the availability of nodes.
one. IP allocation
The IP allocation is as follows:
A: mysql master 246
Fixed IP:211.100.97.246
Program read IP:211.100.97.244 (virtual)
B:mysql master 250
Fixed IP:211.100.97.250
Program read IP:211.100.97.243 (virtual)
Monitor 245
Programming IP:211.100.97.248 (virtual)
Add virtual IP 211.100.97.244 to 246
Ifconfig eth2:1 211.100.97.244 netmask 255.255.255.224 up
[root@XKWB5510 software] # ifconfig-a | grep "inet addr" | head-3 | tail-2 | awk-F "[:] +" {print $4 "/" $NF}'
211.100.97.246/255.255.255.224
211.100.97.244/255.255.255.224
Add virtual IP 211.100.97.243 to 250
Ifconfig eth0:1 211.100.97.243 netmask 255.255.255.224 up
[root@XKWB5705 software] # ifconfig-a | grep "inet addr" | head-2 | awk-F "[:] +" {print $4 "/" $NF}'
211.100.97.250/255.255.255.224
211.100.97.243/255.255.255.224
Add virtual IP:211.100.97.248 to 245
Ifconfig eth2:1 211.100.97.248 netmask 255.255.255.224 up
[root@CentOS mysql-5.1.56] # ifconfig-a | grep "inet addr" | head-3 | tail-2 | awk-F "[:] +" {print $4 "/" $NF}'
211.100.97.245/255.255.255.224
211.100.97.248/255.255.255.224
Second authorization
Add a proxy account useradd rep_agent to the AB machine
Add the monitoring account useradd rep_monitor to the monitor machine
Authorization on A
Mysql > grant all privileges on *. * to identified by '123456'
Mysql > grant all privileges on *. * to identified by '123456'
Check the authorization status
Mysql > select host,user from mysql.user where user like 'rep%'
+-+ +
| | host | user |
+-+ +
| |% | rep_agent |
| |% | rep_monitor |
| | 211.100.97.250 | replication | |
| | localhost | replication |
+-+ +
4 rows in set (0.01sec)
Authorization on B
Mysql > grant all privileges on *. * to identified by '123456'
Mysql > grant all privileges on *. * to identified by '123456'
Mysql > select host,user from mysql.user where user like 'rep%'
+-+ +
| | host | user |
+-+ +
| |% | rep_agent |
| |% | rep_monitor |
| | 211.100.97.246 | replication | |
| | localhost | replication |
+-+ +
4 rows in set (0.00 sec)
Three mmm installation
The CentOS software repository does not contain these software by default, and must have the support of the epel package. Therefore, we must first install epel:
Wget
Rpm-Uvh epel-release-5-4.noarch.rpm
Source package installs mysql-mmm
Wget
Tar zxf mysql-master-master-1.2.3.tar.gz
Cd mysql-master-master-1.2.3
. / install.pl
In addition, the following necessary perl modules need to be installed before installing mmm
Data::Dumper
POSIX
Cwd
Threads
Threads::shared
Thread::Queue
Thread::Semaphore
IO::Socket
Proc::Daemon
Time::HiRes
DBI
DBD::mysql
Algorithm::Diff
Otherwise, the following error will occur when installing mmm and executing the install.pl command:
1)
Checking required module 'Proc::Daemon'...Error!
Can't locate Proc/Daemon.pm in @ INC (@ INC contains: / usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/site_perl/5.8.8 / usr/lib/perl5/site_perl/ usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/vendor_perl/5.8.8 / usr/lib/perl5/vendor _ perl / usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/5.8.8.) At (eval 13) line 2.
BEGIN failed--compilation aborted at (eval 13) line 2.
Required module 'Proc::Daemon' is not found on this system!
Install it (e.g. Run command 'cpan Proc::Daemon') and try again.
Run according to the above error prompt
Basically, cpan Proc::Daemon is to enter.
2)
Checking required module 'DBI'...Error!
Can't locate DBI.pm in @ INC (@ INC contains: / usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/site_perl/5.8.8 / usr/lib/perl5/site_perl/ usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/vendor_perl/5.8.8 / usr/lib/perl5/vendor_perl / usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/5.8.8.) At (eval 16) line 2.
BEGIN failed--compilation aborted at (eval 16) line 2.
Required module 'DBI' is not found on this system!
Install it (e.g. Run command 'cpan DBI') and try again.
+ +
Run the command according to the error prompt
Cpan DBI
3)
Checking required module 'DBD::mysql'...Error!
Can't locate DBD/mysql.pm in @ INC (@ INC contains: / usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/site_perl/5.8.8 / usr/lib/perl5/site_perl/ usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/vendor_perl/5.8.8 / usr/lib/perl5/vendor _ perl / usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/5.8.8.) At (eval 19) line 2.
BEGIN failed--compilation aborted at (eval 19) line 2.
Required module 'DBD::mysql' is not found on this system!
Install it (e.g. Run command 'cpan DBD::mysql') and try again.
Run this command cpan DBD::mysql
The error is as follows:
CPAN.pm: Going to build C/CA/CAPTTOFU/DBD-mysql-4.020.tar.gz
Can't exec "mysql_config": No such file or directory at Makefile.PL line 83.
Cannot find the file 'mysql configuration configuration! Your execution PATH doesn't seem
Not contain the path to mysql_config. Resorting to guessed values!
Can't exec "mysql_config": No such file or directory at Makefile.PL line 478.
Can't find mysql_config. Use-mysql_config option to specify where mysql_config is located
Can't exec "mysql_config": No such file or directory at Makefile.PL line 478.
Can't find mysql_config. Use-mysql_config option to specify where mysql_config is located
Can't exec "mysql_config": No such file or directory at Makefile.PL line 478.
Can't find mysql_config. Use-mysql_config option to specify where mysql_config is located
PLEASE NOTE:
For 'make test' to run properly, you must ensure that the
Database user 'root' can connect to your MySQL server
And has the proper privileges that these tests require such
As' drop table', 'create table',' drop procedure', 'create procedure'
As well as others.
Mysql > grant all privileges on test.* to identified by's 3kr1t'
You can also optionally set the user to run 'make test' with:
Perl Makefile.PL-testuser=username
Can't exec "mysql_config": No such file or directory at Makefile.PL line 478.
Can't find mysql_config. Use-mysql_config option to specify where mysql_config is located
Can't exec "mysql_config": No such file or directory at Makefile.PL line 478.
Can't find mysql_config. Use-mysql_config option to specify where mysql_config is located
Can't exec "mysql_config": No such file or directory at Makefile.PL line 478.
Can't find mysql_config. Use-mysql_config option to specify where mysql_config is located
Failed to determine directory of mysql.h. Use
Perl Makefile.PL-cflags=-I
To set this directory. For details see the INSTALL.html file
Section "C Compiler flags" or type
Perl Makefile.PL-help
Running make test
Make had some problems, maybe interrupted? Won't test
Running make install
Make had some problems, maybe interrupted? Won't install
Check whether there is mysql_config according to the above brain frustration tips.
[root@XKWB5510 mysql-master-master-1.2.3] # find / usr/local/mysql/-name "mysql_config*"
/ usr/local/mysql/bin/mysql_config
/ usr/local/mysql/share/man/man1/mysql_config.1
Take a look at the permissions of mysql_config
[root@XKWB5510 mysql-master-master-1.2.3] # ls-l / usr/local/mysql/bin/mysql_config
-rwxr-xr-x 1 root root 6105 Sep 21 22:43 / usr/local/mysql/bin/mysql_config
Solution.
URL:
DBD-mysql-4.020.tar.gz
Tar zxf DBD-mysql-4.020.tar.gz
Cd DBD-mysql-4.020
Perl Makefile.PL-mysql_config=/usr/local/mysql/bin/mysql_config
Make
Make install
4)
Checking required module 'Algorithm::Diff'...Error!
Can't locate Algorithm/Diff.pm in @ INC (@ INC contains: / usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/site_perl/5.8.8 / usr/lib/perl5/site_perl/ usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/vendor_perl/5.8.8 / usr/lib/perl5/vendor _ perl / usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi / usr/lib/perl5/5.8.8.) At (eval 20) line 2.
BEGIN failed--compilation aborted at (eval 20) line 2.
Required module 'Algorithm::Diff' is not found on this system!
Install it (e.g. Run command 'cpan Algorithm::Diff') and try again.
+
Running
Cpan Algorithm::Diff
Just follow the error message until there is no Error
5)
The final hint for a successful installation is as follows:
[root@XKWB5705 mysql-master-master-1.2.3] #. / install.pl
Checking platform support... Linux Ok!
Checking required module 'Data::Dumper'...Ok!
Checking required module 'POSIX'...Ok!
Checking required module 'Cwd'...Ok!
Checking required module 'threads'...Ok!
Checking required module 'threads::shared'...Ok!
Checking required module 'Thread::Queue'...Ok!
Checking required module 'Thread::Semaphore'...Ok!
Checking required module 'IO::Socket'...Ok!
Checking required module 'Proc::Daemon'...Ok!
Checking required module 'Time::HiRes'...Ok!
Checking required module 'DBI'...Ok!
Checking required module 'DBD::mysql'...Ok!
Checking required module 'Algorithm::Diff'...Ok!
Checking iproute installation...Ok!
Installing mmm files...
Confgiuration:
-installation directory:'/ usr/local/mmm'
-create symlinks: on
-symlinks directory:'/ usr/local/sbin'
Copying files to'/ usr/local/mmm' directory...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmm_control'->'/ usr/local/sbin/mmm_control'...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmmd_agent'->'/ usr/local/sbin/mmmd_agent'...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmm_restore'->'/ usr/local/sbin/mmm_restore'...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmmd_angel'->'/ usr/local/sbin/mmmd_angel'...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmm_get_dump'->'/ usr/local/sbin/mmm_get_dump'...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmm_backup'->'/ usr/local/sbin/mmm_backup'...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmm_clone'->'/ usr/local/sbin/mmm_clone'...Ok!
Creating symlink:'/ usr/local/mmm/sbin/mmmd_mon'->'/ usr/local/sbin/mmmd_mon'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmmd_mon.1'->'/ usr/local/man/man1/mmmd_mon.1'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmm_restore.1'->'/ usr/local/man/man1/mmm_restore.1'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmmd_agent.1'->'/ usr/local/man/man1/mmmd_agent.1'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmm_clone.1'->'/ usr/local/man/man1/mmm_clone.1'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmm_get_dump.1'->'/ usr/local/man/man1/mmm_get_dump.1'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmm_control.1'->'/ usr/local/man/man1/mmm_control.1'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmmd_angel.1'->'/ usr/local/man/man1/mmmd_angel.1'...Ok!
Creating symlink:'/ usr/local/mmm/man/man1/mmm_backup.1'->'/ usr/local/man/man1/mmm_backup.1'...Ok!
Installation is done!
+ +
Four configurations
Cp / home/sysadmin/zhaoyj/software/mysql-master-master-1.2.3/etc/examples/mmm_agent.conf.example / usr/local/mmm/etc/mmm_agent.conf
-
Is this configuration option necessary? [not]
# Cluster interface
Cluster_interface eth0
--
Configuration file / usr/local/mmm/etc/mmm_agent.conf for db1
#
# Master-Master Manager config (agent)
#
Include mmm_common.conf
# Paths
Pid_path / usr/local/mmm/var/mmmd_agent.pid
Bin_path / usr/local/mmm/bin
# MMMD command socket tcp-port and ip
Bind_port 9989
# Logging setup
Log mydebug
File / usr/local/mmm/var/mmm-debug.log
Level debug
Log mytraps
File / usr/local/mmm/var/mmm-traps.log
Level trap
# Define current server id
This db1
Mode master
# For masters
Peer db2
# Cluster hosts addresses and access params
Host db1
Ip 211.100.97.246
Port 3306
User rep_agent
Password 123456
Host db2
Ip 211.100.97.250
Port 3306
User rep_agent
Password 123456
-
Configuration file / usr/local/mmm/etc/mmm_agent.conf for db2
# Master-Master Manager config (agent)
#
Include mmm_common.conf
# Paths
Pid_path / usr/local/mmm/var/mmmd_agent.pid
Bin_path / usr/local/mmm/bin
# MMMD command socket tcp-port and ip
Bind_port 9989
# Logging setup
Log mydebug
File / usr/local/mmm/var/mmm-debug.log
Level debug
Log mytraps
File / usr/local/mmm/var/mmm-traps.log
Level trap
# Define current server id
This db2
Mode master
# For masters
Peer db1
# Cluster hosts addresses and access params
Host db1
Ip 211.100.97.246
Port 3306
User rep_agent
Password 123456
Host db2
Ip 211.100.97.250
Port 3306
User rep_agent
Password 123456
-
Db1 db2 and monitor common configuration file / usr/local/mmm/etc/mmm_common.conf
# Cluster interface
# cluster_interface eth0
# Debug mode
Debug no
# Paths
Bin_path / usr/local/mmm/bin
Pid_path / usr/local/mmm/var/mmmd.pid
Status_path / usr/local/mmm/var/mmmd.status
# Choose the default failover method [manual | wait | auto]
Failover_method auto
# How many seconds to wait for both masters to become ONLINE
# before switching from WAIT to AUTO failover method, 0 = wait indefinitely
Wait_for_other_master 2
# How many seconds to wait before switching node status from AWAITING_RECOVERY to ONLINE
# 0 = disabled
Auto_set_online 1
# Logging setup
Log mydebug
File / usr/local/mmm/var/mmm-debug.log
Level debug
Log mytraps
File / usr/local/mmm/var/mmm-traps.log
Level trap
# Email notification settings
Email notify
From_address
From_name MMM Control
# Define roles
Active_master_role reader
# MMMD command socket tcp-port
Agent_port 9989
Monitor_ip 127.0.0.1
# Cluster hosts addresses and access params
Host db1
Ip 211.100.97.246
Port 3306
User rep_agent
Password 123456
Mode master
Pear db2
Host db2
Ip 211.100.97.250
Port 3306
User rep_agent
Password 123456
Mode master
Pear db1
# Define roles that are assigned to the above hosts
# Mysql Reader role
Role reader
Mode balanced
Servers db1, db2
Ip 211.100.97.243211.100.97.244
# Mysql Writer role
Role writer
Mode exclusive
Servers db1, db2
Ip 211.100.97.248
# Replication credentials used by slaves to connect to the master
Replication_user replication
Replication_password 123456
# Checks parameters
# Ping checker
Check ping
Check_period 1
Trap_period 5
Timeout 2
# Mysql checker
# (restarts after 10000 checks to prevent memory leaks)
Check mysql
Check_period 1
Trap_period 2
Timeout 2
Restart_after 10000
# Mysql replication backlog checker
# (restarts after 10000 checks to prevent memory leaks)
Check rep_backlog
Check_period 5
Trap_period 10
Max_backlog 60
Timeout 2
Restart_after 10000
# Mysql replication threads checker
# (restarts after 10000 checks to prevent memory leaks)
Check rep_threads
Check_period 1
Trap_period 5
Timeout 2
Restart_after 10000
-
Configuration file of mmm_mon.conf on monit machine
# Cluster interface
# cluster_interface eth0
# Debug mode
Debug no
# Paths
Bin_path / usr/local/mmm/bin
Pid_path / usr/local/mmm/var/mmmd.pid
Status_path / usr/local/mmm/var/mmmd.status
# Choose the default failover method [manual | wait | auto]
Failover_method auto
# How many seconds to wait for both masters to become ONLINE
# before switching from WAIT to AUTO failover method, 0 = wait indefinitely
Wait_for_other_master 2
# How many seconds to wait before switching node status from AWAITING_RECOVERY to ONLINE
# 0 = disabled
Auto_set_online 1
# Logging setup
Log mydebug
File / usr/local/mmm/var/mmm-debug.log
Level debug
Log mytraps
File / usr/local/mmm/var/mmm-traps.log
Level trap
# Email notification settings
Email notify
From_address
From_name MMM Control
# Define roles
Active_master_role writer
# MMMD command socket tcp-port
Agent_port 9989
Monitor_ip 127.0.0.1
# Cluster hosts addresses and access params
Host db1
Ip 211.100.97.246
Port 3306
User rep_agent
Password 123456
Mode master
Pear db2
Host db2
Ip 211.100.97.250
Port 3306
User rep_agent
Password 123456
Mode master
Pear db1
# Define roles that are assigned to the above hosts
# Mysql Reader role
Role reader
Mode balanced
Servers db1, db2
Ip 211.100.97.243211.100.97.244
# Mysql Writer role
Role writer
Mode exclusive
Servers db1, db2
Ip 211.100.97.248
# Replication credentials used by slaves to connect to the master
Replication_user replication
Replication_password 123456
# Checks parameters
# Ping checker
Check ping
Check_period 1
Trap_period 5
Timeout 2
# Mysql checker
# (restarts after 10000 checks to prevent memory leaks)
Check mysql
Check_period 1
Trap_period 2
Timeout 2
Restart_after 10000
# Mysql replication backlog checker
# (restarts after 10000 checks to prevent memory leaks)
Check rep_backlog
Check_period 5
Trap_period 10
Max_backlog 60
Timeout 2
Restart_after 10000
# Mysql replication threads checker
# (restarts after 10000 checks to prevent memory leaks)
Check rep_threads
Check_period 1
Trap_period 5
Timeout 2
Restart_after 10000
-
5. Start the process
You cannot start the agent process until you have configured mmm_agent.conf and mmm_common.conf on db1 and db2
Start the mmmd_agent process
[root@XKWB5705 etc] # / usr/local/mmm/scripts/init.d/mmm_agent start
Starting MMM Agent daemon: MySQL Multi-Master Replication Manager
Version: 1.2.3
Ok
Start the mon process after configuring mmm_mon.conf on monit
[root@CentOS etc] # / usr/local/mmm/scripts/init.d/mmm_mon start
Daemon bin:'/ usr/local/mmm/sbin/mmmd_mon'
Daemon pid:'/ usr/local/mmm/var/mmmd.pid'
Starting MMM Monitor daemon: MySQL Multi-Master Replication Manager
Version: 1.2.3
Reading config file: 'mmm_mon.conf'
$VAR1 = {}
Ok
-
Db1 and db2 view processes
[root@XKWB5510 etc] # ps aux | grep mmm
Root 13702 0.4 0.4 107260 8444? S 15:21 0:03 / usr/bin/perl / usr/local/mmm/sbin/mmmd_agent
View processes on monit
[root@CentOS etc] # ps aux | grep mmm
Root 24608 0.6 1.9 258556 39352? Sl 15:17 0:04 perl / usr/local/mmm/sbin/mmmd_mon
Root 24611 0.0 0.4 107392 8280? S 15:17 0:00 perl / usr/local/mmm/bin/check/checker rep_backlog
Root 24613 0.1 0.4 107392 8252? S 15:17 0:00 perl / usr/local/mmm/bin/check/checker mysql
Root 24615 0.2 0.2 91668 5368? S 15:17 0:01 perl / usr/local/mmm/bin/check/checker ping
Root 24617 0.2 0.4 107392 8280? S 15:17 0:01 perl / usr/local/mmm/bin/check/checker rep_threads
The process changes on monit were observed several times in succession.
From the changes, we can see that monitor uses fping to detect the survival status of the two nodes.
[root@CentOS etc] # ps aux | grep mmm
Root 24608 0.6 1.9 258556 39356? Sl 15:17 0:07 perl / usr/local/mmm/sbin/mmmd_mon
Root 24611 0.0 0.4 107392 8288? S 15:17 0:00 perl / usr/local/mmm/bin/check/checker rep_backlog
Root 24613 0.1 0.4 107392 8264? S 15:17 0:01 perl / usr/local/mmm/bin/check/checker mysql
Root 24615 0.2 0.2 91668 5368? S 15:17 0:02 perl / usr/local/mmm/bin/check/checker ping
Root 24617 0.1 0.4 107392 8280? S 15:17 0:02 perl / usr/local/mmm/bin/check/checker rep_threads
[root@CentOS etc] # ps aux | grep mmm
Root 24608 0.6 1.9 258556 39356? Sl 15:17 0:07 perl / usr/local/mmm/sbin/mmmd_mon
Root 24611 0.0 0.4 107392 8288? S 15:17 0:00 perl / usr/local/mmm/bin/check/checker rep_backlog
Root 24613 0.1 0.4 107392 8264? S 15:17 0:01 perl / usr/local/mmm/bin/check/checker mysql
Root 24615 0.2 0.2 91668 5368? S 15:17 0:02 perl / usr/local/mmm/bin/check/checker ping
Root 24617 0.1 0.4 107392 8280? S 15:17 0:02 perl / usr/local/mmm/bin/check/checker rep_threads
Root 25887 0.0 0.0 1804 504? S 15:35 0:00 / usr/local/mmm/bin/sys/fping-Q-u-t 500-C 1 211.100.97.246
[root@CentOS etc] # ps aux | grep mmm
Root 24608 0.6 1.9 258556 39356? Sl 15:17 0:07 perl / usr/local/mmm/sbin/mmmd_mon
Root 24611 0.0 0.4 107392 8288? S 15:17 0:00 perl / usr/local/mmm/bin/check/checker rep_backlog
Root 24613 0.1 0.4 107392 8264? S 15:17 0:01 perl / usr/local/mmm/bin/check/checker mysql
Root 24615 0.2 0.2 91668 5368? S 15:17 0:02 perl / usr/local/mmm/bin/check/checker ping
Root 24617 0.1 0.4 107392 8280? S 15:17 0:02 perl / usr/local/mmm/bin/check/checker rep_threads
Root 25890 0.0 0.0 1804 504? S 15:35 0:00 / usr/local/mmm/bin/sys/fping-Q-u-t 500-C 1 211.100.97.250
Continuously observe the changes of the process on db2
You can see that db2 constantly detects the reading process of db1 and the writing process of monit.
[root@XKWB5705 etc] # ps aux | grep mmm
Root 1613 0.3 0.2 107272 8440? S 15:18 0:04 / usr/bin/perl / usr/local/mmm/sbin/mmmd_agent
Root 12026 0.0 0.1 99564 7056? S 15:38 0:00 perl / usr/local/mmm/bin/agent/check_role writer (211.100.97.248;)
Root 12027 0.0 0.1 102200 7572? R 15:38 0:00 perl / usr/local/mmm/bin/mysql_allow_write
[root@XKWB5705 etc] # ps aux | grep mmm
Root 1613 0.3 0.2 107272 8440? S 15:18 0:04 / usr/bin/perl / usr/local/mmm/sbin/mmmd_agent
Root 12121 0.0 0.1 92552 6176? R 15:38 0:00 perl / usr/local/mmm/bin/agent/check_role writer (211.100.97.248;)
Root 1613 0.3 0.2 107272 8440? S 15:18 0:04 / usr/bin/perl / usr/local/mmm/sbin/mmmd_agent
Root 12202 0.0 0.1 90072 5744? R 15:38 0:00 perl / usr/local/mmm/bin/agent/check_role reader (211.100.97.244;)
[root@XKWB5705 etc] # ps aux | grep mmm
Root 1613 0.3 0.2 107272 8440? S 15:18 0:04 / usr/bin/perl / usr/local/mmm/sbin/mmmd_agent
Continuously observe the changes of the process on db1
You can see that db1 constantly detects the reading process of db2.
[root@XKWB5510 etc] # ps aux | grep mmm | grep-v grep
Root 13702 0.4 0.4 107260 8444? S 15:21 0:06 / usr/bin/perl / usr/local/mmm/sbin/mmmd_agent
Root 26820 0.0 0.3 97212 6712? R 15:44 0:00 perl / usr/local/mmm/bin/agent/check_role reader (211.100.97.243;)
[root@XKWB5510 etc] # ps aux | grep mmm | grep-v grep
Root 13702 0.4 0.4 107260 8444? S 15:21 0:06 / usr/bin/perl / usr/local/mmm/sbin/mmmd_agent
-
Add boot and start automatically
Db1, db2 self-booting
Cp-r / usr/local/mmm/scripts/init.d/mmm_agent / etc/init.d/mmmd
Chkconfig-add mmmd
Chkconfig-level 345 mmmd on
Check out the results of the addition:
[root@XKWB5705 etc] # chkconfig-- list mmmd
Mmmd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
Mon boot self-startup
[root@CentOS etc] # cp-r / usr/local/mmm/scripts/init.d/mmm_agent / etc/init.d/mmmd
[root@CentOS etc] # chkconfig-- add mmmd
[root@CentOS etc] # chkconfig-- level 345 mmmd on
[root@CentOS etc] # chkconfig-- list mmmd
Mmmd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
-
Seven tests
Let's first introduce several states:
Online is running normally.
The admin_offline host is manually set to offline
The hard_offline host is in offline state. It may be a failure to detect ping or mysql.
The awaiting_recovery host is waiting for recovery
Replication_delay replication backlog is too large (failed to detect rep_backlog thread)
Replication_fail replication thread is not running (failed to detect rep_threads thread)
Initial state:
Mmm_control set_online db1 put db1 online.
Mmm_control set_online db2 put db2 online.
[root@CentOS etc] # mmm_control show
Servers status:
Db1 (211.100.97.246): master/ONLINE. Roles: reader (211.100.97.243;), writer (211.100.97.248;)
Db2 (211.100.97.250): master/ONLINE. Roles: reader (211.100.97.244;)
From the above, you can see that db1 is the main writing server.
-
When I stop the mysql process of db1, the log message
[2011-09-28 16:00:00]: 24608: Check: CHECK_FAIL ('db2',' rep_threads') Returned message: ERROR: Replication is broken
[2011-09-28 16:00:07]: 24608: Check: CHECK_OK ('db1',' mysql')
[2011-09-28 16:00:08]: 24608: Daemon: State change (db1): HARD_OFFLINE-> AWAITING_RECOVERY
[2011-09-28 16:00:10]: 24608: Daemon: State change (db1): AWAITING_RECOVERY-> ONLINE. Uptime diff = 12.109999999986 seconds; Status change diff = 1317196810
[root@CentOS var] # mmm_control show
Servers status:
Db1 (211.100.97.246): master/HARD_OFFLINE. Roles: None
Db2 (211.100.97.250): master/ONLINE. Roles: reader (211.100.97.243;), reader (211.100.97.244;), writer (211.100.97.248;)
From the above, you can see that the main writer server has been switched from db1 to db2, and db1 is in offline state.
When I restart the mysql process of db1
[2011-09-28 16:01:54]: 24608: Check: CHECK_OK ('db1',' mysql')
[2011-09-28 16:01:55]: 24608: Daemon: State change (db1): HARD_OFFLINE-> AWAITING_RECOVERY
[2011-09-28 16:01:56]: 24608: Check: CHECK_OK ('db2',' rep_threads')
[2011-09-28 16:01:56]: 24608: Daemon: State change (db1): AWAITING_RECOVERY-> ONLINE. Uptime diff = 2.94999999995343 seconds; Status change diff = 1317196916
-
When I stop the mysql process of db2
[2011-09-28 16:29:22]: 24608: Check: CHECK_FAIL ('db2',' mysql') Returned message: ERROR: Connect error (host = 211.100.97.250 mysql' 3306, user = rep_agent, pass = 'xxxxxx')! Lost connection to MySQL server at 'reading initial communication packet', system error: 111
[2011-09-28 16:29:23]: 24608: Daemon: State change (db2): ONLINE-> HARD_OFFLINE
[2011-09-28 16:29:26]: 24608: Check: CHECK_FAIL ('db1',' rep_threads') Returned message: ERROR: Replication is broken
[root@CentOS var] # mmm_control show
Servers status:
Db1 (211.100.97.246): master/ONLINE. Roles: reader (211.100.97.243;), reader (211.100.97.244;), writer (211.100.97.248;)
Db2 (211.100.97.250): master/HARD_OFFLINE. Roles: None
From the above, you can see that db2 is in offline state.
When I restart the mysql process of db2, the status prompt in the log has changed to online status.
[2011-09-28 16:34:26]: 24608: Check: CHECK_OK ('db2',' mysql')
[2011-09-28 16:34:28]: 24608: Daemon: State change (db2): HARD_OFFLINE-> AWAITING_RECOVERY
[2011-09-28 16:34:29]: 24608: Daemon: State change (db2): AWAITING_RECOVERY-> ONLINE. Uptime diff = 306.320000000065 seconds; Status change diff = 1317198869
[root@CentOS var] # mmm_control show
Servers status:
Db1 (211.100.97.246): master/ONLINE. Roles: reader (211.100.97.244;), writer (211.100.97.248;)
Db2 (211.100.97.250): master/ONLINE. Roles: reader (211.100.97.243;)
Through the above tests, it is proved that the whole construction is successful, the high availability has been realized, and the automatic switching of failed nodes has been realized.
Eighth attachment-A brief introduction to MMM
MMM (mysql Master replication Manager) A scalable suite of scripts for monitoring, failover, and management of mysql master replication configurations (only one node can be written at any time). This suite can also load balance any number of slave servers that reside in the standard master-slave configuration, so you can use it to launch virtual ip on a group of replicated servers In addition, it has scripts that implement data backup and resynchronization between nodes.
MySQL itself does not provide a replication failover solution, through the MMM scheme to achieve server failover, so as to achieve the high availability of mysql.
The official website is:
The main functions of Mmm are provided by the following three scripts
L mmm_mond is responsible for all the monitoring work of the monitoring daemon, determining the removal of nodes, etc.
L mmm_agentd an agent daemon running on a server that is provided to the monitoring node through a simple set of remote services
L mmm_control manages the mmm_mond process through the command line
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.