keepalived+MySQLマスター高が利用可能

3811 ワード

keepalived+MySQLマスター高が利用可能
一、環境紹介:
10.1.1.174:23316 M1 10.1.1.237:23316 M2
二、双主を配置する:略.
三、keepalive取付
[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 /root/keepalived.conf.bak
M1:keepalive    :
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

vrrp_script chk_mysql_port {     #  mysql       。     ,    ,       
    script "/etc/keepalived/chk_mysql.sh"   #        
    interval 2                   #      , 2s    
    weight -5                    #            ,    (     0)     -5
    fall 2                    #    2           。  weight     (1-255  )
    rise 1                    #  1       。       
}

vrrp_instance VI_1 {
    state MASTER    
    interface ens192      #    ip     ,       eth0       
   # mcast_src_ip 10.1.1.174
    virtual_router_id 51    #     ,MASTER BACKUP      
    priority 101            #     ,    ,     ,    vrrp_instance ,MASTER        BACKUP    。  MASTER     ,    VIP        
    unicast_src_ip  10.1.1.174 ##(  IP  )
    unicast_peer {
                  10.1.1.237 ##(  IP  )         
                       }
    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         #####       
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l)
if [ "${counter}" -eq 0 ]; then
    /etc/init.d/keepalived stop
fi
M2:keepalived    :
[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             #    ip     ,       eth0               
    #mcast_src_ip 10.1.1.237
    virtual_router_id 51
    priority 90
    unicast_src_ip  10.1.1.237 ##(  IP  )
    unicast_peer {
                  10.1.1.174       ##(  IP  )         
                       }
    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           #####       
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l)
if [ "${counter}" -eq 0 ]; then
    /etc/init.d/keepalived stop
fi
  keepalived  
[root@master1 ~]# /etc/init.d/keepalived start
    :
/etc/init.d/keepalived restart|start|stop
/etc/init.d/mysqld restart|start|stop
  keepalive  :
systemctl status keepalived.service
    :
tail -f /var/log/messages

四、発生する可能性のある問題:
1.    keepalived ,    VIP。
            ,          。
2.VIP   ,    VIP  MySQL   。
             。
    MySQL    ,         #bind-address = 10.1.1.237,      ,     。