目录
一、配置负载调度器
1.配置虚拟 IP 地址(VIP:192.168.146.180)
2.调整 proc 响应参数
3. 配置负载分配策略
编辑二、部署共享存储(NFS服务器:192.168.146.20)
三、配置节点服务器
1.配置虚拟 IP 地址
2.调整内核的 ARP 响应参数以阻止更新 VIP 的 MAC 地址,避免发生冲突
3.另一台同理
四、测试 LVS 群集
systemctl stop firewalld.service
setenforce 0
modprobe ip_vs
cat /proc/net/ip_vs
yum -y install ipvsadm
cd /etc/sysconfig/network-scripts/
cp ifcfg-ens33 ifcfg-ens33:0
vim ifcfg-ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.10.180
NETMASK=255.255.255.25
由于 LVS 负载调度器和各节点需要共用 VIP 地址,需要关闭 icmp 的重定向,不充当路由器
vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm
ipvsadm -C
ipvsadm -A -t 192.168.10.180:80 -s rr
ipvsadm -a -t 192.168.10.180:80 -r 192.168.10.16:80 -g
ipvsadm -a -t 192.168.10.180:80 -r 192.168.10.17:80 -g
ipvsadm
ipvsadm -ln
systemctl stop firewalld.service
setenforce 0
yum -y install nfs-utils rpcbind
mkdir /opt/kgc /opt/benet
chmod 777 /opt/kgc /opt/benet
vim /etc/exports
/usr/share *(ro,sync)
/opt/kgc 192.168.10.0/24(rw,sync)
/opt/benet 192.168.10.0/24(rw,sync)
systemctl start nfs.service
systemctl start rpcbind.service
systemctl stop firewalld.service
setenforce 0
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
DEVICE=lo:0
ONBOOT=yes
IPADDR=192.168.10.180
NETMASK=255.255.255.255
ifup lo:0
ifconfig lo:0
route add -host 192.168.146.180 dev lo:0
vim /etc/rc.local
/sbin/route add -host 192.168.146.180 dev lo:0
chmod +x /etc/rc.d/rc.local
vim /etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
sysctl -p
yum -y install nfs-utils rpcbind httpd
systemctl start rpcbind
systemctl start httpd
mount.nfs 192.168.146.20:/opt/kgc /var/www/html
echo 'this is kgc web!' > /var/www/html/index.html
在客户端使用浏览器访问 http://192.168.146.180