VIP | RIP | ||
web1 | 192.168.88.136 | httpd | |
web2 | 192.168.88.139 | httpd | |
LVS | 192.168.88.110 | 192.168.88.144(DIP) |
省略最后的共享存储,webserver内容不一致(方便查看负载的效果),关闭防火墙,关闭se
1、配置web服务
web1和web2相同
yum install httpd -y
setenforce 0
systemctl stop firewalld
echo "web test pages ip is `hostname -I`" > /var/www/html/index.html
systemctl restart httpd
2、配置lvs
# lvs的管理工具
yum install -y ipvsadm
①配置LVS虚拟ip(vip)
nmcli c mod ens160 +ipv4.address 192.168.88.110/24
nmcli c up ens160
②手动配置添加lvs服务并增加两台RS
ipvsadm -A -t 192.168.88.110:80 -s rr
ipvsadm -a -t 192.168.88.110:80 -r 192.168.88.139:80 -g
ipvsadm -a -t 192.168.88.110:80 -r 192.168.88.136:80 -g
3、在RS绑定VIP
两端一样
centos7没有ifconfig安装yum install net-tools.x86_64
#临时绑定
ifconfig lo:110 192.168.88.110 netmask 255.255.255.255 up
4、在RS端抑制ARP
每台rs都执行
方法1:
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/ens160/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/ens160/arp_announce
方法2:
使用arptables抑制
arptables -A INPUT -d 192.168.88.110 -j DROP
arptables -A OUTPUT -s 192.168.88.110 -j mangle --mangle-ip-s 192.168.88.136
arptables-save > /etc/sysconfig/arptables
5、测试
在lvs上执行
watch ipvsadm -Ls
实时监控
测试主机
lvs查看