keepalived 多实例

简介:

8.13和8.14的keepalived配置文件

8.13上的如下:

[robin@lb8-ha13 keepalived]$ pwd

/etc/keepalived

[robin@lb8-ha13 keepalived]$ ls

keepalived.conf  scripts

[robin@lb8-ha13 keepalived]$ cd scripts/

[robin@lb8-ha13 scripts]$ ls

chk_haproxy.sh  notify.sh

[robin@lb8-ha13 scripts]$ cat chk_haproxy.sh 

#!/bin/bash

    pid=`ps -C haproxy --no-header |wc -l`  

    if [ $pid -eq 0 ];then  

        service haproxy start  

        sleep 2 

        if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then  

            service keepalived stop  

        fi  

    fi  

[robin@lb8-ha13 scripts]$ cat notify.sh 

#!/bin/bash

Date=`date +%Y%m%d-%l:%M` 

echo $Date>>/var/log/sms.log

echo "will send sms " >> /var/log/sms.log


Content="haproxy $(hostname) into $1"

Mobile="156********"

wget --post-data="token=***&mobile=$Mobile&content=$Content" http://sms.service.domain.com/task/create -O /dev/null

echo "send sms finish $Content $Mobile" >> /var/log/sms.log

#echo "Mobile=$Mobile   Content=$Content"

[robin@lb8-ha13 scripts]$ 

[robin@lb8-ha13 keepalived]$ cat keepalived.conf 

global_defs {

        notification_email {

                robin@qq.com

        }

        notification_email_from haproxy-support@qq.com


        smtp_server 127.0.0.1

        smtp_connect_timeout 30


        router_id HAPROXY 

}

vrrp_script chk_haproxy {

    script "/etc/keepalived/scripts/chk_haproxy.sh"

    interval 4

  #  weight 2

}


vrrp_sync_group VG1 {

        group {

                VI1_GATEWAY

        }

}

vrrp_sync_group VG2 {

        group {

                VI2_GATEWAY

        }

}



vrrp_instance VI1_GATEWAY {

        state MASTER

        interface eth0

        lvs_sync_daemon_interface eth0


        virtual_router_id 56

        priority 51 

        smtp_alert

        advert_int 1

        sorry_server 127.0.0.1 80


        authentication {

                auth_type PASS

                auth_pass hapass8 

        }

       track_script {

                chk_haproxy

        }


        virtual_ipaddress {

                192.168.8.50

                192.168.8.51

                192.168.8.52

                192.168.8.53

                192.168.8.54

                192.168.8.55

                192.168.8.56

                192.168.8.57

                192.168.8.58

                192.168.8.59

        }

    notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"

    notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"

}

vrrp_instance VI2_GATEWAY {

        state MASTER

        interface eth0

        lvs_sync_daemon_interface eth0


        virtual_router_id 57

        priority 50

        smtp_alert

        advert_int 1

        sorry_server 127.0.0.1 80


        authentication {

                auth_type PASS

                auth_pass hapass8

        }

       track_script {

                chk_haproxy

        }


        virtual_ipaddress {

                192.168.8.60

                192.168.8.61

                192.168.8.62

                192.168.8.63

                192.168.8.64

                192.168.8.65

        }

    notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"

    notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"

}


#include conf.d/*.conf

[robin@lb8-ha13 keepalived]$


8.14上如下:

[root@lb8-ha14 keepalived]# pwd

/etc/keepalived

[root@lb8-ha14 keepalived]# ls

keepalived.conf  scripts

[root@lb8-ha14 keepalived]# cd scripts/

[root@lb8-ha14 scripts]# ls

chk_haproxy.sh  notify.sh

[root@lb8-ha14 scripts]# cat chk_haproxy.sh 

#!/bin/bash

    pid=`ps -C haproxy --no-header |wc -l`  

    if [ $pid -eq 0 ];then  

        service haproxy start  

        sleep 2 

        if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then  

            service keepalived stop  

        fi  

    fi  

