基于openEuler构建LVS-DR群集

1.(1)客户端:192.168.32.128

调度器:192.168.32.129

RS1:192.168.32.130

RS2:192.168.32.131

VIP:192.168.32.0/24

RS:1.安装nginx,静态页面

2.绑定VIP

3.arp抑制

LB:

1.绑定VIP

2.安装ipvsadm

3.配置LVS-DR

4.验证

1.安装nginx

[root@openEuler-2 ~]# yum install nginx -y

[root@openEuler-3 ~]# yum install nginx -y

2.找到默认主页

[root@openEuler-2 ~]# ls /usr/share/nginx/html/
404.html  50x.html  index.html  nginx-logo.png
[root@openEuler-3 ~]# ls /usr/share/nginx/html/
404.html  50x.html  index.html  nginx-logo.png

[root@openEuler-2 ~]# echo "web test page,ip is `hostname -I | awk '{print $1}'`."
web test page,ip is 192.168.32.130.
[root@openEuler-3 ~]# echo "web test page,ip is `hostname -I | awk '{print $1}'`."
web test page,ip is 192.168.32.131.

[root@openEuler-2 ~]# echo "web test page,ip is `hostname -I | awk '{print $1}'`." > /usr/share/nginx/html/index.html
[root@openEuler-2 ~]# systemctl enable --now nginx
[root@openEuler-2 ~]# curl localhost
web test page,ip is 192.168.32.130.
[root@openEuler-3 ~]# echo "web test page,ip is `hostname -I | awk '{print $1}'`." > /usr/share/nginx/html/index.html
[root@openEuler-3 ~]# systemctl enable --now nginx
[root@openEuler-3 ~]# curl localhost
web test page,ip is 192.168.32.131.

2.绑定VIP

[root@openEuler-2 ~]# nmcli con add type dummy ifname dummy1 ipv4.method manual ipv4.addresses 192.168.32.0/24
Connection 'dummy-dummy1' (ef01b681-e603-46c1-9a32-81ec481b2bdc) successfully added.
[root@openEuler-3 ~]# nmcli con add type dummy ifname dummy1 ipv4.method manual ipv4.addresses 192.168.32.0/24
Connection 'dummy-dummy1' (b17dadc6-40a5-4131-af19-2017f4935b35) successfully added.

3.完成网络配置后,修改相应的arp内核配置

[root@openEuler-2 ~]# vim /etc/sysctl.conf
[root@openEuler-2 ~]# sysctl -p
kernel.sysrq = 0
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
kernel.dmesg_restrict = 1
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.dummy1.arp_ignore = 1
net.ipv4.conf.dummy1.arp_announce = 2
root@openEuler-3 ~]# vim /etc/sysctl.conf
[root@openEuler-3 ~]# sysctl -p
kernel.sysrq = 0
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
kernel.dmesg_restrict = 1
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.dummy1.arp_ignore = 1
net.ipv4.conf.dummy1.arp_announce = 2

4.调度器上也要绑定VIP

[root@pxc1 ~]# nmcli con add type dummy ifname dummy1 ipv4.method manual ipv4.addresses 192.168.32.0/24
Connection 'dummy-dummy1' (c1680276-1c8b-4376-a19d-f3256a42ef93) successfully added.

5.安装管理工具

[root@pxc1 ~]# yum install ipvsadm -y

6.配置LVS-DR

[root@pxc1 ~]# ipvsadm -At 192.168.32.0:80 -s rr
[root@pxc1 ~]# ipvsadm -at 192.168.32.0:80 -r 192.168.32.130:80 -g
[root@pxc1 ~]# ipvsadm -at 192.168.32.0:80 -r 192.168.32.131:80 -g
[root@pxc1 ~]# ipvsadm -Ln

7.验证客户端

