DR模式
1.根据服务器的角色修改主机名
- internet clinet
[root@centos8 ~]# hostnamectl set-hostname internet
- firewall
[root@centos8 ~]# hostnamectl set-hostname firewall
- router
[root@centos8 ~]# hostnamectl set-hostname router
- lvs director
[root@centos8 ~]# hostnamectl set-hostname lvs
- real sever 1
[root@centos8 ~]# hostnamectl set-hostname rs1
- real server 2
[root@centos8 ~]# hostnamectl set-hostname rs2
2、配置router
- 将路由器网关指向防火墙firewall
[root@router ~]# ip route
default via 10.0.0.28 dev eth1 proto static metric 105
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.68 metric 104
192.168.6.0/24 dev eth1 proto kernel scope link src 192.168.6.68 metric 105
[root@router ~]#
- 开启路由转发功能
[root@router ~]# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
[root@router ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@router ~]#
3、部署lvs服务器
- 安装lvs管理工具
[root@lvs ~]# yum -y install ipvsadm
- 添加vip地址并将网关指向路由器router
[root@lvs ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.0.0.38
IPADDR1=10.0.0.200 #vip地址
GATEWAY=10.0.0.68
PREFIX=24
TYPE=Ethernet
DNS1=180.76.76.76
[root@lvs ~]# nmcli con reload
[root@lvs ~]# nmcli con up eth0
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)
[root@lvs ~]#
[root@lvs ~]# ip route
default via 10.0.0.68 dev eth0 proto static metric 100
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.38 metric 100
[root@lvs ~]#
- 创建lvs规则
[root@lvs ~]# ipvsadm -C
[root@lvs ~]# ipvsadm -A -t 10.0.0.200:80 -s rr #创建一个轮询集群
[root@lvs ~]# ipvsadm -a -t 10.0.0.200:80 -r 10.0.0.48 -g #-g 是DR模式
[root@lvs ~]# ipvsadm -a -t 10.0.0.200:80 -r 10.0.0.58 -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.200:80 rr
-> 10.0.0.48:80 Route 1 0 0
-> 10.0.0.58:80 Route 1 0 0
[root@lvs ~]#
4、部署RS1服务器
- rs1 安装httpd服务
[root@rs1 ~]# yum -y install httpd
[root@rs1 ~]# systemctl start httpd
[root@rs1 ~]#
- 将网关指向router
[root@rs1 ~]# ip route
default via 10.0.0.68 dev eth0 proto static metric 100
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.48 metric 100
[root@rs1 ~]#
- 修改内核参数,禁止realserver回应和发arp广播
[root@rs1 ~]# echo "net.ipv4.conf.all.arp_ignore=1" >> /etc/sysctl.conf
[root@rs1 ~]# echo "net.ipv4.conf.lo.arp_ignore=1" >> /etc/sysctl.conf
[root@rs1 ~]# echo "net.ipv4.conf.all.arp_announce=2" >> /etc/sysctl.conf
[root@rs1 ~]# echo "net.ipv4.conf.lo.arp_announce=2" >> /etc/sysctl.conf
[root@rs1 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
[root@rs1 ~]#
- 在lo网卡配置VIP
[root@rs1 ~]# ip add add 10.0.0.200/32 dev lo
[root@rs1 ~]# ip ad
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.200/32 scope global lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
5、部署RS2服务器
- rs2 安装httpd服务
[root@rs2 ~]# yum -y install httpd
[root@rs2 ~]# systemctl start httpd
[root@rs2 ~]#
- 将网关指向router
[root@rs2 ~]# ip route
default via 10.0.0.68 dev eth0 proto static metric 100
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.48 metric 100
[root@rs2 ~]#
- 修改内核参数,禁止realserver回应和发arp广播
[root@rs2 ~]# echo "net.ipv4.conf.all.arp_ignore=1" >> /etc/sysctl.conf
[root@rs2 ~]# echo "net.ipv4.conf.lo.arp_ignore=1" >> /etc/sysctl.conf
[root@rs2 ~]# echo "net.ipv4.conf.all.arp_announce=2" >> /etc/sysctl.conf
[root@rs2 ~]# echo "net.ipv4.conf.lo.arp_announce=2" >> /etc/sysctl.conf
[root@rs2 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
[root@rs2 ~]#
- 在lo网卡配置VIP
[root@rs2 ~]# ip ad ad 10.0.0.200/32 dev lo
[root@rs2 ~]# ip ad
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.200/32 scope global lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
6、部署 firewall服务器
- 开启路由转发功能
[root@firewall ~]# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
[root@firewall ~]# sysctl -p
net.ipv4.ip_forward = 1
- 设置iptables转发规则,收到外网到“公网”IP192.168.6.200的httpd请求,转发给VIP地址10.0.0.200的httpd
[root@firewall ~]# iptables -t nat -A PREROUTING -d 192.168.6.200 -p tcp --dport 80 -j DNAT --to-destination 10.0.0.200:80
[root@firewall ~]#
- 删除eth0网关
[root@centos8 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
NETBOOT=yes
UUID="ee1d9be0-11ff-4ff1-a1de-6e0ca0d72661"
IPV6INIT=yes
BOOTPROTO=static
IPADDR=10.0.0.28
PREFIX=24
TYPE=Ethernet
DNS1=180.76.76.76
[root@centos8 ~]#
- 将“公网”IP192.168.6.200配置到网卡上,并删除网关
[root@centos8 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Generated by dracut initrd
NAME="eth1"
DEVICE="eth1"
ONBOOT=yes
NETBOOT=yes
IPV6INIT=yes
BOOTPROTO=static
IPADDR=192.168.6.28
IPADDR1=192.168.6.200
PREFIX=24
TYPE=Ethernet
DNS1=180.76.76.76
[root@centos8 ~]#
7、在Internet服务器访问测试
[root@internet ~]# curl 192.168.6.200
rs1
[root@internet ~]# curl 192.168.6.200
rs2
[root@internet ~]# curl 192.168.6.200
rs1
[root@internet ~]# curl 192.168.6.200
rs2