这里使用lvs软件来实现web的集群
实验环境,vmware虚拟机,三台,一台充当director,另外两台充当web服务器
director的ip地址为:192.168.0.64  10.0.1.10(双网卡)
web的ip分别为:10.0.1.11  10.0.1.12
物理机充当客户端,ip为192.168.0.68
这里为了方便使用yum来安装
这里为了方便查看两台realserver的web切换过程我们配置他们的网页不同。

1.首先配置好相应的ip地址和和网关
第一台realserver上配置
route add default gw 10.0.1.10   配置网关
yum install httpd -y
vim /var/www/html/index.html
hi this is test 1
:wq
service httpd start

第二台realserver的配置
route add default gw 10.0.1.10   配置网关
yum install httpd -y
vim /var/www/html/index.html
hi this is test 2
:wq
service httpd start


director上的配置
yum install ipvsadm
cat /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward

此时可以查看一下两台realserver上的网页是否可以正常访问。
elinks --dump http://10.0.1.11
elinks --dump http://10.0.1.12

ipvsadm -A -t 192.168.0.64:80 -s rr
ipvsadm -a -t 192.168.0.64:80 -r 10.0.1.11 -m
ipvsadm -a -t 192.168.0.64:80 -r 10.0.1.12 -m
查看定义
ipvsadm -L -n

此时你就可以通过windows的浏览器输入
http://192.168.0.64来查看你的网页了
此时不断刷新,你就会不端的看到两者进行切换。
hi this is test 1
hi this is test 2

此时你的两台realserver模拟的简单集群就算完成了。

 

 

这里可以修改rr为wlc,
ipvsadm -E -t 192.168.0.64:80 -s wlc

更改权重
ipvsadm -e -t 192.168.0.64:80 -r 10.0.1.11 -m -w 3

watch -n 1 'ipvsadm -L -n'

使用ab来测试你的web的性能
ab -c 10 -n 10000 http://192.168.0.64/index.html
表示用10个并发请求访问10000此

 

 

 


安装lvs-dr集群
此时用两台虚拟机来做realserver,一台director
此时realserver两台的地址为172.16.99.11 172.16.99.12 他们共同的vip都为172.16.99.68
此时director的地址为vip172.16.99.68  dip为172.16.99.10
windows客户端的ip地址为172.16.99.66

此时在两台realserver上的基本配置都相同,如下

此时在两台realserver上都配置如下
        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
表示不响应对vip的arp查询请求。

此时设置一条特殊的路由信息,设置lo为自己与自己在一个网络,与其它任何都不在一个网络。
ifconfig lo:0 172.16.99.68 broadcast 172.16.99.68 netmask 255.255.255.255 up
设定lo:0的ip为172.16.99.68并且设定广播给自己。

添加路由信息。设定同过lo:0的ip都是源ip
route add -host 172.16.99.68 dev lo:0
此时可以通过下面这条命令来查看路由表信息。
route -n

安装apache,并设定一个网页
yum install httpd -y
vim /var/www/html/index.html
hi this is test 1           (网页内容,可以随便写)
:wq
service httpd start

 


此时在director上设置
设置eth0的地址为dip
ifconfig eth0 172.16.99.10
设置eth0:0的ip为vip
ifconfig eth0:0 172.16.99.68 broadcast 172.16.99.68 netmask 255.255.255.255 up
此时添加路由信息。(非必须)
route add -host 172.16.99.68 dev eth0:0

此时配置ipvsadm
yum install ipvsadm
ipvsadm -A -t 172.16.99.68:80 -s wlc
ipvsadm -a -t 172.16.99.68 -r 172.16.99.11 -g -w 2
ipvsadm -a -t 172.16.99.68 -r 172.16.99.12 -g -w 4
查看配置
ipvsadm -L -n

此时你就可以通过windows访问服务器了
http://172.16.99.68/index

不段刷新就可以看到你在网页上定义的内容了 。
此时你可以在director上监控流量,客户机上访问的情况
director上
watch -n 1 'ipvsadm -L -n --rate'

可以再使用一台linux机器使用ab来测量apache的压力
ab -c 20 -n 10000 http://172.16.99.68/index.html