Ubuntu OS xen虚拟机上测试lvs和keepalived负载均衡

Ubuntu OS xen虚拟机上测试lvs和keepalived负载均衡


网络拓扑:

虚拟机管理器和xen虚拟机实例:

step1: 安装LVSkeepalived:director服务器上,分别安装LVSkeepalived软件,使用命令:

$sudo apt-get install ipvsadm

keepalived,使用命令:

$sudo apt-get installkeepalived

step2:配置keepalived:安装装完之后,在/etc/keepalived目录下建立keepalived.conf文件,写入配置文件如下:

# Global Configuration

global_defs {

lvs_id  director1

}

# VRRP Configuration

vrrp_instance LVS {

state MASTER

interface eth0

virtual_router_id 51

priority 150

advert_int 1

authentication {

auth_type PASS

auth_pass 123456

}

virtual_ipaddress {

192.168.122.38

}

# Virtual ServerConfiguration - for WWW service

virtual_server 192.168.122.3880 {

delay_loop 1

lb_algo rr

lb_kind DR

persistence_timeout 60

protocol TCP

# Real Server 1 configuration

real_server 192.168.122.36 80{

weight 3

TCP_CHECK {

connection_timeout 10

nb_get_retry 3

delay_before_retry 3

}

real_server 192.168.122.37 80{

weight 1

TCP_CHECK {

connection_timeout 10

nb_get_retry 3

delay_before_retry 3

}

}

}

step3:配置LVS

LVS在第一步的时候已经安装过了,现在只需要配置即可。

director上使用如下命令:

$sudo ifconfig eth0:0192.168.122.38 broadcast 192.168.122.38 netmask 255.255.255.255 up

$sudo route add -host192.168.122.38 dev eth0:0

$sudo echo "1" >/proc/sys/net/ipv4/ip_forward

$sudo ipvsadm -C

$sudo ipvsadm -A -t192.168.122.38:80 -s rr

$sudo ipvsadm -a -t192.168.122.38:80 -r 192.168.122.36:80 -g

$sudo ipvsadm -a -t192.168.122.38:80 -r 192.168.122.37:80 -g

$sudo ipvsadm

$sudo sysctl -p

step4,配置RealServer

在两台www服务器上,分别配置如下命令:

$sudo ifconfig lo:0192.168.122.38 broadcast 192.168.122.38 netmask 255.255.255.255 up

$sudo route add -host192.168.122.38 dev lo:0

$sudo echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore

$sudo echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce

$sudo echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

$sudo echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

$sudo sysctl -p

step5,验证

client机器上,访问http://192.168.122.38;可以看出来至于192.168.122.37虚拟机:


192.168.122.37虚拟机apache关闭:

root@sst-HVM-domU:~#ifconfig eth0
eth0      Link encap:
以太网 硬件地址 00:16:3e:00:8d:2b 
          inet
地址:192.168.122.37 广播:192.168.122.255 掩码:255.255.255.0
    

root@sst-HVM-domU:~#service apache2 stop
 * Stopping web serverapache2    apache2: Could not reliably determine the server's fully qualifieddomain name, using 127.0.1.1 for ServerName
 ...waiting                                                            [ OK ]


再来访问http://192.168.122.38




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值