1. LVS-NAT模式案例
环境 :
共四台主机
1台: internet client:192.168.10.6/24 GW:无 仅主机
1台:lvs
eth1 仅主机 192.168.10.100/16
eth0 NAT 10.0.0.8/24
2台RS:
RS1: 10.0.0.7/24 GW:10.0.0.8 NAT
RS2: 10.0.0.17/24 GW:10.0.0.8 NAT
配置过程:
internet-client:
[root@internet-server ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.10.6
PREFIX=24
ONBOOT=yes
LVS主机:
[root@lvs-server ~]#yum -y install ipvsadm
[root@lvs-server network-scripts]#cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.8
PREFIX=24
[root@lvs-server network-scripts]#cat ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.0.100
PREFIX=24
RS1-server:
[root@RS1-server ~]#yum -y install httpd ;systemctl enable --now httpd
[root@RS1-server ~]#echo "RS1 10.0.0.7" > /var/www/html/index.html
[root@RS1-server network-scripts]#cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.8
RS2-server:
[root@RS2-server ~]#yum -y install httpd ;systemctl enable --now httpd
[root@RS2-server ~]#echo "RS2 10.0.0.17" > /var/www/html/index.html
[root@RS2-server network-scripts]#cat ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.17
PREFIX=24
GATEWAY=10.0.0.8
配置LVS:
[root@lvs-server ~]#echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
[root@lvs-server ~]#sysctl -p
[root@lvs-server ~]#ipvsadm -A -t 192.168.0.100:80 -s wrr
[root@lvs-server ~]#ipvsadm -a -t 192.168.0.100:80 -r 10.0.0.7:80 -m
[root@lvs-server ~]#ipvsadm -a -t 192.168.0.100:80 -r 10.0.0.17:80 -m
[root@lvs-server ~]#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.0.100:80 wrr
-> 10.0.0.7:80 Masq 1 0 0
-> 10.0.0.17:80 Masq 1 0 0
保存规则:
[root@lvs-server ~]#ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@lvs-server ~]#systemctl enable --now ipvsadm.service
清除规则:
[root@lvs-server ~]#ipvsadm -C
重新加载规则
[root@lvs-server ~]#ipvsadm -R < /etc/sysconfig/ipvsadm
客户端测试:
[root@internet-client ~]#while :;do curl 192.168.0.100;sleep 0.5;done
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
......
2. LVS-DR模式单网段案例
环境:
所有主机禁用iptables和SELinux
五台主机:
一台:客户端 eth0:仅主机 192.168.10.6/24 GW:192.168.10.200
一台:ROUTER
eth0 :NAT 10.0.0.200/24
eth1: 仅主机 192.168.10.200/24
启用 IP_FORWARD
一台:LVS
lo:1 10.0.0.100/32
eth0:NAT: DIP: 10.0.0.8/24 GW:10.0.0.200
两台RS:
RS1:
lo:1 10.0.0.100/32
eth0:NAT: 10.0.0.7/24 GW:10.0.0.200
RS2:
lo:1 10.0.0.100/32
eth0:NAT: 10.0.0.17/24 GW:10.0.0.200
2.1 网络配置
-
intenet-client 配置
[root@intetnet-client ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE="Ethernet" BOOTPROTO="static" NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=192.168.10.6 PREFIX=24 GATEWAY=192.168.10.200 [root@intetnet-client ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.10.200 0.0.0.0 UG 100 0 0 eth0 192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
-
router 配置
[root@router ~]#echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf [root@router ~]#sysctl -p [root@router network-scripts]#cat ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.200 PREFIX=24 [root@router network-scripts]#cat ifcfg-eth1 TYPE=Ethernet BOOTPROTO=static NAME=eth1 DEVICE=eth1 ONBOOT=yes IPADDR=192.168.10.200 PREFIX=24
-
RS1配置
[root@RS1-server ~]#yum -y install httpd ;systemctl enable --now httpd [root@RS1-server ~]#echo "RS1 10.0.0.7" > /var/www/html/index.html [root@RS1-server network-scripts]#cat ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.7 PREFIX=24 GATEWAY=10.0.0.200 [root@RS2-server ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 [root@RS1-server ~]#ping 192.168.10.6 -c1 PING 192.168.10.7 (192.168.10.6) 56(84) bytes of data. 64 bytes from 192.168.10.6: icmp_seq=1 ttl=63 time=0.654 ms --- 192.168.10.6 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.654/0.654/0.654/0.000 ms
-
RS2配置
[root@RS1-server ~]#yum -y install httpd ;systemctl enable --now httpd [root@RS1-server ~]#echo "RS2 10.0.0.17" > /var/www/html/index.html [root@RS2-server network-scripts]#cat ifcfg-eth0 TYPE="Ethernet" BOOTPROTO="static" NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.17 PREFIX=24 GATEWAY=10.0.0.200 [root@RS2-server ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 [root@RS2-server ~]#ping 192.168.10.6 -c1 PING 192.168.10.7 (192.168.10.6) 56(84) bytes of data. 64 bytes from 192.168.10.6: icmp_seq=1 ttl=63 time=1.00 ms --- 192.168.10.6 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 1.007/1.007/1.007/0.000 ms
-
LVS 配置
[root@lvs-server network-scripts]#cat ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.8 PREFIX=24 GATEWAY=10.0.0.200 [root@lvs-server ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
2.2 后端RS的IPVS配置
-
RS1 的IPVS配置
[root@RS1-server ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@RS1-server ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [root@RS1-server ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@RS1-server ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce [root@RS1-server ~]#ip a a 10.0.0.100/32 dev lo label lo:1 [root@RS1-server ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 10.0.0.100/32 scope global lo:1 valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:1e:f4:76 brd ff:ff:ff:ff:ff:ff inet 10.0.0.7/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe1e:f476/64 scope link valid_lft forever preferred_lft forever
-
RS2 的IPVS配置
[root@RS2-server ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@RS2-server ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [root@RS2-server ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@RS2-server ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce [root@RS2-server ~]#ifconfig lo:1 10.0.0.100/32 [root@RS2-server ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 10.0.0.100/0 scope global lo:1 valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:7a:c2:1f brd ff:ff:ff:ff:ff:ff inet 10.0.0.17/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe7a:c21f/64 scope link valid_lft forever preferred_lft forever
2.3 LVS主机的配置
#在LVS上添加VIP
[root@lvs-server ~]#ifconfig lo:1 10.0.0.100/32
或者:
[root@lvs-server ~]#ip a a 10.0.0.100/32 dev lo label lo:1
[root@lvs-server ~]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 10.0.0.100/0 scope global lo:1
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:76:a2:60 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.8/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe76:a260/64 scope link
valid_lft forever preferred_lft forever
[root@lvs ~]#dnf -y install ipvsadm
[root@lvs-server ~]#ipvsadm -A -t 10.0.0.100:80 -s wrr
[root@lvs-server ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.7:80 -g
[root@lvs-server ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.17:80 -g
[root@lvs-server ~]#ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.0.0.100:80 wrr
-> 10.0.0.7:80 Route 1 0 0
-> 10.0.0.17:80 Route 1 0 0
2.4 测试访问
[root@intetnet-client ~]#while :;do curl 10.0.0.100;sleep 0.5;done
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
[root@RS2-server ~]#tail -f /var/log/httpd/access_log -n0
192.168.10.7 - - [05/Nov/2020:19:34:38 +0800] "GET / HTTP/1.1" 200 15 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:39 +0800] "GET / HTTP/1.1" 200 15 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:40 +0800] "GET / HTTP/1.1" 200 15 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:41 +0800] "GET / HTTP/1.1" 200 15 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:42 +0800] "GET / HTTP/1.1" 200 15 "-" "curl/7.29.0"
[root@RS1-server ~]#tail -f /var/log/httpd/access_log -n0
192.168.10.7 - - [05/Nov/2020:19:34:38 +0800] "GET / HTTP/1.1" 200 14 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:39 +0800] "GET / HTTP/1.1" 200 14 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:40 +0800] "GET / HTTP/1.1" 200 14 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:41 +0800] "GET / HTTP/1.1" 200 14 "-" "curl/7.29.0"
192.168.10.7 - - [05/Nov/2020:19:34:42 +0800] "GET / HTTP/1.1" 200 14 "-" "curl/7.29.0"
3. LVS-DR模式多网段案例
环境:
所有主机禁用iptables和SELinux
五台主机:
一台:客户端 eth0:仅主机 192.168.10.6/24 GW:192.168.10.200
一台:ROUTER
eth0: NAT 10.0.0.200/24
eth0: NAT 172.16.0.1/24
eth1: 仅主机 192.168.10.200/24
启用 IP_FORWARD
一台:LVS
lo:1 172.16.0.100/32
eth0:NAT: DIP: 10.0.0.8/24 GW:10.0.0.200
两台RS:
RS1:
lo:1 172.16.0.100/32
eth0:NAT: 10.0.0.7/24 GW:10.0.0.200
RS2:
lo:1 172.16.0.100/32
eth0:NAT: 10.0.0.17/24 GW:10.0.0.200
3.1 网络配置
-
intenet-client 配置
[root@intetnet-client ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE="Ethernet" BOOTPROTO="static" NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=192.168.10.6 PREFIX=24 GATEWAY=192.168.10.200 [root@intetnet-client ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.10.200 0.0.0.0 UG 100 0 0 eth0 192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
-
router 配置
[root@router ~]#echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf [root@router ~]#sysctl -p [root@router network-scripts]#cat ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.200 PREFIX=24 [root@router network-scripts]#cat ifcfg-eth1 TYPE=Ethernet BOOTPROTO=static NAME=eth1 DEVICE=eth1 ONBOOT=yes IPADDR=192.168.10.200 PREFIX=24 [root@router ~]#ip addr add 172.16.0.200/24 dev eth0 label eth0:1 [root@router ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:2a:a2:cb brd ff:ff:ff:ff:ff:ff inet 10.0.0.200/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet 172.16.0.200/24 scope global eth0:1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe2a:a2cb/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:2a:a2:d5 brd ff:ff:ff:ff:ff:ff inet 192.168.10.200/24 brd 192.168.10.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe2a:a2d5/64 scope link valid_lft forever preferred_lft forever
-
RS1配置
[root@RS1-server ~]#yum -y install httpd ;systemctl enable --now httpd [root@RS1-server ~]#echo "RS1 10.0.0.7" > /var/www/html/index.html [root@RS1-server network-scripts]#cat ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.7 PREFIX=24 GATEWAY=10.0.0.200 [root@RS2-server ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 [root@RS1-server ~]#ping 192.168.10.6 -c1 PING 192.168.10.7 (192.168.10.6) 56(84) bytes of data. 64 bytes from 192.168.10.6: icmp_seq=1 ttl=63 time=0.654 ms --- 192.168.10.6 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.654/0.654/0.654/0.000 ms [root@router ~]#hostname -I 10.0.0.200 172.16.0.200 192.168.10.200
-
RS2配置
[root@RS1-server ~]#yum -y install httpd ;systemctl enable --now httpd [root@RS1-server ~]#echo "RS2 10.0.0.17" > /var/www/html/index.html [root@RS2-server network-scripts]#cat ifcfg-eth0 TYPE="Ethernet" BOOTPROTO="static" NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.17 PREFIX=24 GATEWAY=10.0.0.200 [root@RS2-server ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 [root@RS2-server ~]#ping 192.168.10.6 -c1 PING 192.168.10.7 (192.168.10.6) 56(84) bytes of data. 64 bytes from 192.168.10.6: icmp_seq=1 ttl=63 time=1.00 ms --- 192.168.10.6 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 1.007/1.007/1.007/0.000 ms
-
LVS 配置
[root@lvs-server network-scripts]#cat ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=10.0.0.8 PREFIX=24 GATEWAY=10.0.0.200 [root@lvs-server ~]#route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.200 0.0.0.0 UG 100 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
3.2 用脚本实现相关配置
-
在LVS主机运行的脚本
[root@lvs-server ~]#vim lvs_dr_vs.sh #!/bin/bash # #******************************************************************** #Author: Tangtao #QQ: 1812237069 #Date: 2020-11-05 #FileName: lvs_dr_vs.sh #Website(URL): http://www.magedu.com #Description: The test script #Copyright (C): 2020 All rights reserved #******************************************************************** vip='172.16.0.100' iface='lo:1' mask='255.255.255.255' port='80' rs1='10.0.0.7' rs2='10.0.0.17' scheduler='wrr' type='-g' rpm -q ipvsadm &> /dev/null || yum -y install ipvsadm &> /dev/null case $1 in start) ifconfig $iface $vip netmask $mask iptables -F ipvsadm -C ipvsadm -A -t ${vip}:${port} -s $scheduler ipvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1 ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1 echo "The LVS Server is Ready!" ;; stop) ipvsadm -C ifconfig $iface down echo "The LVS Server is Canceled!" ;; *) echo "Usage: $(basename $0) start | stop" ;; esac [root@lvs-server ~]#bash lvs_dr_vs.sh Usage: lvs_dr_vs.sh start|stop [root@lvs-server ~]#bash lvs_dr_vs.sh start The LVS Server is Ready! [root@lvs-server ~]#ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.16.0.100:80 wrr -> 10.0.0.7:80 Route 1 0 0 -> 10.0.0.17:80 Route 1 0 0
-
在后端服务器RS运行的脚本实现IPVS配置
[root@RS1-server ~]#vim lvs_dr_rs.sh #!/bin/bash # #QQ: 1812237069 #Date: 2020-11-05 #FileName: lvs_dr_rs.sh #Website(URL): http://www.magedu.com #Description: The test script #Copyright (C): 2020 All rights reserved #******************************************************************** vip='172.16.0.100 ' mask='255.255.255.255' dev='lo' label='lo:1' case $1 in start) echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce ip a a $vip dev $dev label $label echo "The RS Server is Ready!" ;; stop) ip a d $vip dev $dev label $label echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce echo "The RS Server is Canceled!" ;; *) echo "Usage: $(basename $0) start|stop" exit 1 ;; esac [root@RS1-server ~]#bash lvs_dr_rs.sh start The RS Server is Ready! [root@RS2-server ~]#bash lvs_dr_rs.sh start The RS Server is Ready!
3.3 测试访问
[root@intetnet-client ~]#while :;do curl 172.16.0.100;sleep 0.5;done
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
RS2 10.0.0.17
RS1 10.0.0.7
......