[root@lb8-ha14 scripts]# cat notify.sh 

#!/bin/bash

Date=`date +%Y%m%d-%l:%M` 

echo $Date>>/var/log/sms.log

echo "will send sms " >> /var/log/sms.log


Content="haproxy $(hostname) into $1"

Mobile="156********" #过个手机号,用逗号分隔

wget --post-data="token=51********&mobile=$Mobile&content=$Content" http://sms.service.domain.com/task/create -O /dev/null

echo "send sms finish $Content $Mobile" >> /var/log/sms.log

#echo "Mobile=$Mobile   Content=$Content"

[root@lb8-ha14 scripts]# 

[root@lb8-ha14 keepalived]# cat keepalived.conf 

global_defs {

        notification_email {

                robin@qq.com

        }

        notification_email_from haproxy-support@qq.cn


        smtp_server 127.0.0.1

        smtp_connect_timeout 30


        router_id HAPROXY 

}

vrrp_script chk_haproxy {

    script "/etc/keepalived/scripts/chk_haproxy.sh"

    interval 4

  #  weight 2

}


vrrp_sync_group VG1 {

        group {

                VI1_GATEWAY

        }

}

vrrp_sync_group VG2 {

        group {

                VI2_GATEWAY

        }

}



vrrp_instance VI1_GATEWAY {

        state MASTER

        interface eth0

        lvs_sync_daemon_interface eth0


        virtual_router_id 56

        priority 50 

        smtp_alert

        advert_int 1

        sorry_server 127.0.0.1 80


        authentication {

                auth_type PASS

                auth_pass hapass8 

        }

       track_script {

                chk_haproxy

        }


        virtual_ipaddress {

                192.168.8.50

                192.168.8.51

                192.168.8.52

                192.168.8.53

                192.168.8.54

                192.168.8.55

                192.168.8.56

                192.168.8.57

                192.168.8.58

                192.168.8.59

        }

    notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"

    notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"

}

vrrp_instance VI2_GATEWAY {

        state MASTER

        interface eth0

        lvs_sync_daemon_interface eth0


        virtual_router_id 57

        priority 51

        smtp_alert

        advert_int 1

        sorry_server 127.0.0.1 80


        authentication {

                auth_type PASS

                auth_pass hapass8

        }

       track_script {

                chk_haproxy

        }


        virtual_ipaddress {

                192.168.8.60

                192.168.8.61

                192.168.8.62

                192.168.8.63

                192.168.8.64

                192.168.8.65

        }

    notify_master "/bin/bash /etc/keepalived/scripts/notify.sh master"

    notify_backup "/bin/bash /etc/keepalived/scripts/notify.sh backup"

}


#include conf.d/*.conf

[root@lb8-ha14 keepalived]#






      本文转自Tenderrain 51CTO博客,原文链接:http://blog.51cto.com/tenderrain/1630609,如需转载请自行联系原作者



相关文章
|
应用服务中间件 Linux 网络架构
Keepalived - Keepalived 实现 tomcat双机热备(抢占式)
Keepalived - Keepalived 实现 tomcat双机热备(抢占式)
436 0
|
监控 负载均衡 网络协议
keepalived实现服务高可用
第1章 keepalived服务说明 1.1 keepalived是什么?   Keepalived软件起初是专为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实现高可用的VRRP功能。
2718 0
|
移动开发 网络协议 Shell
LVS+KEEPALIVED 安装与配置实例
--------------------------------------master--------------------------------------- echo "1" > /proc/sys/net/ipv4/ip_forward wget http://www.
1316 0
|
网络架构
Keepalived 介绍、安装、配置(高可用)
1、keepalived的工作原理是VRRP(Virtual Router Redundancy Protocol)虚拟路由冗余协议。 2、VRRP路由器是指运行VRRP的路由器,是物理实体,虚拟路由器是指VRRP协议创建的,是逻辑概念。
1219 0
|
监控 负载均衡 网络协议
|
MySQL 关系型数据库 Shell