• keepalived 安装及配置VIP漂移


    环境:

    主机 10.10.6.105

    备机 10.10.6.106

    VIP  10.10.6.188

    一、安装

    yum install keepalived -y

    二、配置文件(/etc/keepalived/keepalived.conf)

    主机配置

    global_defs {
       notification_email {
         acassen@firewall.loc
         failover@firewall.loc
         sysadmin@firewall.loc
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server 192.168.200.1
       smtp_connect_timeout 30
       router_id LVS_DEVEL
       vrrp_skip_check_adv_addr
      #注释下行否则ping 不通 #vrrp_strict vrrp_garp_interval
    0 vrrp_gna_interval 0 } #脚本监控 vrrp_script chk_mysql { script "/etc/keepalived/check_mysql.sh" interval 2 weight 2 } vrrp_instance VI_1 { #主机设置master
       state MASTER
      #监听网卡设置
    interface ens32 #虚拟路由ID 保持主从配置相同
      virtual_router_id
    51
    #权重主的大于从的
    priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 }
    #引用脚本 track_script { chk_mysql }
      #虚拟IP设置 virtual_ipaddress {
    10.10.6.188 } }

    从机配置与主机大致相同

    #vrrp_strict
    state BACKUP
    priority 90

    监控脚本(/etc/keepalived/check_mysql.sh )

    #scripts is check for Mysql Slave status
    counter=$(netstat -na|grep "LISTEN"|grep "8080"|wc -l)
    if [ "${counter}" -eq 0 ]; then
        echo 'not found'
    else
        echo 'pass'
    fi

    三、测试

    日志查看

    tail -f /var/log/messages

    两台机器,启动端口

    nc -vl 8080

    两台机器,启动服务

    service keepalived start

    关闭主机8080端口后日志

    Nov 7 05:28:17 localhost Keepalived[47369]: Stopping
    Nov 7 05:28:17 localhost systemd: Stopping LVS and VRRP High Availability Monitor...
    Nov 7 05:28:17 localhost Keepalived_vrrp[47371]: VRRP_Instance(VI_1) sent 0 priority
    Nov 7 05:28:17 localhost Keepalived_vrrp[47371]: VRRP_Instance(VI_1) removing protocol VIPs.
    Nov 7 05:28:17 localhost Keepalived_healthcheckers[47370]: Stopped
    Nov 7 05:28:18 localhost Keepalived_vrrp[47371]: Stopped
    Nov 7 05:28:18 localhost Keepalived[47369]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
    Nov 7 05:28:18 localhost systemd: Stopped LVS and VRRP High Availability Monitor.

    查看从机已经转移VIP

    [root@localhost keepalived]# ip a|grep 188
    inet 10.10.6.188/32 scope global ens32

    漂移过程中无任何延迟问题,ping 返回正常,重启服务后vip 又返回主机

  • 相关阅读:
    用Iterator实现遍历集合
    SimpleDateFormat使用详解 <转>
    Java学习之Iterator(迭代器)的一般用法 (转)
    Java:String和Date、Timestamp之间的转换
    关于PreparedStatement.addBatch()方法 (转)
    JavaBean入门及简单的例子
    Tomcat7.0无法启动解决方法[failed to start]
    executeQuery、executeUpdate 和 execute
    jquery中attr和prop的区别
    Jquery的parent和parents(找到某一特定的祖先元素)
  • 原文地址:https://www.cnblogs.com/maoxianfei/p/9924594.html
Copyright © 2020-2023  润新知