LVS的DR模式与NAT模式的部署

本文介绍了LVS集群在DR模式和NAT模式下的配置步骤,包括子接口创建、服务器配置、访问测试及性能比较。在DR模式下,由于不涉及IP地址转换,性能更优,资源消耗更低。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LVS集群配置信息DR模式

节点关闭Networkmanager所有的节点

[root@zabbix-server ~]# systemctl stop NetworkManager.service
[root@zabbix-server ~]# systemctl disable NetworkManager.service
lvs机器上创建一个子接口
[root@centos network-scripts]# cat ifcfg-eno16777728:0
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
DEVICE=eno16777728:0
ONBOOT=yes
DNS1=192.168.40.2
IPADDR=192.168.40.100
PREFIX=24
GATEWAY=192.168.40.2
[root@centos network-scripts]# systemctl restart network
[root@centos network-scripts]# ifconfig
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.40.25  netmask 255.255.255.0  broadcast 192.168.40.255
        inet6 fe80::20c:29ff:feda:abcb  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:da:ab:cb  txqueuelen 1000  (Ethernet)
        RX packets 50417  bytes 71989175 (68.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14742  bytes 1029561 (1005.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno16777728:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.40.100  netmask 255.255.255.0  broadcast 192.168.40.255
        ether 00:0c:29:da:ab:cb  txqueuelen 1000  (Ethernet)

关闭广播功能
[root@centos ~]# grep -v "#" /etc/sysctl.conf
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.eno16777728.send_redirects=0
[root@centos ~]# sysctl -p
安装软件
[root@centos ~]# yum install -y ipvsadm
[root@centos ~]# modprobe ip_vs
[root@centos ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
[root@centos ~]#
配置服务器1和2完全一致
[root@zabbix-server network-scripts]# cat ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.40.100
NETMASK=255.255.255.255
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback
[root@zabbix-server ~]# grep -v "#" /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.lo.arp_ignore=1
net.ipv4.conf.lo.arp_announce=2
[root@zabbix-server ~]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
[root@zabbix-server ~]# ifup lo:0
[root@zabbix-server ~]# ifconfig
lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.40.100  netmask 255.255.255.255
        loop  txqueuelen 0  (Local Loopback)
[root@zabbix-server ~]# route add -host 192.168.40.100 dev lo:0
[root@zabbix-server ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.40.2    0.0.0.0         UG    100    0        0 eno16777                                                                                                         736
192.168.40.0    0.0.0.0         255.255.255.0   U     100    0        0 eno16777                                                                                                         736
192.168.40.100  0.0.0.0         255.255.255.255 UH    0      0        0 lo
[root@zabbix-server ~]#

访问测试

在这里插入图片描述

LVS配置规则测试
[root@centos ~]# ipvsadm -A -t 192.168.40.100:80 -s rr
[root@centos ~]# ipvsadm -a -t 192.168.40.100:80 -r 192.168.40.23:80 -g
[root@centos ~]# ipvsadm -a -t 192.168.40.100:80 -r 192.168.40.24:80 -g
[root@centos ~]# 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.40.100:80 rr
  -> 192.168.40.23:80             Route   1      0          0
  -> 192.168.40.24:80             Route   1      0          0
[root@centos ~]#

LVS集群配置信息NAT模式

在这里插入图片描述

角色IP地址
lvs负载均衡192.168.40.25/24 10.10.10.11/24
web服务器1192.168.40.23/24
web服务器2192.168.40.24/24

所有的节点关闭NetworkManager防火墙和selinux

[root@zabbix-server ~]# systemctl stop NetworkManager.service
[root@zabbix-server ~]# systemctl disable NetworkManager.service
[root@zabbix-server ~]# systemctl stop firewalld.service
[root@zabbix-server ~]# setenforce 0
lvs负载均衡
[root@centos ~]# echo "1" > /proc/sys/net/ipv4/ip_forward
[root@centos ~]# sysctl -p
[root@centos ~]# yum install -y ipvsadm
[root@centos ~]# systemctl start ipvsadm
[root@centos ~]# iptables -t nat -A POSTROUTING -s 192.168.40.0/24 -o eno16777728 -j SNAT --to-source 10.10.10.11
[root@centos ~]# ipvsadm -A -t 10.10.10.11:80 -s rr
[root@centos ~]# ipvsadm -a -t 10.10.10.11:80 -r 192.168.40.23:80 -m
[root@centos ~]# ipvsadm -a -t 10.10.10.11:80 -r 192.168.40.24:80 -m
[root@centos ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.10.10.11:80 rr
  -> 192.168.40.23:80             Masq    1      0          0
  -> 192.168.40.24:80             Masq    1      0          0
[root@centos ~]#
所有服务器端

将网关换成为lvs另外一张网卡的ip

[root@zabbix-server network-scripts]# grep -i "gateway" ifcfg-eno16777736
GATEWAY=192.168.40.25
[root@zabbix-server network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.40.25   0.0.0.0         UG    100    0        0 eno16777736
192.168.40.0    0.0.0.0         255.255.255.0   U     100    0        0 eno16777736
[root@zabbix-server network-scripts]#

访问测试

在这里插入图片描述
总结:在生产使用中DR模式比NAT更加的优秀,因为它能处理更多的响应。处理相同的响应的资源消耗比NAT模式更加的低。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值