LVS-DR模式单网段案例
环境:
一台:客户端 eth0:仅主机 192.168.10.11/24 GW:192.168.10.100
一台:ROUTER
eth0 :NAT 10.0.0.81/24
eth1: 仅主机 192.168.10.100/24
启用 IP_FORWARD
一台:LVS
eth0: NAT: DIP:10.0.0.8/24 GW:10.0.0.81 VIP:10.0.0.10/32
两台RS:
RS1:eth0:NAT:10.0.0.71/24 GW:10.0.0.81 VIP:10.0.0.10/32
RS2:eth0:NAT:10.0.0.72/24 GW:10.0.0.81 VIP:10.0.0.10/32
**
LVS的网络配置
**
client 主机环境
root@client:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.10.100 0.0.0.0 UG 0 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
route的网络配置
[root@router ~]# echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
[root@router ~]# cat /etc/sys
sysconfig/ sysctl.d/ system-release
sysctl.conf systemd/ system-release-cpe
[root@router ~]# cat /etc/sysctl.conf
。。。。。。
net.ipv4.ip_forward=1
[root@router ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.0.0.81
PREFIX=24
[root@router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth1
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.10.100
PREFIX=24
RS1/2的网络配置一样
[root@rs1 ~]#yum -y install httpd
[root@rs1 ~]#systemctl enable --now httpd
[root@rs1 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.81
ONBOOT=yes
LVS的网络配置
[root@lvs ~]#yum -y install ipvsadm
(先下载再改配置)
[root@lvs ~]#ip route
default via 10.0.0.81 dev eth0 proto static metric 100
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.82 metric 100
后端RS的IPVS配置
LVS主机的配置
#RS1/2的IPVS配置
[root@rs1 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@rs1 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@rs1 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@rs1 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@rs1 ~]#ifconfig lo:1 10.0.0.10/32
[root@rs1 ~]#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.10/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:60:f8:02 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.71/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe60:f802/64 scope link
valid_lft forever preferred_lft forever
LVS主机的配置
[root@lvs ~]#ifconfig lo:1 10.0.0.10/32
[root@lvs ~]#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.10/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:9f:f0:4a brd ff:ff:ff:ff:ff:ff
inet 10.0.0.82/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe9f:f04a/64 scope link
valid_lft forever preferred_lft forever
加规则
[root@lvs ~]#ipvsadm -A -t 10.0.0.10:80 -s rr
[root@lvs ~]#ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.71 -g
[root@lvs ~]#ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.72 -g
root@client:~# curl 10.0.0.10
Second back end
root@client:~# curl 10.0.0.10
The first back end