zoukankan      html  css  js  c++  java
  • keepalived 实战

    两个节点:10.0.2.18   和 10.0.2.19

    1、安装:yum install -y keepalived

    2、查看配置文件位置:rpm -qc keepalived

    3、修改配置文件:

    10.0.2.18上的配置文件:
    global_defs {
      router_id zcylb
    }
    vrrp_instance VI_1 {
      state MASTER
      interface enp0s3
      unicast_peer {
          10.0.2.19
      }
      virtual_router_id 51
      priority 100 advert_int 1
      authentication {
        auth_type PASS
        auth_pass 1111
      }
      virtual_ipaddress {
            10.0.2.250 dev enp0s3    
      }
    }

    其中
    10.0.2.250 是我随便设的一个没有被使用的ip,因为我的网卡叫enp0s3,所以配置文件里写的是enp0s3
    
    
    10.0.2.19上的配置文件:
    global_defs {
      router_id zcylb
    }
    vrrp_instance VI_1 {
      state BACKUP
      interface enp0s3
      unicast_peer {
          10.0.2.18
      }
      virtual_router_id 51
      priority 90
      advert_int 1
      authentication {
        auth_type PASS
        auth_pass 1111
      }
      virtual_ipaddress {
          10.0.2.250 dev enp0s3
      }
    }

    4、启动keepalived

    service keepalived start

    5、查看效果

     

     6、停掉master的keepalived

    service keepalived stop  , 发现虚拟ip漂移了

    注:在启停keepalived时,也可以查看日志 

    tail -f /var/log/messages

     ==============

    ==下面给keepalived加上执行脚本===

    ==============

    10.0.2.18上的配置文件:
    global_defs {
      router_id zcylb
      script_user root
    }
    vrrp_script check_docker 
    {
        script "/home/check_docker_by_keep.sh"
        interval 5
        user root
    }
    vrrp_instance VI_1 {
      state MASTER
      interface enp0s3
      unicast_peer {
          10.0.2.19
      }
      virtual_router_id 51
      priority 100 advert_int 1
      authentication {
        auth_type PASS
        auth_pass 1111
      }
      track_script {
            check_docker
        }
      virtual_ipaddress {
            10.0.2.250 dev enp0s3
      }
    }


    ========
    10.0.2.19上的配置文件
    
    

    global_defs {
    router_id zcylb
    script_user root
    }
    vrrp_script check_docker {
    script "/home/check_docker_by_keep.sh"
    interval 5
    }
    vrrp_instance VI_1 {
    state BACKUP
    interface enp0s3
    unicast_peer {
    10.0.2.18
    }
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    track_script {
    check_docker
    }
    virtual_ipaddress {
    10.0.2.250 dev enp0s3
    }
    }

    [root@zcy ~]# cat /home/check_docker_by_keep.sh 
    #!/bin/bash
    
    A=$(service docker status | grep ' active (running)')
    if [ "${A}" ] 
    then
        echo "runing zcy"
        echo "runing zcy" >> /home/mylog
    else
        #service keepalived stop
        echo "not runing" >> /home/mylog
        service keepalived stop
    
    fi 
    当需要keepalived执行脚本时,需要脚本有可执行权限,且要关闭SELINUX
    
    sudo setenforce 0
    sudo sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/’ /etc/selinux/config

    判断脚本可以被成功执行:

    grep 'VRRP_Script(check_docker) succeeded' /var/log/messages

    查看绑定效果

    ip add show
  • 相关阅读:
    第二篇:如何在IIS上启用HTTP压缩
    This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its 错误解决办法
    linux字符集查看与设置
    MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
    SELinux状态修改
    zabbix server is not running解决办法
    mysql存储过程之事务篇
    mysql时间相减的问题
    MySql存储过程及MySql常用流程控制语法
    shell 字符串处理汇总(查找,替换等等)
  • 原文地址:https://www.cnblogs.com/testzcy/p/15369483.html
Copyright © 2011-2022 走看看