NAT模式 LVS负载均衡群集部署
作者:互联网
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