MySQL + maintained dual active hot standby highly available operation records

Keywords: MySQL network OpenSSL

MySQL + maintained dual active hot standby highly available operation records

Environmental Science:

ubuntu18.04.2

mysql5.7.21

 1 #1)install keepalived And configure it as a system service. master1 and master2 The following operations are also performed on both machines:
 2 apt-get install libssl-dev
 3 apt-get install openssl
 4 apt-get install libpopt-dev
 5 [root@master1 ~]# cd /usr/local/src/
 6 [root@master1 src]# wget http://www.keepalived.org/software/keepalived-1.3.5.tar.gz
 7 [root@master1 src]# tar -zvxf keepalived-1.3.5.tar.gz
 8 [root@master1 src]# cd keepalived-1.3.5
 9 [root@master1 keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived
10 [root@master1 keepalived-1.3.5]# make && make install
11 mkdir /etc/sysconfig
12 cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
13 cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
14 cp /usr/local/keepalived/sbin/keepalived /sbin/
15 mkdir /etc/keepalived
16 cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

Before realizing high availability, make sure that your mysql is active / standby or active / standby. Please refer to my previous article for mysql operation: https://www.cnblogs.com/-admin-/p/11654318.html

ip set this time:
vip:192.168.85.142
01:192.168.85.140
02:192.168.85.141

Please change the corresponding ip according to your needs

#Configuration of keepalived.conf of 01
! Configuration File for keepalived
       
global_defs {
notification_email {
    759571872@qq.com
#Address of the recipient of the alarm message
}
       
notification_email_from 759571872@qq.com
smtp_server 127.0.0.1 
smtp_connect_timeout 30
ubuntu001
}
       
vrrp_script chk_mysql_port {     
#Check if mysql service is running. There are many ways, such as process, script detection, etc.
    script "/opt/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-zero), the priority -5
    fall 2                    
    #If the detection fails twice in a row, it is determined to be a true failure. Will use weight Reduce priority(1-255 Between)
    rise 1                    
    #A successful test is a success. But do not change priority
}
       
vrrp_instance VI_1 {
    state MASTER    
    interface ens33      
    #Specify the network interface of virtual ip
    mcast_src_ip 192.168.85.140
    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. 
    advert_int 1         
    authentication {   
        auth_type PASS 
        auth_pass 123456     
    }
    virtual_ipaddress {    
        192.168.85.142
    }
      
track_script {               
   chk_mysql_port             
}
}

01 server configuration completed.

Next, configure 02 server:

#Configuration of keepalived.conf of 02
! Configuration File for keepalived
       
global_defs {
notification_email {
    759571872@qq.com
#Address of the recipient of the alarm message
}
       
notification_email_from 759571872@qq.com
smtp_server 127.0.0.1 
smtp_connect_timeout 30
ubuntu002
}
       
vrrp_script chk_mysql_port {     
#Check if mysql service is running. There are many ways, such as process, script detection, etc.
    script "/opt/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-zero), the priority -5
    fall 2                    
    #If the detection fails twice in a row, it is determined to be a true failure. Will use weight Reduce priority(1-255 Between)
    rise 1                    
    #A successful test is a success. But do not change priority
}
       
vrrp_instance VI_1 {
    state BACKUP    
    interface ens33      
    #Specify the network interface of virtual ip
    mcast_src_ip 192.168.85.141
    virtual_router_id 51    
    #Router ID, MASTER and BACKUP must be consistent
    priority 99            
    #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. 
    advert_int 1         
    authentication {   
        auth_type PASS 
        auth_pass 123456     
    }
    virtual_ipaddress {    
        192.168.85.142
    }
      
track_script {               
   chk_mysql_port             
}
}

Script:

#vi /opt/chk_mysql.sh
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]; then
    /etc/init.d/keepalived stop
fi

At this point, MySQL + maintained dual active hot standby high availability has been configured.

Posted by Arsench on Wed, 16 Oct 2019 15:07:30 -0700