侧边栏壁纸
博主头像
爱运维 博主等级

行动起来,活在当下

  • 累计撰写 197 篇文章
  • 累计创建 143 个标签
  • 累计收到 21 条评论

目 录CONTENT

文章目录

lvs+keepalived中keepalived.conf里面参数详解

Administrator
2017-01-15 / 0 评论 / 0 点赞 / 1 阅读 / 0 字
[root@master ~]# cat /etc/keepalived/keepalived.conf  
! Configuration File for keepalived
global_defs {  
   notification_email {   
      351937287@qq.com #配置管理员邮箱   
   }   
   notification_email_from root #配置发件人   
   smtp_server 127.0.0.1 #配置邮件服务器   
   smtp_connect_timeout 30   
   router_id LVS_DEVEL   
}
vrrp_script chk_mantaince_down {    #定义脚本检测
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"    #检测文件是否存在,存在返回1,不存在0
   interval 1                    #1秒检测一次
   weight -2                     #失败后权重-2
    fall  2                      #失败判断2次
   rise  1                        #成功判断1次
}
vrrp_instance VI_1 {  
    state MASTER #配置模式   
    interface eth0   #vip绑定接口
    virtual_router_id 51   #router_id
    priority 101 #配置优先级   
    advert_int 1   
    authentication {   
        auth_type PASS   #认证
        auth_pass 1111   #认证密码
    }   
    virtual_ipaddress {   
        192.168.18.200 #配置虚拟IP地址   
    }
        track_script {                           #配置执行上面定义的脚本
                chk_mantaince_down         上面定义的脚本
            }   
        notify_master "/etc/keepalived/notify.sh master"    当切换主节点执行    通常用于发邮件通知管理员
            notify_backup "/etc/keepalived/notify.sh backup"  当切换备节点执行
            notify_fault "/etc/keepalived/notify.sh fault"       当切无法连接执行
}
virtual_server 192.168.18.200 80 {   #lvs配置部分,设置IP 端口
    delay_loop 6   
    lb_algo rr                       #设置权重模型
    lb_kind DR                       #DR模型
    nat_mask 255.255.255.0   
    #persistence_timeout 50             #长连接超时
    protocol TCP                        
    real_server 192.168.18.201 80 { #配置rs 
        weight 1   
        HTTP_GET {          #监控配置   ,通过HTTP监控,还有ssl,tcp,smtp
            url {   
              path /        #监控网址
             status_code 200      #检测状态码200
            }   
            connect_timeout 2  #检测时长
            nb_get_retry 3   
            delay_before_retry 1   
        }   
    }   
    real_server 192.168.18.202 80 {   
        weight 1   
        HTTP_GET {   
            url {   
              path /   
              status_code 200   
            }   
            connect_timeout 2   
            nb_get_retry 3   
            delay_before_retry 1   
        }   
    }   
     sorry_server 127.0.0.1 80   #增加一行sorry_server ,当所有节点挂掉就启用临时页面
}






下面是一个notify.sh脚本的简单示例:
#!/bin/bash
# 
# 
# 

vip=172.16.100.1
contact='root@localhost'

notify() {
    mailsubject="`hostname` to be $1: $vip floating"
    mailbody="`date '+%F %H:%M:%S'`: vrrp transition, `hostname` changed to be $1"
    echo $mailbody | mail -s "$mailsubject" $contact
}

case "$1" in
    master)
        notify master
        /etc/rc.d/init.d/haproxy start
        exit 0
    ;;
    backup)
        notify backup
        /etc/rc.d/init.d/haproxy stop
        exit 0
    ;;
    fault)
        notify fault
        /etc/rc.d/init.d/haproxy stop
        exit 0
    ;;
    *)
        echo 'Usage: `basename $0` {master|backup|fault}'
        exit 1
    ;;
esac


0

评论区