Keepalived模式LVS高可用群集部署
一、Keepalived模式LVS高可用群集
1. Keepalived
- 支持故障自动切换
- 支持节点健康状态检查
判断LVS负载调度器、节点服务器的可用性,当master主机出现故障及时切换到backup节点保证业务正常,当 master 故障主机恢复后将其重新加入群集并且业务重新切换回 master 节点
2. Keepalived实现原理
二、Keepalived模式LVS高可用集群
实验准备
主机 | 操作系统 | IP地址 | 软件包 |
---|---|---|---|
Director1 | CentOS7 | ens33:192.168.117.10 | ipvsadm、keepalived |
Director2 | CentOS7 | ens33:192.168.117.20 | ipvsadm、keepalived |
NFS-Server | CentOS7 | ens33:192.168.117.30 | rpcbind、nfs-utils |
Web-Server1 | CentOS7 | ens33:192.168.117.40 lo:0 (VIP):192.168.117.100 | rpcbind、nfs-utils、httpd |
Web-Server2 | CentOS7 | ens33:192.168.117.50 lo:0 (VIP):192.168.117.100 | rpcbind、nfs-utils、httpd |
客户机 | CentOS7 | ens33:192.168.117.60 |
1. NFS共享服务器配置
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
yum -y install nfs-utils rpcbind
systemctl start rpcbind.service
systemctl start nfs.service
systemctl enable nfs.service
systemctl enable rpcbind.service
mkdir /opt/qq
mkdir /opt/ww
chmod 777 /opt/qq
chmod 777 /opt/ww
vim /etc/exports
/opt/qq 192.168.117.0/24(rw,sync)
/opt/ww 192.168.117.0/24(rw,sync)
exportfs -rv
2. 配置节点服务器
Web-Server1:192.168.117.40 lo:0 (VIP):192.168.117.100
Web-Server2:192.168.117.50 lo:0 (VIP):192.168.117.100
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
2.1 配置虚拟IP地址
VIP:192.168.117.100
vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.117.100
NETMASK=255.255.255.255
ONBOOT=yes
ifup lo:0
ifconfig lo:0
#设置临时的路由,重启失效
route add -host 192.168.117.100 dev lo:0
#开机自动添加路由
vim /etc/rc.local
/sbin/route add -host 192.168.117.100 dev lo:0
chmod +x /etc/rc.d/rc.local
2.2 调整内核ARP响应参数
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 install -y nfs-utils rpcbind httpd
systemctl start rpcbind
systemctl enable rpcbind
systemctl start httpd.service
systemctl enable httpd.service
2.3 编辑网页内容
Web-Server1:192.168.117.40 lo:0 (VIP):192.168.117.100
showmount -e 192.168.117.30
mount.nfs 192.168.117.30:/opt/qq /var/www/html
df -hT
echo 'this is qq web!' > /var/www/html/index.html
Web-Server2:192.168.117.50 lo:0 (VIP):192.168.117.100
showmount -e 192.168.117.30
mount.nfs 192.168.117.30:/opt/ww /var/www/html
df -hT
echo 'this is ww web!' > /var/www/html/index.html
同Web-Server1配置,不放图了
3. 配置负载调度器
Director1:192.168.117.10
Director2:192.168.117.20
systemctl stop firewalld.service
setenforce 0
yum -y install ipvsadm keepalived
modprobe ip_vs
cat /proc/net/ip_vs
vim /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
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm
ipvsadm -C
ipvsadm -A -t 192.168.117.100:80 -s rr
ipvsadm -a -t 192.168.117.100:80 -r 192.168.117.40:80 -g
ipvsadm -a -t 192.168.117.100:80 -r 192.168.117.50:80 -g
ipvsadm
ipvsadm -ln
注:上图指定的IP地址应为VIP,即:192.168.117.100,两台Web服务器配置相同
Director1:192.168.117.10
Director2:192.168.117.20
配置keeplived
Director1:192.168.117.10
Director2:192.168.117.20
yum -y install keepalived
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vim keepalived.conf
4. 验证
客户机访问:192.168.117.100
关闭主调度器keepalived服务
Director1:192.168.117.10
systemctl stop keepalived
Director2:192.168.117.20
客户机依然可以访问