lvs配置之DR模式

环境

系统 IP
redhat 8 DR  192.168.100.131 vip:192.168.100.100
redhat 8 RS1  192.168.100.132 vip:192.168.100.100
redhat 8 RS2  192.168.100.133 vip:192.168.100.100

 

准备工作

//安装ipvsadm
[root@DR ~]# dnf -y install ipvsadm
[root@RS1 ~]# dnf -y install ipvsadm
[root@RS2 ~]# dnf -y install ipvsadm

//RS1.RS2安装httpd
#dnf -y install httpd

//RS1.RS2.DR关闭防火墙和selinux
#systemctl stop firewalld
#setenforce 0

//RS1.RS2设置开机自启并立即启动httpd
#systemctl enable --now httpd

//创建测试页(如果想直观查看测试结果可以做这一步,否则可以跳过)
[root@RS1 ~]# echo "RS1" > /var/www/html/index.html
[root@RS2 ~]# echo "RS2" > /var/www/html/index.html
[root@DR ~]# ip addr add 192.168.100.100/32 dev ens160
//这条两台RS机器都做
yum -y install httpd net-tools

 

RS服务器配置

//RS1
[root@RS1 ~]# vim /etc/sysctl.conf
// 在最后面插入如下两行
net.ipv4.conf.all.arp_ignore = 1     // 将对应网卡设置为只回应目标IP为自身接口地址的ARP请求
net.ipv4.conf.all.arp_announce = 2    // 将ARP请求的源IP设置为eth0上的IP,也就是RIP

[root@RS1 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

//RS2
[root@RS2 ~]# vim /etc/sysctl.conf
// 在最后面插入如下两行
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

[root@RS2 ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

配置VIP

一定要先设置好内核参数在配置VIP,如果先配置VIP,VIP配置好后会立即通告给所有人,而修改内核参数就是为了不通告

//Rs1
[root@RS1 ~]# ip addr add 192.168.100.100/32 dev lo
//Rs2
[root@RS1 ~]# ip addr add 192.168.100.100/32 dev lo

配置路由信息

//RS1
[root@RS1 ~]#  route add -host 192.168.100.100/32 dev lo
[root@RS1 ~]# echo "192.168.100.100/32 via 0.0.0.0 dev lo" > /etc/sysconfig/network-scripts/route-lo
[root@RS1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.254 0.0.0.0         UG    100    0        0 ens160
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens160
192.168.100.100 0.0.0.0         255.255.255.255 UH    0      0        0 lo

//RS2
[root@RS2 ~]# route add -host 192.168.100.100/32 dev lo
[root@RS2 ~]# echo '192.168.100.100/32 via 0.0.0.0 dev lo' > /etc/sysconfig/network-scripts/route-lo
[root@RS2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.254 0.0.0.0         UG    100    0        0 ens160
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens160
192.168.100.100 0.0.0.0         255.255.255.255 UH    0      0        0 lo

添加并保存规则

//DR
[root@DR network-scripts]# ipvsadm -A -t 192.168.100.100:80 -s wrr
[root@DR network-scripts]#  ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.132 -g
[root@DR network-scripts]#  ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.133 -g

[root@DR network-scripts]# 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.100.100:80 wrr
  -> 192.168.100.132:80           Route   1      0          0         
  -> 192.168.100.133:80           Route   1      0          0 

[root@DR network-scripts]# ipvsadm -S > /etc/sysconfig/ipvsadm
[root@DR network-scripts]# systemctl enable --now ipvsadm

访问测试

[root@DR network-scripts]# 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.100.100:80 wrr
  -> 192.168.100.132:80           Route   1      4          1         
  -> 192.168.100.133:80           Route   1      1          1  

 

posted @ 2021-05-07 20:35  离愁落雨  阅读(84)  评论(0编辑  收藏  举报