环境
名称 | IP | 类型 |
---|---|---|
DR | 192.168.163.250 | VIP |
DR | 192.168.163.135 | DIP |
RS1 | 192.168.163.137 | RIP |
RS2 | 192.168.163.134 | RIP |
在DR上配置DIP(135)和VIP(250)
[root@DR network-scripts]# cat ifcfg-ens160
TYPE=Ethernet
BOOTPROTO=static
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR0=192.168.163.135
GATEWAY0=192.168.163.1
NETMASK0=255.255.255.0
IPADDR1=192.168.163.250
GATEWAY1=192.168.163.1
接着.测试本机可以ping通VIP
在RS上分别配置RIP,并将网关指向DIP
[root@localhost network-scripts]# cat ifcfg-ens160
TYPE=Ethernet
BROWSER_ONLY=no
BOOTPROTO=dhcp
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.163.134
GATEWAY=192.168.163.135
NETMASK=255.255.255.0
在DR上开启IP转发,配置转发规则
开启转发功能
[root@DR ~]# vim /etc/sysctl.conf
[root@DR ~]# sysctl -p
net.ipv4.ip_forward = 1
配置规则
[root@DR yum.repos.d]# ipvsadm -A -t 192.168.163.250:80 -s rr
[root@DR yum.repos.d]# ipvsadm -a -t 192.168.163.250:80 -r 192.168.163.134:80 -m
[root@DR yum.repos.d]# ipvsadm -a -t 192.168.163.250:80 -r 192.168.163.137:80 -m
查看规则
[root@DR yum.repos.d]# 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.163.250:80 rr
-> 192.168.163.134:80 Masq 1 0 0
-> 192.168.163.137:80 Masq 1 0 0
保存
[root@DR yum.repos.d]# ipvsadm -Sn > /etc/sysconfig/ipvsadm
[root@DR yum.repos.d]# cat /etc/sysconfig/ipvsadm
-A -t 192.168.163.250:80 -s rr
-a -t 192.168.163.250:80 -r 192.168.163.134:80 -m -w 1
-a -t 192.168.163.250:80 -r 192.168.163.137:80 -m -w 1
在RS上分别配置HTTP
[root@localhost yum.repos.d]# cd /var/www/html
[root@localhost html]# echo "RS1" > index.html
[root@localhost html]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost html]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
验证
[root@DR ~]# curl http:///192.168.163.250
RS1
[root@DR ~]# curl http:///192.168.163.250
RS2