目录

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

1.部署共享存储

2.配置节点服务器

192.168.17.130

​编辑

192.168.17.133

3.配置负载调度器

4.测试效果


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

负载调度器:内网关 ens33:192.168.17.70,外网关 ens36:12.0.0.1
Web节点服务器1:192.168.17.130
Web节点服务器2:192.168.17.133
NFS服务器:192.168.17.60
客户端:12.0.0.40

1.部署共享存储

NFS服务器:192.168.17.60

systemctl stop firewalld.servicesystemctl disable firewalld.servicesetenforce 0yum install nfs-utils rpcbind -ysystemctl start rpcbind.servicesystemctl start nfs.servicesystemctl enable nfs.servicesystemctl enable rpcbind.servicemkdir /opt/kgc /opt/benetchmod 777 /opt/kgc /opt/benetecho 'this is kgc web!' > /opt/kgc/index.htmlecho 'this is benet web!' > /opt/benet/index.htmlvim /etc/exports/usr/share *(ro,sync)/opt/kgc 192.168.17.0/24(rw,sync)/opt/benet 192.168.17.0/24(rw,sync)--发布共享---exportfs -rv

2.配置节点服务器

192.168.17.130、192.168.17.133

systemctl stop firewalld.servicesystemctl disable firewalld.servicesetenforce 0yum install httpd -ysystemctl start httpd.servicesystemctl enable httpd.serviceyum install nfs-utils rpcbind -yshowmount -e 192.168.17.60systemctl start rpcbindsystemctl enable rpcbind--192.168.17.130---mount.nfs 192.168.17.60:/opt/kgc /var/www/htmlvim /etc/fstab192.168.80.13:/opt/kgc/var/www/htmlnfsdefaults,_netdev00--192.168.17.133---mount.nfs 192.168.17.60:/opt/benet /var/www/htmlecho 'this is benet web!' > /var/www/html/index.htmlvim /etc/fstab192.168.17.60:/opt/benet/var/www/htmlnfs defaults,_netdev00

192.168.17.130

修改网关

换成服务器的IP地址

192.168.17.133

换成服务器的IP地址

3.配置负载调度器

内网关 ens33:192.168.17.70,外网关 ens36:12.0.0.1

systemctl stop firewalld.servicesystemctl disable firewalld.servicesetenforce 0(1)配置SNAT转发规则vim /etc/sysctl.confnet.ipv4.ip_forward = 1(2)加载LVS内核模块modprobe ip_vs#加载 ip_vs模块cat /proc/net/ip_vs#查看 ip_vs版本信息for i in $(ls /usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs|grep -o "^[^.]*");do echo $i; /sbin/modinfo -F filename $i >/dev/null 2>&1 && /sbin/modprobe $i;done(3)安装ipvsadm 管理工具yum -y install ipvsadm--启动服务前须保存负载分配策略---ipvsadm-save > /etc/sysconfig/ipvsadm或者 ipvsadm --save > /etc/sysconfig/ipvsadmsystemctl start ipvsadm.service(4)配置负载分配策略(NAT模式只要在服务器上配置,节点服务器不需要特殊配置)ipvsadm -C #清除原有策略ipvsadm -A -t 12.0.0.1:80 -s rr [-p 60]ipvsadm -a -t 12.0.0.1:80 -r 192.168.17.130:80 -m [-w 1]ipvsadm -a -t 12.0.0.1:80 -r 192.168.17.133:80 -m [-w 1]ipvsadm#启用策略ipvsadm -ln#查看节点状态,Masq代表 NAT模式ipvsadm-save > /opt/ipvsadm#保存策略ipvsadm-save > /etc/sysconfig/ipvsadm

4.测试效果

在一台IP为12.0.0.45的客户机使用浏览器访问 http://12.0.0.1/ ,不断刷新浏览器测试负载均衡效果,刷新间隔需长点(或者关闭Web服务的连接保持)。