mysql主从加MHA+keepalived部署(四) —— keepalived部署安装

相关文章:

mysql主从加MHA+keepalived部署(一)——mysql安装:

https://blog.csdn.net/royzhang7/article/details/100031390

mysql主从加MHA+keepalived部署(二)——mysql主从配置:

https://blog.csdn.net/royzhang7/article/details/100031462

mysql主从加MHA+keepalived部署(三)——mha部署安装: 

https://blog.csdn.net/royzhang7/article/details/100031601

 

环境:
192.168.3.3 redhat7.5
192.168.3.4 redhat7.5


--安装keepalived,两个节点均安装,光盘安装

 yum install keepalived
 
 
--mha node 3.3 配置keepalived

vi /etc/keepalived/keepalived.conf

 

! Configuration File for keepalived
global_defs{

   router_id MHA_01
   script_user root
   enable_script_security 
}

 

vrrp_script check_mysql {

  script "/etc/keepalived/ck_mysql.sh"
  interval 2
  weight -20

}
                                                   

vrrp_instance VI_1 {

    state BACKUP          
    interface ens33
    virtual_router_id 60
    priority 100              
    advert_int 1
    authentication {
    
        auth_type PASS
        auth_pass 1111

    }

    virtual_ipaddress {
      192.168.3.5/24
    }

    nopreempt

    track_script {
      check_mysql
    }

}


--mha master 3.4 配置keepalived

! Configuration File for keepalived
global_defs {

   router_id MHA_02
   script_user root
   enable_script_security 
}

vrrp_script check_mysql {

  script "/etc/keepalived/ck_mysql.sh"
  interval 2
  weight -20

}                                                    

vrrp_instance VI_1 {

    state BACKUP       
    interface ens33
    virtual_router_id 60
    priority 90       
    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

      192.168.3.5/24

    }

    track_script {

      check_mysql

    }

}

--两个节点添加ch_mysql.sh
vi /etc/keepalived/ck_mysql.sh

#!/bin/sh

mysql -utest -ptest123 -e "select version()" >/dev/null 2>&1

if[ $? -eq 0 ];then

  exit 0

else

  exit 1

fi


--两个节点创建test连接用户
CREATE USER 'test'@'%' IDENTIFIED BY 'test123';
flush privileges;


--两节点启动keepalived
systemctl start keepalived

--查看启动情况日志
tail -100 /var/log/messages


--确认vip是否能ping通

ping 192.168.3.5


--测试关闭主库,观察mha failover 日志

--3.3
systemctl stop mysqld

--3.4 tail -f /usr/local/mha/manager.log

----- Failover Report -----

mha: MySQL Master failover 192.168.3.3(192.168.3.3:3306) to 192.168.3.4(192.168.3.4:3306) succeeded

Master 192.168.3.3(192.168.3.3:3306) is down!

Check MHA Manager logs at zhangry-test2:/usr/local/mha/manager.log for details.

Started automated(non-interactive) failover.
Selected 192.168.3.4(192.168.3.4:3306) as a new master.
192.168.3.4(192.168.3.4:3306): OK: Applying all logs succeeded.
192.168.3.4(192.168.3.4:3306): Resetting slave info succeeded.
Master failover to 192.168.3.4(192.168.3.4:3306) completed successfully.


--3.4 ip addr |grep 192.168.3.

    inet 192.168.3.4/24 brd 192.168.3.255 scope global noprefixroute ens33
    inet 192.168.3.5/24 scope global secondary ens33
    
vip已切换至备节点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值