1. Story Review
On the previous blog, I did a MySQL master-slave configuration experiment, linked in this: http://blog.51cto.com/superpcm/2094958. Here I decided to make these two databases to master from each other, and then in the two mutual primary from the database configuration keepalived, to achieve high availability, how to configure can refer to my previous high-availability experiment blog, http://blog.51cto.com/superpcm/2095395.
The final topology diagram is implemented as follows:
2. Configure MySQL to master replication from each other
Before it may not be stated, the experiment defaults to open all ports to the same network segment, iptables inside the set.
Iptables-i input-s 192.168.31.0/24-j Accept/etc/init.d/iptables Save
(1) Set MYSQL02 (original from database) configuration file, Vim/etc/my.ini, add a line log-bin, and then restart the database:/etc/init.d/mysqld restart
(2) Check the master status on the MySQL02 and record the file and position data.
(3) Add change master on the MYSQL01 database.
Change MASTER tomaster_host= ' 192.168.31.53 ', master_port=3306,master_user= ' rep ', master_password= ' pcm123456 ', Master_log_file= ' mysql-bin.000004 ', master_log_pos=712372;
(4) Start slave to view the status of slave. It succeeds here, and if you want to test it, you can test it as you did in the previous blog post.
3. Use keepalived to achieve high availability of the database.
(1) Install keepalived software, set to boot
Yum Install Keepalivedecho "/etc/init.d/keepalived start" >>/etc/rc.local
(2) Configure the keepalived configuration file, the main configuration is as follows.
(3) Start the Keepalived software to check if the vip:192.168.31.54 is generated on the MySQL01
(4) above appears only on the MySQL01 VIP is successful, can be closed on 01 keepalived and then check 02 will not appear VIP. Then check with other devices to see if you can log on to MySQL via VIP. Here because I was in front of WEB01 and web02 built WordPress, I directly modify the wordpress configuration file, the database point to 192.168.31.54.
vim/usr/local/nginx/html/blog/wp-config.php
Define (' Db_host ', ' 192.168.31.54 ');
(5) Landing WordPress, the results found normal, more test results here do not provide.
MySQL Mutual master from +keepalived High-availability DB cluster