构建LVS负载均衡群集LVS-NAT

本文详细介绍LVS-NAT模式的配置步骤,包括设置VIP地址、安装ipvsadm、配置路由转发规则、设定负载均衡策略及节点服务器配置,实现基于轮询的HTTP服务负载分担。

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

案列:地址转换模式(LVS-NAT)
在这里插入图片描述
1、 实施准备:外网地址172.16.16.172作为vip地址。Lvs调度器有两块网卡
2、 ens33:192.168.7.254 (内网网关)
3、 ens37:172.16.16.172(外网)
Lvs调度器开启路由转发规则,以便节点服务器能够访问lnternet。
共享存储调度器的内网地址网关(192.168.7.254)
2、 配置负载调度器
1) 安装ipvsadm包
[root@localhost ~]# yum -y install ipvsadm
2) 开启路由转发规则
[root@localhost network-scripts]# vim /etc/sysctl.conf
[root@localhost network-scripts]# sysctl -p
net.ipv4.ip_forward = 1
3) 配置负载分配策略
[root@localhost ~]# ipvsadm -C //清除原有的策略
[root@localhost ~]# ipvsadm -A -t 172.16.16.172:80 -s rr 创建虚拟服务器
[root@localhost ~]# ipvsadm -a -t 172.16.16.172:80 -r 192.168.7.21:80 -m -w 1
[root@localhost ~]# ipvsadm -a -t 172.16.16.172:80 -r 192.168.7.22:80 -m -w 1
[root@localhost ~]# ipvsadm -a -t 172.16.16.172:80 -r 192.168.7.23:80 -m -w 1
[root@localhost ~]# ipvsadm -a -t 172.16.16.172:80 -r 192.168.7.24:80 -m -w 1
[root@localhost ~]# ipvsadm-save
-A -t 172.16.16.172:http -s rr
-a -t 172.16.16.172:http -r 192.168.7.21:http -m -w 1
-a -t 172.16.16.172:http -r 192.168.7.22:http -m -w 1
-a -t 172.16.16.172:http -r 192.168.7.23:http -m -w 1
-a -t 172.16.16.172:http -r 192.168.7.24:http -m -w 1
[root@localhost ~]# systemctl enable ipvsadm.service
3、 配置节点服务器
所有节点服务器均使用相同配置,包括http及端口,网站文档。
1)[root@localhost ~]# yum -y install httpd
2)启用httpd服务程序
3)写入httpd访问目录
[root@localhost yum.repos.d]# echo “web1” >> /var/www/html/index.html
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
4) 在客户机测试lvs群集,如果有多个节点的网页不同,刷新则不同
在这里插入图片描述
在这里插入图片描述
如果要实现web目录统一,在所有节点服务器挂载nfs
[root@localhost yum.repos.d]# showmount -e 192.168.7.250
Export list for 192.168.7.250:
/opt/wwwroot *
[root@localhost yum.repos.d]# mount 192.168.7.250:/opt/wwwroot /var/www/html/
在测试如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值