Mysql + Keepalived bis availability Hot Standby master recording operation

Mysql + Keepalived bis availability Hot Standby master recording operation

surroundings:

ubuntu18.04.2

mysql5.7.21

1 # 1 ) and mounted keepalived system configured to service. The same operation as follows on two machines master1 and master2:
 2 APT - GET for libssl the install - dev
 . 3 APT - GET the install OpenSSL
 . 4 APT - GET libpopt the install - dev
 . 5  [ the root master1 @ ~ ] # CD / usr / local / the 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/

Prior to ensure their high availability standby or mysql is already a mutual backup, mysql mutual backup operations see my last article:  https://www.cnblogs.com/-admin-/p/11654318. html

The set ip:
vip: 192.168.85.142
01: 192.168.85.140
02: 192.168.85.141

Please change the appropriate ip according to their own needs

# 01 keepalived.conf configuration 
! The Configuration File  for keepalived 
       
global_defs { 
notification_email { 
    759 571 872 @qq .com 
# alarm mail recipient address 
} 
       
notification_email_from 759 571 872 @qq .com 
smtp_server 127.0 . 0.1  
smtp_connect_timeout 30 
ubuntu001 
} 
       
vrrp_script chk_mysql_port {      
# detection mysql services It is running. There are many ways, such as process, script testing, etc. 
    Script " / opt / chk_mysql.sh"    
    # script here by monitoring 
    interval The 2                    
    # script execution interval, tested once every 2s 
    weight- 5                     
    priority # script changes result of detection failure (script returns a non-zero) the priority - 5 
    Fall 2                     
    # 2 consecutive failure detection is considered to determine the true failure. Priority will be reduced by weight ( 1 - between 255) 
    Rise 1                     
    # 1 Detection successful even if successful. But does not modify the priority 
} 
       
vrrp_instance VI_1 { 
    State the MASTER     
    interface ens33       
    # ip of the specified virtual network interface 
    mcast_src_ip 192.168 . 85.140 
    virtual_router_id 51 is     
    # router identification, the MASTER and BACKUP must be consistent 
    priority 101             
    # define the priority, the larger the number, the priority higher, under the same vrrp_instance, MASTER priority must be higher than the priority of BACKUP. MASTER recovery after this, you can again win back the VIP resource 
    advert_int . 1          
    authentication {    
        AUTH_TYPE the PASS
        auth_pass 123456     
    }
    virtual_ipaddress {    
        192.168.85.142
    }
      
track_script {               
   chk_mysql_port             
}
}

01 server configured.

Next, configure the server 02:

# 02 keepalived.conf configuration 
! The Configuration File  for keepalived 
       
global_defs { 
notification_email { 
    759 571 872 @qq .com 
# alarm mail recipient address 
} 
       
notification_email_from 759 571 872 @qq .com 
smtp_server 127.0 . 0.1  
smtp_connect_timeout 30 
ubuntu002 
} 
       
vrrp_script chk_mysql_port {      
# detection mysql services It is running. There are many ways, such as process, script testing, etc. 
    Script " / opt / chk_mysql.sh"    
    # script here by monitoring 
    interval The 2                    
    # script execution interval, tested once every 2s 
    weight- 5                     
    priority # script changes result of detection failure (script returns a non-zero) the priority - 5 
    Fall 2                     
    # 2 consecutive failure detection is considered to determine the true failure. Priority will be reduced by weight ( 1 - between 255) 
    Rise 1                     
    # 1 Detection successful even if successful. But does not modify the priority 
} 
       
vrrp_instance VI_1 { 
    State BACKUP     
    interface ens33       
    # ip of the specified virtual network interface 
    mcast_src_ip 192.168 . 85.141 
    virtual_router_id 51 is     
    # router identification, the MASTER and BACKUP must be consistent 
    priority 99             
    # define the priority, the larger the number, the priority higher, under the same vrrp_instance, MASTER priority must be higher than the priority of BACKUP. MASTER recovery after this, you can again win back the VIP resource 
    advert_int . 1          
    authentication {    
        AUTH_TYPE the PASS
        auth_pass 123456     
    }
    virtual_ipaddress {    
        192.168.85.142
    }
      
track_script {               
   chk_mysql_port             
}
}

Scripting:

#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

Thus, Mysql + Keepalived double hot standby master availability been configured.

Guess you like

Origin www.cnblogs.com/-admin-/p/11683318.html