xml地图|网站地图|网站标签 [设为首页] [加入收藏]

热门直播

当前位置:美高梅游戏网站 > 热门直播 > Lvs+keepalived实现负载均衡、故障剔除(DR模式)

Lvs+keepalived实现负载均衡、故障剔除(DR模式)

来源:http://www.gd-chuangmei.com 作者:美高梅游戏网站 时间:2019-09-06 04:17

使用Lvs DR模式实现负载均衡

  本文出自 “山捻子” 博客

 

图片 1

  LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,适应LVS可以构建高性能的负载均衡系统,LVS有三种模式即:LVS/NAT(网络地址转换)、LVS/TUN(IP隧道)、LVS/DR(直接路由),通常用的是DR模式,下面介绍一下DR模式的配置方式。

Node1: 192.168.1.253
Node2: 192.168.1.254
VIP: 192.168.1.250
 
环境 centos5.2(我这里是用两台机实现的)
1、安装ipvsadm
yum -y install ipvsadm
 
2、安装keepalived
[[email protected] ~]# wget
[[email protected] ~]# tar zxvf keepalived-1.1.15.tar.gz
[[email protected] ~]# cd keepalived-1.1.15
[[email protected] keepalived-1.1.15]# ./configure --prefix=/ --mandir=/usr/local/share/man/ --with-kernel-dir=/usr/src/kernels/2.6.18-92.el5-i686/
configure后会输入这结果为正确

    假设测试环境:使用虚拟IP192.168.1.243,调度机的IP地址是192.168.1.245,两台真实服务器的IP分别是192.168.1.246、192.168.1.247。

Keepalived configuration

Keepalived version       : 1.1.15
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVS Framework       : Yes    #支持lvs
IPVS sync daemon support : Yes 
Use VRRP Framework       : Yes
Use LinkWatch            : No
Use Debug flags          : No
 
[[email protected] keepalived-1.1.15]# make && make install
到此,lvs+keepalived安装完成。但是还不能使用lvs功能,接下来以dr模式配置lvs+keepalived
 
3、[[email protected] ~]# cd /etc/keepalived/
[[email protected] keepalived]# vim keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
    [email protected]
   }
   notification_email_from  [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
 
vrrp_instance VI_1 {
    state MASTER      ##主lvs设置成master
    interface eth0
    virtual_router_id 51
    priority 102     ##从lvs设置成 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       192.168.1.250 ## 如多个vip,继续换行填写。
    }
}
virtual_server 192.168.1.250 80 {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    persistence_timeout 50
    protocol TCP
 
    real_server 192.168.1.253 80 {
        weight 3
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }
    real_server 192.168.1.254 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 30
        }
    }
 
好了,keepalived配置完成了。
启动keepalived 
[[email protected] ~]# /etc/init.d/keepalived start
如果要随系统启动,执行chkconfig --add keepalived
                                       chkconfig keepalived  on
 
4、接着配置真实服务器,这里通过脚本来实现吧(这个脚本只在WEB机上执行,我现在是用两台机。服务器既充当lvs、也充当web机)
 [[email protected] keepalived]# vim realserver
#!/bin/bash
#description : start realserver
VIP=192.168.1.250
/etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP 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
[[email protected] keepalived]# chmod +x realserver
[[email protected] keepalived]# ./realserver start
 
5、启动keepalived (附启动日志)
[[email protected] ~]# /etc/init.d/keepalived start  (主LVS)
Oct 15 13:59:36 vmtest Keepalived: Starting Keepalived v1.1.15 (10/15,2009)
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Using MII-BMSR NIC polling thread...
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Netlink reflector reports IP 192.168.1.253 added
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Netlink reflector reports IP 10.0.0.253 added
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Registering Kernel netlink reflector
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Registering Kernel netlink command channel
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Opening file /etc/keepalived/keepalived.conf.
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Configuration is using : 11891 Bytes
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Activating healtchecker for service [192.168.1.253:80]
Oct 15 13:59:36 vmtest Keepalived_healthcheckers: Activating healtchecker for service [192.168.1.254:80]
Oct 15 13:59:36 vmtest Keepalived: Starting Healthcheck child process, pid=28419
Oct 15 13:59:36 vmtest Keepalived_vrrp: Using MII-BMSR NIC polling thread...
Oct 15 13:59:36 vmtest Keepalived_vrrp: Netlink reflector reports IP 192.168.1.253 added
Oct 15 13:59:36 vmtest Keepalived: Starting VRRP child process, pid=28420
Oct 15 13:59:36 vmtest Keepalived_vrrp: Netlink reflector reports IP 10.0.0.253 added
Oct 15 13:59:36 vmtest Keepalived_vrrp: Registering Kernel netlink reflector
Oct 15 13:59:36 vmtest Keepalived_vrrp: Registering Kernel netlink command channel
Oct 15 13:59:36 vmtest Keepalived_vrrp: Registering gratutious ARP shared channel
Oct 15 13:59:36 vmtest Keepalived_vrrp: Opening file /etc/keepalived/keepalived.conf.
Oct 15 13:59:36 vmtest Keepalived_vrrp: Configuration is using : 36278 Bytes
Oct 15 13:59:36 vmtest Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(8,9)]
Oct 15 13:59:37 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Oct 15 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Oct 15 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Oct 15 13:59:38 vmtest Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.250
Oct 15 13:59:38 vmtest Keepalived_healthcheckers: Netl

本文出自 “山捻子” 博客 Node1: 192.168.1.253 Node2: 192.168.1.254 VIP: 192.168.1.250 环境 centos5.2(我这里是用两台机...

    首先在调度机上安装ipvsadm

yum -y install ipvsadm

    调度机设置虚拟IP

ifconfig eth0:0 192.168.1.243 netmask 255.255.255.255

route add -host 192.168.1.243 dev eth0:0

    两台真实服务器设置虚拟IP

ifconfig lo:0 192.168.1.243 netmask 255.255.255.255

route add -host 192.168.1.243 dev lo:0

    真实服务器配置arp忽略脚本(有几台配置几台)

vi /data0/arp_ignore.sh

    加入

#!/bin/sh

echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

本文由美高梅游戏网站发布于热门直播,转载请注明出处:Lvs+keepalived实现负载均衡、故障剔除(DR模式)

关键词:

上一篇:linux grep less字符高亮配置

下一篇:没有了