LVS-NAT模式群集部署
LVS调度器作为Web 服务器池的网关,LVS具有两块网卡,分别连接内外网,使用轮询(rr)调度算法
1.配置负载调度器LVS(ens33:192.168.10.11 ens37:12.0.0.1)
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
配置SNAT转发规则
vim /etc/sysctl.conf
net.ipv4.ip_forward=1
sysctl -p
iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o ens37 -j SNAT --to-source 12.0.0.1
【nat表:修改数据包中的源、目标IP地址或端口
POSTROUTING: 在进行路由判断之"后"所要进行的规则(SNAT/MASQUERADE)
PREROUTING: 在进行路由判断之"前"所要进行的规则(DNAT/REDIRECT)
-A: 在规则链的末尾加入新规则
-s: 匹配来源地址IP/MASK.
-o 网卡名称匹配从这块网卡流出的数据
-i 网卡名称匹配从这块网卡流入的数据
-j 控制类型】
加载LVS内核模块
modprobe ip_vs #手动加载ip_vs模块
cat /proc/net/ip_vs #查看ip_vs版本信息
安装ipvsadm管理工具
yum install -y ipvsadm
注意:启动服务前必须保存负载分配策略,否则将会报错
ipvsadm-save > /etc/sysconfig/ipvsadm
或者
ipvsadm --save > /etc/sysconfig/ipvsadm
或者
touch /etc/sysconfig/ipvsadm
systemctl start ipvsadm.service
2.配置节点服务器
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
#修改网卡网关为LVS服务器
yum install -y httpd
systemctl start httpd.service
systemctl enable httpd.service
yum install -y nfs-utils rpcbind
systemctl start rpcbind.service
systemctl enable rpcbind.service
showmount -e 192.168.10.128
web1:192.168.10.128
mount.nfs 192.168.10.128:/opt/test1 /var/www/html/
echo 'this is test1 web' > /var/www/html/index.html
web2:192.168.10.13
mount.nfs 192.168.10.128:/opt/benet /var/www/html/
echo 'this is test2 web' > /var/www/html/index.html
3.部署共享存储(NFS服务器:192.168.10.128)
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
yum install -y nfs-utils rpcbind
systemctl start nfs.service
systemctl start rpcbind.service
systemctl enable nfs.service
systemctl enable rpcbind.service
mkdir /opt/test1 /opt/test2
chmod 777 /opt/test1 /opt/test2/
vim /etc/exports
/opt/test1 192.168.10.0/24(rw,sync,no_squash_root)
/opt/test2 192.168.10.0/24(rw,sync,no_squash_root)
#发布共享
exportfs -rv
showmount -e
标签:opt,LVS,service,群集,ipvsadm,192.168,systemctl,NAT
From: https://www.cnblogs.com/y0226/p/16899881.html