Maintained + MySQL primary high availability
1, Environment introduction:
10.1.1.174:23316 M1
10.1.1.237:23316 M2
2, Configure dual master: omitted.
3, keepalive installation
[root@master1 ~]# cd /usr/local/src/ [root@master1 src]# wget https://www.keepalived.org/software/keepalived-2.0.17.tar.gz [root@master1 src]# tar -xf keepalived-2.0.17.tar.gz [root@master1 src]# cd keepalived-2.0.17 [root@master1 keepalived-2.0.17]# yum install openssl* libnlâdev* gcc-c++ [root@master1 keepalived-2.0.17]# ./configure --prefix=/usr/local/keepalived [root@master1 keepalived-2.0.17]# make [root@master1 keepalived-2.0.17]# make install
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ echo "/etc/init.d/keepalived start" >> /etc/rc.local mkdir -p /etc/keepalived/ mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
M1:keepalive Profile: vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived vrrp_script chk_mysql_port { #Check if mysql service is running. There are many ways, such as process, script detection, etc script "/etc/keepalived/chk_mysql.sh" #Script monitoring here interval 2 #Script execution interval, every 2s weight -5 #Priority change caused by script result. If the detection fails (the script returns non-0), the priority is - 5 fall 2 #If the detection fails twice in a row, it is determined to be a true failure. Reduce priority with weight (between 1-255) rise 1 #A successful test is a success. But do not change priority } vrrp_instance VI_1 { state MASTER interface ens192 #Specify the network interface of virtual ip, change it to your own eth0 or something # mcast_src_ip 10.1.1.174 virtual_router_id 51 #Router ID, MASTER and BACKUP must be consistent priority 101 #Define the priority. The larger the number is, the higher the priority is. Under the same VRRP? Instance, the priority of MASTER must be greater than that of BACKUP. In this way, VIP resources can be retrieved again after MASTER fails to recover unicast_src_ip 10.1.1.174 ##(local IP address) unicast_peer { 10.1.1.237 ##(opposite IP address) this address must not be forgotten } advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.1.1.111 } track_script { chk_mysql_port } } [root@crm-db01 ~]# cat /etc/keepalived/chk_mysql.sh #####Pay attention to executable rights #!/bin/bash counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l) if [ "${counter}" -eq 0 ]; then /etc/init.d/keepalived stop fi
M2: keepalived Profile: [root@#localhost keepalived]# cat keepalived.conf ! Configuration File for keepalived vrrp_script chk_mysql_port { script "/etc/keepalived/chk_mysql.sh" interval 2 weight -5 fall 2 rise 1 } vrrp_instance VI_1 { state BACKUP interface ens192 #Specify the network interface of virtual ip, change it to your own eth0 or something #mcast_src_ip 10.1.1.237 virtual_router_id 51 priority 90 unicast_src_ip 10.1.1.237 ##(local IP address) unicast_peer { 10.1.1.174 ##(opposite IP address) this address must not be forgotten } advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.1.1.111 } track_script { chk_mysql_port } } [root@#localhost keepalived]# cat chk_mysql.sh #####Pay attention to executable rights #!/bin/bash counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l) if [ "${counter}" -eq 0 ]; then /etc/init.d/keepalived stop fi
start-up keepalived service [root@master1 ~]# /etc/init.d/keepalived start //Common commands: /etc/init.d/keepalived restart|start|stop /etc/init.d/mysqld restart|start|stop //To view the keepalive status: systemctl status keepalived.service //To view the log: tail -f /var/log/messages
4, Possible problems:
1. Start two keepalived, VIP s on both sides. My configuration file has been modified. This should not happen. 2.VIP after getting up, you cannot access the MySQL database through the VIP. Turn off the firewall or open related ports. Check your MySQL configuration file to see if it has the parameter "bind address = 10.1.1.237". If so, comment it out and restart the database.