转载请注明出处:http://blog.csdn.net/l1028386804/article/details/52644698
1. 搭建环境 (系统为 Centon 6.5 )
(1)、LVS-server IP:192.168.0.145
(2)、Real-Server1 IP: 192.168.0.146 安装web服务器 准备测试站点内容
(3)、Real-Server2 IP: 192.168.0.147 安装web服务器 准备测试站点内容
测试机:xp/window7/8都可以,只要能ping通 192.168.0.*
2. LVS服务器部署
(1)、LVS-server配置
a. VIP设置:
[root@liuyazhuang ~]# ifconfig eth0:0 192.168.0.100 netmask 255.255.255.255
[root@liuyazhuang ~]# route add -host 192.168.0.100 dev eth0:0
b.安装Ipvsadm
[root@liuyazhuang ~]# yum -y install ipvsadm*
c.lvs配置:
[root@liuyazhuang ~]# ipvsadm -C
[root@liuyazhuang ~]# ipvsadm -At 192.168.0.100:80 -s rr
[root@liuyazhuang ~]# ipvsadm -at 192.168.0.100:80 -r 192.168.0.146:80 -g
[root@liuyazhuang ~]# ipvsadm -at 192.168.0.100:80 -r 192.168.0.147:80 -g
[root@liuyazhuang ~]# ipvsadm -L -n
(2)、Real-Server1配置
[root@liuyazhuang ~]# ifconfig lo:0 192.168.0.100 netmask 255.255.255.255
[root@liuyazhuang ~]# route add -host 192.168.0.100 dev lo:0
[root@liuyazhuang ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@liuyazhuang ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@liuyazhuang ~]# echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@liuyazhuang ~]# echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
(3)、Real-Server2配置
同Real-Server1相同。
3.测试
现在通过测试机,直接访问 LVS VIP http://192.168.0.100 正常的话即可访问到准备的测试站点.
配置LVS采用的是轮循模式。第一次是访问Real-Server1,刷新后是访问Real-Server2,再刷新后访问Real-Server1