LVS+Keepalived-DR模式

LVS+Keepalived-DR模式

作者:admin |  时间:2014-03-10 |  浏览:713 |  0 条评论

Image

安装LVS:
yum install ipvsadm keepalived

主192.168.48.152  /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   router_id LVS_CNC_1
}
vrrp_sync_group VGM {
   group {
     VI_CACHE
   }
}
vrrp_instance VI_CACHE {
    state MASTER
    interface eth0
    virtual_router_id 51
    lvs_sync_daemon_interface eth0
    priority 100
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.48.200
        192.168.48.201
    }
}
virtual_server_group www {
   192.168.48.200 80
   192.168.48.201 80
}
virtual_server group www {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    persistence_timeout 50 #动态网站session保持,确保映射到同一台服务器
    protocol TCP
    real_server 192.168.48.154 80 {
        weight 3
        HTTP_GET {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
            url {
              path /status.html
              status_code 200
            }
        }
    }
    real_server 192.168.48.155 80 {
        weight 3
        HTTP_GET {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
            url {
              path /status.html
              status_code 200
            }
        }
    }
}

从192.168.48.153 /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   router_id LVS_CNC_2
}
vrrp_sync_group VGM {
   group {
     VI_CACHE
   }
}
vrrp_instance VI_CACHE {
    state BACKUP
    interface eth0
    virtual_router_id 51
    lvs_sync_daemon_interface eth0
    priority 80
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.48.200
        192.168.48.201
    }
}
virtual_server_group www {
    192.168.48.200 80
    192.168.48.201 80
}
virtual_server group www {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    persistence_timeout 50  #动态网站session保持,确保映射到同一台服务器
    protocol TCP
    real_server 192.168.48.154 80 {
        weight 3
        HTTP_GET {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
            url {
                path /status.html
                status_code 200
            }
        }
    }
    real_server 192.168.48.155 80 {
        weight 3
        HTTP_GET {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
            url {
               path /status.html
               status_code 200
            }
        }
    }
}
真实服务器192.168.48.154  lvs_real.sh
#!/bin/bash
#description:start realserver
VIP=192.168.48.200
VIP1=192.168.48.201
/bin/bash /etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REAL Server"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/ifconfig lo:1 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore  # 抑制ARP广播
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
/sbin/ifconfig lo:1 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
真实服务器192.168.48.155  lvs_real.sh
#!/bin/bash
#description:start realserver
VIP=192.168.48.200
VIP1=192.168.48.201
/bin/bash /etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REAL Server"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/ifconfig lo:1 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up
echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore  # 抑制ARP广播
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
/sbin/ifconfig lo:1 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
通过ip addr命令可以看到虚拟ip 192.168.48.200, 192.168.48.201
对于lvs在使用过程中产生的日志查看/var/log/messages

本文标签:

相关推荐

TCP与UDP的输出,MSS与MTU之间关系
Posted on 04月02日
SeaJS使用举例
Posted on 05月20日
为什么我要用Node.js?
Posted on 07月19日
Hadoop集群配置
Posted on 03月16日

发表评论

电子邮件地址不会被公开。

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>