架構圖:

環境:
一臺:客戶端 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
eth0:NAT:DIP:10.0.0.8/24 GW:10.0.0.200
兩臺RS:
RS1:eth0:NAT:10.0.0.7/24 GW:10.0.0.200
RS2:eth0:NAT:10.0.0.17/24 GW:10.0.0.200
配置:
Router
[root@Router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24
[root@Router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.10.200
PREFIX=24
#開啟Router的ip_forward功能
[root@Router ~]# cat /etc/sysctl.d/99-sysctl.conf
net.ipv4.ip_forward = 1
[root@Router ~]# sysctl -p
net.ipv4.ip_forward = 1
Client:
tom@Client:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#auto eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.10.6
netmask 255.255.255.0
gateway 192.168.10.200
tom@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 0 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
LVS:
[root@LVS ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.8
PREFIX=24
GATEWAY=10.0.0.200
DNS1=180.76.76.76
[root@LVS ~]# 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
#在LVS上添加VIP
ifconfig lo:1 10.0.0.100/32
#實作LVS 規則
[root@LVS ~]#dnf -y install ipvsadm
[root@LVS ~]#ipvsadm -A -t 10.0.0.100:80 -s rr
[root@LVS ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.7:80 -g
[root@LVS ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.17:80 -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 10.0.0.100:80 rr
-> 10.0.0.7:80 Route 1 0 0
-> 10.0.0.17:80 Route 1 0 0
RS1:
[root@RS1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.200
[root@RS1 ~]# 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
#設定RS1的VIP
[root@RS1 ~]# ifconfig lo:1 10.0.0.100/32
#RS1的IPVS配置
#關閉配置vip網卡的arp的兩個內核引數
#需要寫入組態檔中才會重啟生效
[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
#設定RS1的web服務
[root@RS1 ~]# yum -y install httpd
[root@RS1 ~]# systemctl enable --now httpd
[root@RS1 ~]# 10.0.0.17 rs1 -I > /var/www/html/index.html
[root@RS1 ~]# curl 10.0.0.17
10.0.0.17 rs1
RS2:
[root@RS2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.17
PREFIX=24
GATEWAY=10.0.0.200
[root@RS2 ~]# 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
#設定RS2的VIP
[root@RS2 ~]# ifconfig lo:1 10.0.0.100/32
#RS2的IPVS配置
[root@RS2 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore #忽略請求
[root@RS2 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce #對外宣傳
[root@RS2 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@RS2 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
#安裝并啟動web服務
[root@RS2 ~]# yum -y install httpd
[root@RS2 ~]# systemctl enable --now httpd
[root@RS2 ~]# 10.0.0.17 rs1 -I > /var/www/html/index.html
[root@RS2 ~]# curl 10.0.0.7
10.0.0.7 rs2
測驗:
tom@Client:~$ curl 10.0.0.100
10.0.0.7 rs1
tom@Client:~$ curl 10.0.0.100
10.0.0.7 rs1
說明:
DR模型中各主機上均需要配置VIP,解決地址沖突的方式有三種:
-
(1) 在前端網關做靜態系結
-
(2) 在各RS使用arptables
-
(3) 在各RS修改內核引數,來限制arp回應和通告的級別
限制回應級別:arp_ignore
-
0:默認值,表示可使用本地任意介面上配置的任意地址進行回應
-
1:僅在請求的目標IP配置在本地主機的接收到請求報文的介面上時,才給予回應
限制通告級別:arp_announce
-
0:默認值,把本機所有介面的所有資訊向每個介面的網路進行通告
-
1:盡量避免將介面資訊向非直接連接網路進行通告
-
2:必須避免將介面資訊向非本網路進行通告
注意:
lvs的DR模式,不支持埠映射功能,DR模式只修改資料鏈路層,不會修改網路鏈層以上,
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/521753.html
標籤:其他
上一篇:AIR32F103(四) 27倍頻216MHz,CoreMark跑分測驗
下一篇:在不受支持的 Mac 上安裝 macOS Ventura、Monterey、Big Sur (OpenCore Legacy Patcher)
