13.从 Piranha 上配置
----由于本实验中 VIRTUAL SERVER 没有做双机热备,也就不用设置从 Piranha
14.REAL SERVER 配置
在选择连接类型有NAT、DR(路由直连)、Tunneling三种,选择不同类型真实服务器也要对应不同的设置
上面我们选择了DR类型,只要把每台真实服务器按着之前做路由直连时
(ipvsadm),设置多台真实服务器就可以了
10.1禁止real server 相应ARP请求,只允许LVS 相应
[root@zzh /]# vim /etc/sysctl.conf
编辑内核运行参数,添加下面字段
net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2 net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2
[root@zzh /]# sysctl -p 使上面的修改立即生效
10.2配置VIP地址
[root@localhost ~]# ifconfig lo:0 192.168.1.135 broadcast 192.168.1.135 netmask 255.255.255.255 up
[root@localhost ~]# route add -host 192.168.1.135 dev lo:0
需要在所有的real server 执行相同的命令,可以写成脚本在所有的real server上执行,并 放到 /etc/rc.d/rc.local 中使该脚本开机执行
15.测试
REAL SERVER1 上
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# echo "real server 1" >> index.html
[root@localhost html]# service httpd start
Starting httpd: httpd: Could not reliably determine t
he server's fully qualified domain name, using localhost.localdomain for ServerName
[ OK ]
[root@localhost html]# chkconfig httpd on
REAL SERVER2 上
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# echo "real server 2" >> index.html
[root@localhost html]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[ OK ]
[root@localhost html]# chkconfig httpd on
----实验成功
多种配置LVS的方式,real server的配置都是一样的。附上配置脚本,设置固定ip后就可以执行该脚本,并立即生效。而且重启后依然有效。
real server配置脚本
#!/bin/bash
#本次生效
VIP=192.168.1.135
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
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
sysctl -p &> /dev/null
/usr/sbin/setenforce 0
/sbin/iptables -F
/sbin/iptables -Z
service iptables save
#每次开机自动执行lvs.sh
/bin/cat <<EOF >> /etc/rc.d/rc.local
/sbin/lvs-rs.sh
EOF
/bin/cat <<EOF>> /sbin/lvs.sh
#!/bin/bash
VIP=192.168.1.135
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
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
sysctl -p &> /dev/null
/usr/sbin/setenforce 0
EOF