ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

NAT模式 LVS负载均衡群集部署

2022-06-13 04:31:08  阅读:166  来源: 互联网

标签:opt LVS service 群集 ipvsadm 12.0 systemctl NAT 172.16


NAT模式 LVS负载均衡群集部署的操作步骤

实验环境准备:

负载调度器:内网关 ens33:172.16.10.1,外网关 ens37:12.0.0.1

Web节点服务器1:172.16.10.10

Web节点服务器2:172.16.10.20

NFS服务器:172.16.10.101

客户端:12.0.0.20

1、部署共享存储(NFS服务器:172.16.10.101)

systemctl stop firewalld.service

systemctl disable firewalld.service

setenforce 0

yum install nfs-utils rpcbind -y

systemctl start rpcbind.service

systemctl start nfs.service

systemctl enable rpcbind.service

systemctl enable nfs.service

mkdir /opt/xhx /opt/hello

chmod 777 /opt/xhx /opt/hello

echo 'this is xhx web!' > /opt/xhx/index.html

echo 'this is hello web!' > /opt/hello/index.html

vim /etc/exports

/opt/xhx 172.16.10.0/24(rw,sync)

/opt/hello 172.16.10.0/24(rw,sync)

systemctl start rpcbind

systemctl start nfs

重新加载nfs服务,并显示共享目录:

exports -rv

 

2、配置节点服务器(172.16.10.10、172.16.10.20)

 

--172.16.10.10---

systemctl stop firewalld.service

systemctl disable firewalld.service

setenforce 0

yum install httpd -y

systemctl start httpd.service

systemctl enable httpd.service

yum install nfs-utils rpcbind -y

showmount -e 172.16.10.101

mount.nfs 172.16.10.101:/opt/xhx /var/www/html

 

另一台节点服务器挂载如下:

--172.16.10.20---

systemctl stop firewalld.service

systemctl disable firewalld.service

setenforce 0

yum install httpd -y

systemctl start httpd.service

systemctl enable httpd.service

yum install nfs-utils rpcbind -y

showmount -e 172.16.10.101

mount.nfs 172.16.10.101:/opt/weq /var/www/html

 

3、配置负载调度器(内网关 ens33:172.16.10.1,外网关 ens37:12.0.0.1)

systemctl stop firewalld.service

systemctl disable firewalld.service

setenforce 0

4、配置SNAT转发规则

yum -y install iptables iptables-services

vim /etc/sysctl.conf

net.ipv4.ip_forward = 1 #添加ip路由转发

sysctl -p

iptables -t nat -F iptables -F iptables -t nat -A POSTROUTING -s 172.16.10.0/24 -o ens37 -j SNAT --to 12.0.0.1

5、加载LVS内核模块

modprobe ip_vs #加载 ip_vs模块

cat /proc/net/ip_vs #查看 ip_vs版本信息

 

6、 安装ipvsadm 管理工具

yum -y install ipvsadm

ipvsadm-save > /etc/sysconfig/ipvsadm

或者 ipvsadm --save > /etc/sysconfig/ipvsadm

systemctl start ipvsadm.service

7、配置负载分配策略(NAT模式只要在服务器上配置,节点服务器不需要特殊配置)

ipvsadm -C #清除原有策略

ipvsadm -A -t 12.0.0.1:80 -s rr ipvsadm -a -t 12.0.0.1:80 -r 172.16.10.10:80 -m #添加真实ip

ipvsadm -a -t 12.0.0.1:80 -r 172.16.10.20:80 -m #添加真实

ip ipvsadm #启用策略

ipvsadm -ln #查看节点状态,Masq代表 NAT模式

ipvsadm-save > /etc/sysconfig/ipvsadm #保存策略

 

8、测试效果

网络设置里面网关需要设置为网关服务器 在一台IP为12.0.0.55的客户机使用浏览器访问 http://12.0.0.1/ ,不断刷新浏览器测试负载均衡效果,刷新间隔需长点。  

标签:opt,LVS,service,群集,ipvsadm,12.0,systemctl,NAT,172.16
来源: https://www.cnblogs.com/xhx1991874414/p/16369468.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有