码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived配置基于lvs DR模型的HA

时间:2015-12-07 00:51:21      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:start   模型   


 基本架构图如下:

技术分享 
平台环境:centos6.x
1.    安装keepalived、安装ipvsadm
yum –y install keepalived  ipvsadm

2.    配置服务
2.1 lvs realserver 配置脚本
#!/bin/bash
VIP1=192.168.1.199
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

2.2 keepalived master 配置文件
! Configuration File for keepalived

global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
     192.168.1.199
    }
    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.1.199 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.1.204 80 {
         weight 1
         HTTP_GET {
            url {
              path http://192.168.1.204/index.html
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
           }
       }

     real_server 192.168.1.205 80 {
         weight 1
         HTTP_GET {
            url {
              path http://192.168.1.205/index.html
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3

        }
    }
}


2.3  keepalived backup配置文件
! Configuration File for keepalived

global_defs {
   notification_email {
        root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
     192.168.1.199
    }
    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.1.199 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.1.204 80 {
         weight 1
         HTTP_GET {
            url {
              path http://192.168.1.204/index.html
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
           }
      }

       real_server 192.168.1.205 80 {
         weight 1
         HTTP_GET {
            url {
              path http://192.168.1.205/index.html
              status_code 200
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3

        }
    }
}


3.测试 

   启动服务,在master上查看ipvs规则生效状况

   技术分享

 

   maill命令查看邮件

   技术分享

 

 downmaster查看backup是否能成功接管

 

 查看状态是否转换  

技术分享

 查看ipvs规则是否生效

技术分享

  查看vip是否转移

技术分享








本文出自 “左手右手” 博客,请务必保留此出处http://mofeihu.blog.51cto.com/1825994/1720089

keepalived配置基于lvs DR模型的HA

标签:start   模型   

原文地址:http://mofeihu.blog.51cto.com/1825994/1720089

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!