Background: The previously implemented MySQL synchronous replication feature (see author before article http://blog.csdn.net/kingofworld/article/details/39210937) is only a dual-machine hot standby function, Still can't do the Mysql link itself actively switch.
This configuration implements a true MySQL cluster. This allows the application to actively switch to the MySQL connection of another machine when the MySQL application of one machine is stopped, so as to achieve high stability of the application. It also makes it possible to extend the Mysql service.
This configuration implements cluster functionality using the Mysql-mmm (master-master Replication Manager for MySQL) component.
This demo is configured using three machines, such as the following:
Master1 and Master2 Two machines for dual-machine hot standby. One of the machines has a MySQL service stop or a machine outage. The application will connect to the database itself to switch to another machine.
In addition, the Master1 data is backed up in real time with one machine .
1. Installation mysql-mmm service
Installed on all three machines
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RPM-IVH epel-release-6-8.noarch.rpm
Yum-y Install mysql-mmm*
Check rpm-qa|grep mysql-mmm after completion
The following component indicates a successful installation
Rhel5 or centos5,32 bit:/http/dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
Rhel6 or centos6,32 bit:/http/dl.fedoraproject.org/pub/epel/6/i386/ epel-release-6-5.noarch.rpm
Rhel6 or centos6,64 bit:http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
1 . Users who join MySQL
MySQL users are added to all three machines . For copying,
Go to MySQL service mysql-u root-p
Use MySQL;
Grant REPLICATION slave,replication CLIENT on * * to ' repl ' @ '% ' identified by ' password '; Create a replication user
Grant Process,super,replication CLIENT on * * to ' mmm_agent ' @ ' percent ' identified by 'password'; //build agent User
Grant REPLICATION CLIENT on * * to ' mmm_monitor ' @ ' percent ' identified by 'password'; //Build User
FLUSH privileges;
2. Configuring synchronous replication
Configure the replication policy as seen in the schema diagram.
Configuration method In my previous article has been introduced, here no longer repeated. See the author's previous article http://blog.csdn.net/kingofworld/article/details/39210937
3. Change the hosts
Change the hosts file for three machines separately
Vi/etc/hosts
Join
200.200.168.24 M1
200.200.168.25 M2
200.200.168.23 slave1
4, configuration mysql-mmm
Change/etc/mysql-mmm/mmm_common.conf the configuration of each machine is the same
active_ Master_role writer
Note: 200.200.168.26 and 200.200.168.27 are two virtual IP addresses that can be used by an application, with only two of the IP that no one occupies . To provide write and read services, respectively. For later implementation of the database read/write separation (but to achieve read and write separation needs to change the application.) MySQL does not actively identify and switch on its own).
Change/etc/mysql-mmm/mmm_agent.conf
Three machines are set to this M1,thisM2,thisslave1 , respectively
Change/etc/mysql-mmm/mmm_mon.conf
Only monitor (200.200.168.24) needs to be configured
Include mmm_common.conf<monitor> IP 127.0.0.1 pid_path /var/run/mysql-mmm/mmm_mond.pid bin_path /usr/libexec/mysql-mmm status_path /var/lib/mysql-mmm/mmm_mond.status ping_ips 200.200.168.24,200.200.168.25,200.200.168.23 auto_set_online # The Kill_host_bin does not exist by default, though the monitor would # throw a warning about it missing. See the sections 5.10 "Kill Host # functionality" in the PDF documentation. # # kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host #</monitor>
After the configuration is complete, execute
Three machines are required to perform:
/etc/init.d/mysql-mmm-agent start
Monitor Machine execution
/etc/init.d/mysql-mmm-monitor start
5. Check Service status and test
perform Mmm_control show on Monitor
Can see the following information:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqva2luz29md29ybgq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Indicates that write server (200.200.168.26) is using 200.200.168.24
Read server (200.200.168.27) is using 200.200.168.25
To view the status of individual services:
Mmm_control checks All
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqva2luz29md29ybgq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
6. Test:
Stop the master1 mysql service. Then mmm_control Show View status
Can see the read-write server is transferred to the Master2, then the servermaster1 process application can also be used normally. Ability to conduct application process testing
Then view Mmm_control checks all
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqva2luz29md29ybgq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Start the master1 mysql service and check the status:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqva2luz29md29ybgq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Read and write server is separated.
Using mysql-mmm to implement MySQL high-availability clusters