案列:LVS-DR 负载均衡集群搭建

一台调度器: VM1:192.168.100.114
二台WEB服务器集群池: 192.168.100.85、192.168.100.87
一台NFS共享服务器: 192.168.100.86

一、在调度器配置:192.168.100.114##

【1】配置虚拟IP地址(VIP)
cd /etc/sysconfig/network-scripts/
cp ifcfg-ens33 ifcfg-ens33:0
vi ifcfg-ens33:0 #配置文件中修改成下面内容

NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.255

ifup ifcfg-ens33:0
systemctl restart network
ifconfig #可以看看有没有生成ens33:0的IP地址
2】调整/proc响应参数 对于 DR 群集模式来说,由于 LVS 负载调度器和各节点需要共用 VIP 地址,应该关闭 Linux 内核的重定向参数响应服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能
vi /etc/sysctl.conf

net.ipv4.conf.all.send_redirects = 0 ##新增
net.ipv4.conf.default.send_redirects = 0 ##新增
net.ipv4.conf.ens33.send_redirects = 0 ##新增

sysctl -p ###生效
[[email protected] network-scripts]# sysctl -p
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
【3】配置负载分配策略
cd
ipvsadm -v
modprobe ip_vs
cat /proc/net/ip_vs
yum -y install ipvsadm
ipvsadm -A -t 192.168.100.10:80 -s rr

ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.85:80 -g -w 1
ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.87:80 -g -w 1

cd /etc/sysconfig/network-scripts/
systemctl enable ipvsadm
ipvsadm-save > /opt/ipvsadm
ipvsadm --save > /etc/sysconfig/ipvsadm
systemctl restart ipvsadm #若还是出错用下面的开启
systemctl start ipvsadm
systemctl status ipvsadm

二、存储服务器上配置####

rpm -q nfs-utils
yum -y install nfs-utils
rpm -q rpcbind
yum -y install rpcbind

systemctl start rpcbind
systemctl start nfs

vi /etc/exports
/opt/51xit 192.168.100.0/24 (rw,sync)
/opt/52xit 192.168.100.0/24 (rw,sync)

systemctl restart rpcbind
systemctl restart nfs
systemctl enable nfs
systemctl enable rpcbind

mkdir /opt/51xit /opt/52xit
echo “this is 51xit” >/opt/51xit/index.html
echo “this is 52xit” >/opt/52xit/index.html

三、配置节点服务器:192.168.100.85####

【1】先添加lo:0的IP的地址
cd /etc/sysconfig/network-scripts/
cp ifcfg-ens33 ifcfg-lo:0
vi ifcfg-lo:0 ##修改成下面的内容

DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes

ifup lo:0
ifconfig

vi /etc/rc.local
/sbin/route add -host 192.168.100.10 dev lo:0

【2】调整/proc响应参数
vi /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

sysctl -p

【2】安装httpd 挂载测试页
cd
showmount -e 192.168.100.86
######如果还没发布,请到存储服务器发布下,exportfs -rv
yum -y install httpd
mount 192.168.100.86:/opt/51xit /var/www/html/
vi /etc/fstab
192.168.100.86:/opt/51xit/ /var/www/html/ nfs defaults_netdev 0 0

systemctl start httpd
systemctl enable httpd

登录192.168.100.85测试网站是否正常#

四、配置节点服务器:192.168.100.87####

【1】配置虚拟IP地址
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
vi ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes

ifup lo:0

vi /etc/rc.local
/sbin/route add -host 192.168.100.10 dev lo:0

vi /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

sysctl -p
【2】安装httpd 挂载测试页
showmount -e 192.168.100.86
###如果还没发布,请到存储服务器发布下,exportfs -rv
yum -y install httpd
mount 192.168.100.86:/opt/52xit /var/www/html/
vi /etc/fstab
192.168.100.86:/opt/52xit/ /var/www/html/ nfs rw,tcp,intr 0 1

cd
systemctl start httpd
systemctl enable httpd

#######测试网站 ######
192.168.100.10

问题1:#RPC–注册问题###
[[email protected] ~]# showmount -e
clnt_create: RPC: Program not registered

解决方案:
[[email protected] ~]# systemctl stop nfs
[[email protected] ~]# systemctl stop rpcbind
[[email protected] ~]# systemctl start rpcbind ###再次启动
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# showmount -e
Export list for localhost.localdomain:
/opt/52xit 20.0.0.0/24
/opt/51xit 20.0.0.0/24

问题2:##问题: /etc/sysconfig/ipvsadm: No such …ry####
解决方案:ipvsadm --save > /etc/sysconfig/ipvsadm
[[email protected] opt]# systemctl status ipvsadm.service ###查看ipvsadm是否工作正常
● ipvsadm.service - Initialise the Linux Virtual Server
Loaded: loaded (/usr/lib/systemd/system/ipvsadm.service; enabled; vendor preset: disabled)
Active: active (exited) since Mon 2020-09-21 23:47:17 EDT; 19min ago
Process: 18092 ExecStart=/bin/bash -c exec /sbin/ipvsadm-restore < /etc/sysconfig/ipvsadm (code=exited, status=0/SUCCESS)
Main PID: 18092 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/ipvsadm.service

问题三:##问题:TCP 127.0.0.1:80 rr ###添加虚拟服务器数据异常

[[email protected] ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 127.0.0.1:80 rr ###添加虚拟服务器数据异常
-> 192.168.100.85:80 Route 1 0 0
-> 192.168.100.87:80 Route 1 0 0

###如何解决,清空重新添加###
ipvsadm -C
ipvsadm -A -t 192.168.100.10:80 -s rr
ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.85:80 -g -w 1
ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.87:80 -g -w 1
ipvsadm --save > /etc/sysconfig/ipvsadm

实验结果是:为了证明使用VIP地址上去看网页的时候能看到 轮询的情况
在这里插入图片描述

常用命令
添加一个集群服务
ipvsadm -A -t 192.168.100.10:80 -s rr
ipvsadm -ln 查看
修改集群服务的调度算法。
ipvsadm -E -t 192.168.1.100:80 -s wlc
ipvsadm -ln
删除一个集群服务
ipvsadm -D -t 192.168.1.100:80
ipvsadm -ln
删除所有的集群
ipvsadm -C

往集群服务中添加一个真实服务器
ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.85:80 -m -w 1

修改集群服务中的一个真实服务器的权重值。
ipvsadm -e -t 192.168.1.100:80 -r 172.16.16.2:80 -m -w 2

删除集群服务中的一个真实服务器
ipvsadm -d -t 192.168.1.100:80 -r 172.16.16.2:80
清空转发请求计时器
ipvsadm -Z

猜你喜欢

转载自blog.csdn.net/Laiyunpeng666/article/details/108740014