Background: The mysql synchronization replication function (see the previous article http: blogcsdnnetkingofworldarticledetails39210937) is only a dual-host hot standby function and cannot automatically switch Mysql connections. The configuration of the real mysql Cluster, making in the background: the mysql synchronization replication function (see the author's article http://blog.csdn.net/kingofworld/article/details/39210937) is just a dual-machine hot standby function, can not achieve the Mysql link automatic switch.
This configuration implements a real mysql Cluster, enabling the application to automatically switch to the mysql connection of another host when the mysql application of a certain machine is stopped to achieve high application stability, it also makes it possible to expand the Mysql service.
This configuration uses the mysql-mmm (master-master Replication Manager for MySQL) component to implement cluster functions.
The configuration in this demonstration uses three Machines. the architecture is as follows:
Master 1 and Master2 enable hot standby on both servers. when the mysql service of one server is stopped or the machine is down, the application automatically switches the database connection to another server. In addition, a host is used to back up master1 data in real time.
1. install the mysql-mmm service
Install 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 *
View rpm-qa | grep mysql-mmm
The following components indicate that the installation is successful:
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. add mysql Users
Add mysql Users 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' @ '% 'identified by 'password'; // Create an agent user
Grant replication client on *. * to 'Mmm _ monitor' @ '%' identified by 'password'; // Create a user
Flush privileges;
2. configure synchronous replication
Shows the architecture diagram of the replication policy configuration.
The configuration method has been introduced in my previous article, here is no longer repeated, see the author's previous article http://blog.csdn.net/kingofworld/article/details/39210937
3. modify hosts
Modify the hosts files of the three machines respectively.
Vi/etc/hosts
Add
200.200.168.24 M1
200.200.168.25 M2
200.200.168.23 slave1
4. configure mysql-mmm
Modify/etc/mysql-mmm/mmm_common.conf the configurations of each machine are the same
active_master_role writer
cluster_interface eth0 pid_path /var/run/mysql-mmm/mmm_agentd.pid bin_path /usr/libexec/mysql-mmm/ replication_user repl replication_password password agent_user mmm_agent agent_password password
ip 200.200.168.24 mode master peer M2
ip 200.200.168.25 mode master peer M1
ip 200.200.168.23 mode slave
hosts M1,M2 ips 200.200.168.26 mode exclusive
hosts M1,M2,slave1 ips 200.200.168.27 mode balanced
Note: 200.200.168.26 and 200.200.168.27 are two virtual IP addresses, which are used to provide write and read Services for program calls, for the future implementation of database read/write splitting (but the implementation of read/write splitting requires modifying the application, mysql cannot automatically identify and switch ).
Modify/etc/mysql-mmm/mmm_agent.conf
The three machines are set to this M1, this M2, and this slave1 respectively.
Modify/etc/mysql-mmm/mmm_mon.conf
Only the monitor (200.200.168.24) sub-host needs to be configured
include mmm_common.conf
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 10 # 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 mmm_monitor monitor_password password
debug 0
Run After configuration is complete
All three machines need to run:
/Etc/init. d/mysql-mmm-agent start
Monitor sub-run
/Etc/init. d/mysql-mmm-monitor start
5. View service status and test
Run mmm_control show on monitor.
You can see the following information:
Indicates that the write server (200.200.168.26) uses 200.200.168.24
The read server (200.200.168.27) uses 200.200.168.25.
View the status of each service:
Mmm_control checks all
6. test:
Stop the mysql service of master1 and check the status of mmm_control show.
You can see that the read and write servers are transferred to master2, and the master1 process application can still be used normally. you can test the application process.
Check mmm_control checks all
Start the mysql service of master1 and check the status again:
The read/write servers are separated.