环境:centos7
首先得准备五台虚拟机
得理清楚lvs vr模式的原理
先构建个图,根据下图配置五台虚拟机网络
关闭防火墙和selinux(所有)
route中
vi /etc/sysctl.conf
加一句话net.ipv4.ip_forward = 1
sysctl -p
添加虚拟vip
在server1中
[root@server1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@server1 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@server1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@server1 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@server1 ~]# ip a a 192.168.43.130/32 dev lo
在server2中
[root@server2 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@server2 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@server2 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@server2 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@server2 ~]# ip a a 192.168.43.130/32 dev lo
server1
[root@server1 ~]# systemctl start httpd.service
[root@server1 ~]# echo server1 > /var/www/html/index.html
server2
[root@server2 ~]# systemctl start httpd.service
[root@server2 ~]# echo server2 > /var/www/html/index.html
调度规则
lvs中
[root@lvs ~]# ipvsadm -A -t 192.168.43.130:80 -s rr
[root@lvs ~]# ipvsadm -a -t 192.168.43.130:80 -r 192.168.43.131 -g
[root@lvs ~]# ipvsadm -a -t 192.168.43.130:80 -r 192.168.43.132 -g
[root@lvs ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.43.130:80 rr
-> 192.168.43.131:80 Route 1 0 0
-> 192.168.43.132:80 Route 1 0 0
客户端测试
[root@client ~]# curl 192.168.43.130
server1
[root@client ~]# curl 192.168.43.130
server2