完整的的KeepAlived配置模板

参考:

http://my.oschina.net/ahanflw/blog/286206 某人的KeepAlived安装步骤

http://my.oschina.net/9981/blog/473209

http://my.oschina.net/ahanflw/blog/286206

下面是KeepAlived的配置模板,以后直接用就行了。

! Configuration File for keepalived
vrrp_script chk_haproxy {    
     script "/etc/keepalived/check_haproxy.sh"    //这里是具体的执行的脚本,包括时间参数
     interval 2    
     weight   2 
}
 
global_defs {
   notification_email {
     837500869@qq.com   }
   notification_email_from 
   smtp_server  smtp.qq.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    nopreempt         这个只要MASTER设置就可以了,SLAVE不用设置,已经亲自测试过。
    interface eth0
    virtual_router_id 51
    mcast_src_ip      这里填上与虚拟IP同一个网段的本机IP!!!
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
     
    track_script {    
     chk_haproxy   //这里写上要执行的脚本ID
    } 

    virtual_ipaddress {
        192.168.200.16
        192.168.200.17
        192.168.200.18
    }
}
 
#virtual_server 192.168.200.100 443 {
#delay_loop 6
#lb_algo rr
#lb_kind NAT
#nat_mask 255.255.255.0
#persistence_timeout 50
#protocol TCP
#real_server 192.168.201.100 443 {
# weight 1
# SSL_GET {
#url {
# path /
#digest ff20ad2481f97b1754ef3e12ecd3a9cc
# }
#url {
#path /mrtg/
#digest 9b3a0c85a887a256d6939da88aabd8cd
#}
#connect_timeout 3
#nb_get_retry 3
#delay_before_retry 3
#}
#}
#}
#virtual_server 10.10.10.2 1358 {
#delay_loop 6
#lb_algo rr 
#lb_kind NAT
#persistence_timeout 50
#protocol TCP
#sorry_server 192.168.200.200 1358
#
#real_server 192.168.200.2 1358 {
#weight 1
# HTTP_GET {
# url { 
#   path /testurl/test.jsp
#digest 640205b7b0fc66c1ea91c463fac6334d
#}
#url { 
# path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url { 
# path /testurl3/test.jsp
#  digest 640205b7b0fc66c1ea91c463fac6334d
# }
# connect_timeout 3
# nb_get_retry 3
# delay_before_retry 3
#}
#}
#real_server 192.168.200.3 1358 {
# weight 1
#HTTP_GET {
#url { 
# path /testurl/test.jsp
#  digest 640205b7b0fc66c1ea91c463fac6334c
# }
# url { 
#  path /testurl2/test.jsp
# digest 640205b7b0fc66c1ea91c463fac6334c
#}
# connect_timeout 3
#  nb_get_retry 3
# delay_before_retry 3
#}
#}
#}
#virtual_server 10.10.10.3 1358 {
#delay_loop 3
# lb_algo rr 
#lb_kind NAT
#nat_mask 255.255.255.0
# persistence_timeout 50
#protocol TCP
#real_server 192.168.200.4 1358 {
# weight 1
# HTTP_GET {
#  url { 
#  path /testurl/test.jsp
#   digest 640205b7b0fc66c1ea91c463fac6334d
# }
# url { 
#   path /testurl2/test.jsp
#      digest 640205b7b0fc66c1ea91c463fac6334d
#     }
#   url { 
#    path /testurl3/test.jsp
#    digest 640205b7b0fc66c1ea91c463fac6334d
#  }
#  connect_timeout 3
#  nb_get_retry 3
# delay_before_retry 3
#  }
# }
#real_server 192.168.200.5 1358 {
# weight 1
#   HTTP_GET {
#       url { 
#        path /testurl/test.jsp
#       digest 640205b7b0fc66c1ea91c463fac6334d
#      }
#      url { 
#        path /testurl2/test.jsp
#      digest 640205b7b0fc66c1ea91c463fac6334d
#     }
#      url { 
#      path /testurl3/test.jsp
#      digest 640205b7b0fc66c1ea91c463fac6334d
#     }
#   connect_timeout 3
#   nb_get_retry 3
#    delay_before_retry 3
#  }
# }
#}

 

真正执行的脚本check_haproxy.sh定义为:需要修改的地方请自行修改。

#!/bin/bash
status=$(ps aux|grep haproxy | grep -v grep | grep -v bash | wc -l)
echo "Start Status:" $status
if [ $status = "0" ] ; then
        echo "haproxy stoped.starting haproxy ..."
         cd /root/haproxy-1.4.23/haproxy-1.4.23/haproxy-1.4.23
        ./haproxy -f ./examples/haproxy.cfg
        sleep 3
        status=$(ps aux|grep haproxy | grep -v grep | grep -v bash | wc -l)
#status="1"
        if [ $status = "0" ] ; then
                pkill keepalived
                echo "haproxy start failed. so keepalived stoped.";
        else
                echo "haproxy started.";
        fi
fi
echo "End Status:" $status

 

启动KeepAlived的命令:

./bin/keepalived -f /root/keepalived-1.2.8/keepalived/etc/keepalived/keepalived.conf -P -l  如果想前台启动则加上-n

 

 

问题:

1 如何手动删除虚拟IP?

启动两个KeepAlived前,务必清除虚拟IP

 ip addr del 这里填写虚拟IP dev eth0

2

转载于:https://my.oschina.net/qiangzigege/blog/506647

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Keepalived是一种基于VRRP协议实现的高可用性解决方案,它可以用于保证网络服务的高可用性。下面是一个简单的Keepalived配置示例: 1. 安装Keepalived 在Linux环境下,可以使用以下命令安装Keepalived: ``` sudo apt-get install keepalived ``` 2. 配置Keepalived Keepalived配置文件位于/etc/keepalived/keepalived.conf。以下是一个基本的Keepalived配置示例,其中包含了两个节点(192.168.1.10和192.168.1.11),它们将共享一个虚拟IP地址(192.168.1.100): ``` ! Configuration File for keepalived global_defs { router_id LVS_DEVEL } vrrp_script chk_nginx { script "/etc/keepalived/check_nginx.sh" interval 2 weight 2 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.100 } track_script { chk_nginx } } virtual_server 192.168.1.100 80 { delay_loop 6 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.1.10 80 { weight 1 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.1.11 80 { weight 1 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } } ``` 在上面的配置中: - global_defs:定义全局变量,这里定义了路由器ID。 - vrrp_script:定义监控脚本,这里使用了一个名为check_nginx.sh的自定义脚本。 - vrrp_instance:定义VRRP实例,这里定义了一个名为VI_1的实例,它的状态为MASTER。 - virtual_ipaddress:定义虚拟IP地址。 - track_script:定义跟踪监控脚本。 - virtual_server:定义虚拟服务器,这里定义了一个IP地址为192.168.1.100,端口为80的虚拟服务器。 - real_server:定义实际服务器,这里定义了两个实际服务器,它们的IP地址分别为192.168.1.10和192.168.1.11。 3. 启动Keepalived 在完成配置后,可以使用以下命令启动Keepalived: ``` sudo systemctl start keepalived ``` 如果要在系统启动时自动启动Keepalived,可以使用以下命令: ``` sudo systemctl enable keepalived ``` 以上是一个简单的Keepalived配置示例,实际使用中可能需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值