zoukankan      html  css  js  c++  java
  • Keepalived实战(3)

    一、环境

    如上图所示:

    keepalived的mater为proxy-master,keepalived的slave为proxy-slave。

    要求:当mater出现问题时,主动切换到slave上。这里只是进行简单的主从切换展示,后续会有专门一节将zabbix proxy高可用方式。

    二、配置文件

    1、master的配置文件

    cat keepalived.conf
    ! Configuration File for keepalived

    global_defs {
    notification_email {
    xuequn@kingsoft.com
    }
    notification_email_from zabbix@kingsoft.com
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id LVS_DEVEL
    }

    vrrp_script chk_zabbix_web {

    script "killall -0 zabbix_proxy"
    interval 10
    weight 20

    }


    vrrp_instance VI_ZBX_WEB {
    state BACKUP  #注意,这里因为考虑到切换成slave后我不再切回来,所以也配置成backup,且为nopreempt模式
    nopreempt #when myself is master,set this option.
    interface eth0
    virtual_router_id 160
    priority 100
    advert_int 1
    mcast_src_ip 192.168.1.102
    authentication {
    auth_type PASS
    auth_pass ZabbixServer
    }
    track_script {

    chk_zabbix_web

    }
    virtual_ipaddress {
    192.168.1.100
    }

    #notify_master "/etc/keepalived/change_to_master.sh"
    notify_backup "/etc/keepalived/change_to_backup.sh"   #切换为backup后,执行的脚本
    }

    slave上的配置:

    cat keepalived.conf
    ! Configuration File for keepalived

    global_defs {
    notification_email {
    xuequn@kingsoft.com
    }
    notification_email_from zabbix@kingsoft.com
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id LVS_DEVEL
    }


    vrrp_script chk_zabbix_web {

    script "killall -0 zabbix_agentd"
    interval 10
    weight 20


    }


    vrrp_instance VI_ZBX_WEB {
    state BACKUP
    #nopreempt #when myself is master,set this option.
    interface eth1
    virtual_router_id 160
    priority 90
    advert_int 1
    mcast_src_ip 192.168.1.101
    authentication {
    auth_type PASS
    auth_pass ZabbixServer
    }
    track_script {

    chk_zabbix_web

    }
    virtual_ipaddress {
    192.168.1.100

    }

    notify_master "/etc/keepalived/change_to_master.sh"  #切换为master后,执行的脚本
    #notify_backup "/etc/keepalived/change_to_backup.sh"
    }

    三、启动并测试

    1、正常启动

    2、故障切换

    3、nopreempt测试

    PS:本文纯属记录个人实践经历,如有问题,可随时联系我。QQ505711559

  • 相关阅读:
    图片上传前预览、压缩、转blob、转formData等操作
    Vue背景图打包之后访问路径错误
    图片上传前预览的功能
    总结div里面水平垂直居中的实现方法
    IE浏览器报Promise未定义的错误、解决vuex requires a Promise polyfill in this browser问题
    普通项目转换成maven项目
    HTTP 错误 404.0
    电商项目系列文档(四):售后的设计(退换货)
    Sqlserver数据库还原.bak文件失败的两个问题
    数据库字段顺序的【坑】
  • 原文地址:https://www.cnblogs.com/skyflask/p/6970110.html
Copyright © 2011-2022 走看看