节点规划:

配置RS:
RS1-RS3的网关配置均为 192.168.163.8
配置RS1:
[root@localhost ~]# hostnamectl hostname rs1
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.163.7/24 ipv4.gateway 192.168.163.8 connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
[root@rs1 ~]# dnf install nginx -y
[root@rs1 ~]# echo $(hostname -I) > /usr/share/nginx/html/index.html
[root@rs1 ~]# systemctl start nginx
[root@rs1 ~]# curl localhost
192.168.163.7
配置RS2:
[root@localhost ~]# hostnamectl hostname rs2
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.163.17/24 ipv4.gateway 192.168.163.8 connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
[root@rs2 ~]# dnf install nginx -y
[root@rs2 ~]# echo $(hostname -I) > /usr/share/nginx/html/index.html
[root@rs2 ~]# systemctl start nginx
[root@rs2 ~]# curl localhost
192.168.163.17
配置RS3:
[root@localhost ~]# hostnamectl hostname rs3
[root@localhost ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.163.27/24 ipv4.gateway 192.168.163.8 connection.autoconnect yes
[root@localhost ~]# nmcli c up ens160
[root@rs3 ~]# dnf install nginx -y
[root@rs3 ~]# echo $(hostname -I) > /usr/share/nginx/html/index.html
[root@rs3 ~]# systemctl start nginx
[root@rs3 ~]# curl localhost
192.168.163.27
配置LVS:
lvs服务器有两块网卡,第一块网卡采用仅主机模式,IP 地址为 192.168.110.200,第二块网卡采用 NAT 模式,IP 地址为192.168.163.8
修改虚拟网络及主机名:
[root@localhost ~]# nmcli c modify 'Wired connection 1' connection.id ens224
[root@localhost ~]# nmcli c show
NAME UUID TYPE DEVICE
ens224 716944d5-683d-3297-9f0b-39530d65c935 ethernet ens224
ens160 c6adadcb-89ef-3ed8-a265-09260f58abe1 ethernet ens160
lo 3919112a-6bb6-4ad3-a213-3ce8394ca9a9 loopback lo
[root@localhost ~]# hostnamectl hostname lvs
配置仅主机模式网卡:
[root@lvs ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.110.200/24 ipv4.gateway 192.168.110.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@lvs ~]# nmcli c up ens160
安装软件:
[root@lvs ~]# dnf install ipvsadm -y
配置NAT模式网卡:
[root@lvs ~]# nmcli c modify ens224 ipv4.method manual ipv4.addresses 192.168.163.8/24 ipv4.gateway 192.168.163.2 connection.autoconnect yes
[root@lvs ~]# nmcli c up ens224
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
配置客户端:
[root@localhost ~]# hostnamectl hostname client
[root@client ~]# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.10.100/24 ipv4.gateway 192.168.10.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@client ~]# nmcli c up ens160
[root@client ~]# nmcli d show ens160
GENERAL.DEVICE: ens160
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:DF:3E:09
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: ens160
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnecti>
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.110.100/24
IP4.GATEWAY: 192.168.110.2
IP4.ROUTE[1]: dst = 192.168.110.0/24, nh = 0.0.0.0, mt = 100
IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 192.168.110.2, mt = 100
IP4.DNS[1]: 223.5.5.5
IP6.ADDRESS[1]: fe80::20c:29ff:fedf:3e09/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 1024
启动ipvsadm服务:
[root@lvs ~]# ipvsadm-save > /etc/sysconfig/ipvsadm
[root@lvs ~]# systemctl start ipvsadm
[root@lvs ~]# ipvsadm -C
[root@lvs ~]# ipvsadm -A -t 192.168.110.200:80 -s rr
[root@lvs ~]# ipvsadm -a -t 192.168.110.200:80 -r 192.168.163.7:80 -m
[root@lvs ~]# ipvsadm -a -t 192.168.110.200:80 -r 192.168.163.17:80 -m
[root@lvs ~]# ipvsadm -a -t 192.168.110.200:80 -r 192.168.163.27:80 -m
[root@lvs ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.110.200:80 rr
-> 192.168.163.7:80 Masq 1 0 0
-> 192.168.163.17:80 Masq 1 0 0
-> 192.168.163.27:80 Masq 1 0 0
配置完成后,重启服务
[root@lvs ~]# systemctl restart ipvsadm
重启好后再配置内核转发参数net.ipv4.ip_forward=1
。
[root@lvs ~]# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
[root@lvs ~]# sysctl -p
net.ipv4.ip_forward = 1