一、VS/DR实施
1. 准备工作(集群中所有主机)
IP, hostname, hosts, iptables, SELinux, ssh trust, ntp关闭防火墙
给服务端的所有主机都配置
[root@server ~]# vim /etc/hosts
192.168.46.128 dr
192.168.46.132 rs1
192.168.46.133 rs2
2. RS配置(rs1,rs2都要配置)
配置好网站服务器,测试所有RS //为了测试效果,提供不同的页面
这个是VIP每个主机都要配置
( ifconfig lo:0 192.168.46.100 netmask 255.255.255.255
[root@localhost ~]# route add -host 192.168.46.100 dev lo:0)
[root@rs1 ~]# yum -y install httpd
配置不同的页面:echo 'rs1' > /var/www/html/index.html
[root@rs1 ~]# ip addr add dev lo 192.168.122.100/32
( ifconfig lo:0 192.168.46.100 netmask 255.255.255.255
[root@localhost ~]# route add -host 192.168.46.100 dev lo:0)//在lo接口上绑定VIP
[root@rs1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore //non-arp
[root@rs1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@rs1 ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@rs1 ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
3. Director分发器配置
配置VIP
[root@dr ~]# ip addr add dev eth0 192.168.46.100/32 //配置VIP
[root@dr ~]# yum -y install ipvsadm //确保LoadBalancer仓库可用
定义LVS分发策略
[root@dr ~]# ipvsadm -C
[root@dr ~]# ipvsadm -A -t 192.168.46.100:80 -s rr
[root@dr ~]# ipvsadm -a -t 192.168.46.100:80 -r 192.168.46.132 -g
[root@dr ~]# ipvsadm -a -t 192.168.46.100:80 -r 192.168.46.133 -g
[root@dr ~]# service ipvsadm save
4查看lvs状态
[root@dr ~]# ipvsadm -L -n
[root@dr ~]# ipvsadm -L -n --stats
[root@dr ~]# ipvsadm -L -n --rate
[root@drn~]# ipvsadm -Ln -c
[root@dr ~]# watch -n.5 'ipvsadm -Ln -c'
4. 测试
[root@client ~]# elinks -dump http://192.168.46.100
[root@client ~]# ab -c 1000 -n 1000 http://192.168.122.100/
5. 小结
VS/DR模式的原理是: 当一个client发送一个请求到VIP,Director根据VIP选择对应的real-server的Pool,根据算法,在Pool中选择一台Real-server,然后将client的请求包发给选择的Real-server,最后选择的Real-server把应答包直接传给client