[root@openEuler-1 ~]# curl 192.168.32.130
ip is 192.168.32.130
[root@openEuler-1 ~]# curl 192.168.32.130
ip is 192.168.32.131
[root@openEuler-1 ~]# for((i=1;i<6;i++))
> do
> curl 192.168.32.0
> done
 ip is 192.168.32.131
 ip is 192.168.32.130
 ip is 192.168.32.131
 ip is 192.168.32.130
 ip is 192.168.32.131

2.对比LVS负载均衡群集的NAT模式和DR模式,比较其各自的优势

LVS(Linux Virtual Server)是一个开源的负载均衡解决方案,它提供了多种负载均衡模式,其中 NAT(Network Address Translation)模式和 DR(Direct Routing)模式是比较常用的两种。以下是这两种模式各自的优势对比:

NAT 模式优势

1. 网络结构简单

NAT 模式对网络环境要求较低,只需要一个公网 IP 地址就可以实现多台服务器的负载均衡。所有的服务器可以处于一个内部网络中,通过调度器的 NAT 功能与外部网络通信。这对于网络资源有限,尤其是公网 IP 资源稀缺的环境非常友好。例如,在小型企业网络中,可能只有一个可用的公网 IP,使用 NAT 模式的 LVS 就可以将内部多台 Web 服务器的服务对外提供。

2. 易于管理和配置

在 NAT 模式下,所有的流量都经过调度器,调度器可以方便地对流量进行监控和管理。管理员只需要在调度器上进行配置和维护,不需要对每台真实服务器进行复杂的网络设置。同时,由于真实服务器不需要直接与外部网络通信,它们的安全性也更容易保障,因为可以通过调度器的防火墙进行统一防护。

3. 对服务器要求低

真实服务器不需要具备公网 IP 地址,也不需要对网络配置进行特殊调整,只需要配置内部 IP 地址并连接到内部网络即可。这使得服务器的部署和管理更加简单,降低了对服务器硬件和软件的要求。

DR 模式优势

1. 高性能和高吞吐量

DR 模式中,调度器只负责接收客户端的请求并将其转发给合适的真实服务器,而真实服务器直接将响应返回给客户端,不需要再经过调度器。这样大大减少了调度器的负载,提高了整个系统的处理能力和响应速度,尤其适用于高并发、大流量的应用场景,如大型电商网站、在线游戏平台等。

2. 扩展性强

由于 DR 模式中调度器的负载相对较轻,可以轻松应对大量的并发请求,因此可以通过增加真实服务器的数量来扩展系统的处理能力。而且,真实服务器之间的通信效率较高,不会因为调度器的性能瓶颈而影响整个系统的扩展性。

3. 网络效率高

DR 模式减少了网络传输的中间环节,数据直接在客户端和真实服务器之间传输,降低了网络延迟和带宽消耗。这对于对网络性能要求较高的应用来说非常重要,能够提供更好的用户体验。

综上所述,NAT 模式适合网络资源有限、对配置和管理要求较低的场景;而 DR 模式则更适用于对性能、扩展性和网络效率要求较高的大型应用场景。

相关推荐
obboda3 天前
LVS相关原理
linux·服务器·lvs
小马爱打代码3 天前
负载均衡 LVS vs Nginx 对比
nginx·负载均衡·lvs
竹竿袅袅4 天前
LVS 负载均衡集群(DR 模式)
linux·运维·网络·负载均衡·lvs
2301_旺仔6 天前
负载均衡集群——LVS-DR配置
负载均衡·lvs·linux集群
不会敲代码的XW6 天前
基于 openEuler 构建 LVS-DR 群集
运维·负载均衡·lvs
π大星星️6 天前
LVS 部署 NAT 模式集群实现nginx负载均衡实验
lvs·nat模式集群
only_Klein6 天前
LVS-DR集群构建
linux·服务器·lvs
Spike()6 天前
web集群(LVS-DR)
服务器·网络·lvs
小吃饱了6 天前
基于 openEuler 构建 LVS-DR 群集
开发语言·php·lvs