要求:1.通过RR算法实现同一用户每次都访问到同一页面
说明:由于实验条件有限,现使用4台linux虚拟机完成实验配置,其中一台为directory,另两台为Real Server,最后一台为共享主机
 

群集lvs—DR的配置及应用

Ip地址分配如下:
Directory:eth0---192.168.145.100 逻辑网卡eth0:0---192.168.145.101
Real Server1 eth0---192.168.145.200 eth1---192.168.2.200 lo:0---192.168.145.101
Real Server2 eth0---192.168.145.201 eth1---192.168.2.201 lo:0---192.168.145.101
Share Server eth0---192.168.2.100
在这里ip地址的添加过程不再详述。
一、directory的配置
安装ipvsadm
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom
[[email protected] ~]# cd /mnt/cdrom/Cluster
[[email protected] Cluster]# rpm -ivh ipvsadm-1.24-10.i386.rpm
配置
[[email protected] ~]# iptables -A PREROUTING -t mangle -p tcp -d 192.168.145.101/24 --dport 80 -j MARK --set-mark 10
[[email protected] ~]# iptables -A PREROUTING -t mangle -p tcp -d 192.168.145.101/24 --dport 443 -j MARK --set-mark 10
[[email protected] Cluster]# ipvsadm -A -f  -s rr  1800
[[email protected] Cluster]# ipvsadm -a -f   10 -r 192.168.145.200  -g
[[email protected] Cluster]# ipvsadm -a -f   10 -r 192.168.145.201  -g
[[email protected] Cluster]# service ipvsadm save //保存规则表格,不然启动ipvsadm时报错
[[email protected] Cluster]# service ipvsadm start //启动ipvsadm
[[email protected] Cluster]# ipvsadm –ln //查看规则
 

群集lvs—DR的配置及应用

二、Real Server1的配置
httpd服务器的安装启动(不再详述)
地址配置如下:
[[email protected] Server]# route add -host 192.168.145.101 dev lo:0
[[email protected] Server]# route –n //查看路由表
 

群集lvs—DR的配置及应用

[[email protected] Server]# sysctl -a |grep arp //查看arp工具
把上面两句话追加的/etc/sysctl.conf文件中
[[email protected] Server]# echo "net.ipv4.conf.eth0.arp_ignore = 1" >>/etc/sysctl.conf
[[email protected] Server]# echo "net.ipv4.conf.all.arp_ignore = 1" >>/etc/sysctl.conf
[[email protected] Server]# echo "net.ipv4.conf.eth1.arp_announce = 2" >>/etc/sysctl.conf
[[email protected] Server]# echo "net.ipv4.conf.all.arp_announce = 2" >>/etc/sysctl.conf
[[email protected] Server]# vim /etc/sysctl.conf //开启数据转发服务
[[email protected] Server]# sysctl –p
 

群集lvs—DR的配置及应用

三、Real Server2的配置
地址配置如下
 

群集lvs—DR的配置及应用

说明:其他配置和Real Server1一样,不再详述
四、Share server的配置
Http服务器安装启动不再详述
地址配置如下
 

群集lvs—DR的配置及应用

通过NFS共享家目录
    [[email protected] yp]# vim /etc/exports //添加下面一句,实现家目录共享
/var/www/html  *(rw,sync)
[[email protected] ~]# service nfs start
五、Real Server1上实现挂载并查看
 

群集lvs—DR的配置及应用

说明:在Real Server2上实施同样操作,不再详述
六、在客户端浏览
 

群集lvs—DR的配置及应用

查看连接数
 

群集lvs—DR的配置及应用

 
七、实现自动挂载 (本实验选作)
Real Server1上配置
[[email protected] ~]# vim /etc/auto.master //插入下面一行
/var/www/html /etc/auto.lvs --timeout=60
[[email protected] ~]# cp -p /etc/auto.misc /etc/auto.lvs //创建auto.lvs文件,输入以下内容
*            -rw,soft,intr           192.168.2.100:/var/www/html
[[email protected] www]# service autofs restart
Real Server2上同样配置,不再详述
刷新客户端
 

群集lvs—DR的配置及应用

查看连接效果
 

群集lvs—DR的配置及应用

查看自动挂载
 

群集lvs—DR的配置及应用