部署LVS-NAT群集

目录

一、设备准备

二、数据流向

三、部署LVS-NAT群集

1、部署共享存储NFS(192.168.62.5)

 2、配置节点服务器(web01 和 web02)

3、配置LVS负载调度器

 4、客户端配置(测试)


一、设备准备

NFS服务器:192.168.62.5

web01:192.168.62.40

web02:192.168.62.50

LVS:(内网)192.168.62.10 (外网)192.168.88.10

二、数据流向

 

 

三、部署LVS-NAT群集

1、部署共享存储NFS(192.168.62.5)

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

安装nfs服务和rpcbind服务

yum -y install ngs-utils rpcbind
systemctl start nfs
systemctl start rpcbind
systemctl enable nfs.service
systemctl enable rpcbind.service

创建共享目录,并设置权限

mkdir /opt/zb /opt/lc
chmod 777 /opt/zb /opt/lc

输入网页内容

echo "this is web01" > /opt/web01/index.html
echo "this is web02" > /opt/web02/index.html

设置共享目录

vim /etc/exports
rw:该主机对该共享目录有读写权限
sync:资料同步写入到内存与硬盘中

ro	              该主机对该共享目录有只读权限
rw	              该主机对该共享目录有读写权限
root_squash	      客户机用root用户访问该共享文件夹时,将root用户映射成匿名用户
no_root_squash	  客户机用root访问该共享文件夹时,不映射root用户
all_squash	      客户机上的任何用户访问该共享目录时都映射成匿名用户
anonuid	          将客户机上的用户映射成指定的本地用户ID的用户
anongid	          将客户机上的用户映射成属于指定的本地用户组ID
sync	          资料同步写入到内存与硬盘中
async	          资料会先暂存于内存中,而非直接写入硬盘
insecure	      允许从这台机器过来的非授权访问

启动服务,查看共享

systemctl start rpcbind
systemctl start nfs
showmount -e localhost     #查看共享

 

 2、配置节点服务器(web01 和 web02)

两台节点安装nfs、rpcbind和httpd服务,然后启动服务

yum -y install nfs-utils rpcbind httpd
systemctl start nfs
systemctl start rpcbind
systemctl start httpd

查看共享目录 

showmount -e 192.168.62.5

挂载共享目录

web01

mount.nfs 192.168.62.5:/opt/web01 /var/www/html/

web02

mount.nfs 192.168.62.5:/opt/web02 /var/www/html/

修改网卡

更改web01和web02服务器的网关,指向LVS的内网网卡,并重启网卡

web01

vim /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network

web02

vim /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network

 

 

3、配置LVS负载调度器

(内网卡:192.168.62.10 外网卡:192.168.88.10)

开启路由转发功能

 

配置SNAT转发规则

yum -y install iptables     #下载iptables防火墙
iptables -F     #清空防火墙规则
iptables -t nat -F    #清空nat表中的路由规则
iptables -t nat -A POSTROUTING -s 192.168.62.0/24 -o ens37 -j SNAT --to-source 192.168.88.10

查看nat表中规则

加载lvs内核模块

modprobe ip_vs     #加载ip_vs模块
cat /proc/net/ip_vs    #查看ip_vs版本信息

安装ipvsadm管理工具

yum -y install ipvsadm

启动前要保存负载分配策略

ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm

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

修改外网、内网的网卡

vim /etc/sysconfig/network-scripts/ifcfg-ens33

systemctl restart network    #重启网卡

 4、客户端配置(测试)

在一台IP为192.168.88.20的客户机使用浏览器访问192.168.88.10,不断刷新浏览器测试负载均衡效果,刷新间隔需长点。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值