【LVS】部署DR模式集群

 一、配置实验环境

每台主机的防火墙和SELinux都要关掉

systemctl stop firewalld

setenforce 0

1、client(eth0为nat模式)

配置好网卡IP和网关IP,然后重启网卡

nmcli connection reload

nmcli connection up eth0

[root@client ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection 
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
method=manual
address1=172.25.254.200/24,172.25.254.100
dns=114.114.114.114
[root@client ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.25.254.100  0.0.0.0         UG    100    0        0 eth0
172.25.254.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0

2、route(eth0为nat模式和eth1为仅主机模式)

配置好网卡IP,然后重启网卡

nmcli connection reload

nmcli connection up eth0

nmcli connection up eth1

[root@route ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection 
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
method=manual
address1=172.25.254.100/24
[root@route ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection 
[connection]
id=eth1
type=ethernet
interface-name=eth1

[ipv4]
method=manual
address1=192.168.0.100/24

3、lvs(eth1为仅主机模式)

配置好网卡IP和网关以及环路IP,然后重启网卡

nmcli connection reload

nmcli connection up eth1

[root@lvs ~]# ip a a 192.168.0.200/32 dev lo

[root@lvs ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection 
[connection]
id=eth1
type=ethernet
interface-name=eth1

[ipv4]
method=manual
address1=192.168.0.50/24,192.168.0.100
[root@lvs ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.100   0.0.0.0         UG    100    0        0 eth1
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 eth1

4、webserver1(eth0为仅主机模式)

配置好网卡IP和网关以及环路IP,然后重启网卡

nmcli connection reload

nmcli connection up eth0

[root@lvs ~]# ip a a 192.168.0.200/32 dev lo

[root@webserver1 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection 
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
method=manual
address1=192.168.0.10/24,192.168.0.100
[root@webserver1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.100   0.0.0.0         UG    100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0

5、webserver2(eth0为仅主机模式)

配置好网卡IP和网关以及环路IP,然后重启网卡

nmcli connection reload

nmcli connection up eth0

[root@lvs ~]# ip a a 192.168.0.200/32 dev lo

[root@webserver2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection 
[connection]
id=eth0
type=ethernet
interface-name=eth0

[ipv4]
method=manual
address1=192.168.0.20/24,192.168.0.100
[root@webserver2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.100   0.0.0.0         UG    100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0

 二、解决vip响应问题

DR模型中各主机上均需要配置VIP,解决地址冲突的方式有三种:

(1)在前端网关做静态绑定

(2)在各RS使用arptables

(3)在各RS修改内核参数,来限制arp响应和通告的级别

限制响应级别:arp_ignore

  • 0:默认值,表示可使用本地任意接口上配置的任意地址进行响应
  • 1:仅在请求的目标IP配置在本地主机的接收到请求报文的接口上时,才给予响应

限制通告级别:arp_announce

  • 0:默认值,把本机所有接口的所有信息向每个接口的网络进行通告
  • 1:尽量避免将接口信息向非直接连接网络进行通告 2:必须避免将接口信息向非本网络进行通告

webserver1:

[root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

[root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

[root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

[root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

webserver2:

[root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

[root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

[root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

[root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

三、配置策略

lvs:

[root@lvs ~]# ipvsadm -A -t 192.168.0.200:80 -s wrr

[root@lvs ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.10:80 -g -w 1

[root@lvs ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.20:80 -g -w 2

 四、路由器启用IP转发功能

net.ipv4.ip_forward = 1启用IP转发功能,当设置为 1 时,表示允许系统在不同的网络接口之间转发 IP 数据包。

net.ipv4.ip_forward_update_priority = 1这个配置项用于设置 IP 转发更新的优先级。当系统进行 IP 转发相关的更新操作时,这个优先级值会影响更新的顺序和处理方式。

net.ipv4.ip_forward_use_pmtu = 0这个配置项控制着在 IP 转发过程中是否使用路径最大传输单元(PMTU)发现机制。当设置为 0 时,表示在 IP 转发中不使用 PMTU 发现。

[root@route ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1       
net.ipv4.ip_forward_update_priority = 1        
net.ipv4.ip_forward_use_pmtu = 0

在 /etc/sysctl.conf配置文件中添加net.ipv4.ip_forward = 1

五、测试结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

new不出对象来

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值