keepalive介绍
专为LVS和HA设计的一款健康检查工具
支持故障自动切换(Failover)
支持节点健康状态检查(Health Checking)
keepalive工作原理
-
Keepalived可实现多机热备,每个热备组可有多台服务器
-
双机热备的故障切换是由虚拟IP地址的漂移来实现,适用于各种应用服务器
-
实现基于Web服务的双机热备
VRRP
VRRP是针对路由器的一种备份解决方案
由多台路由器组成一个热备组,通过共用的虚拟IP地址对外提供服务
每个热备组内同时只有一台主路由器提供服务,其他路由器处于冗余状态
若当前在线的路由器失效,则其他路由器会根据设置的优先级自动接替虚拟IP地址,继续提供服务
部署LVS+keepalive
环境:
两台调度服务器:
主调度器:真实IP:192.168.1.30
备调度器:真实IP:192.168.1.40
两台节点服务器:
web server1:192.168.1.10
web server2:192.168.1.20
一台NFS共享存储服务器:
地址192.168.1.50
一台客户机
配置主调度器
modprobe ip_vs
yum -y install ipvsadm gcc gcc-c++ make popt-devel kernel-devel openssl-devel
tar -zxvf keepalived-1.4.2.tar.gz
cd keepalived-1.4.2/
./configure --prefix=/
make && make install
cp keepalived/etc/init.d/keepalived /etc/init.d/
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_1
}
vrrp_instance v1
state MASTER
interface ens33
virtual_router_id 1
priority 110
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192。168.1.200
}
}
virtual_server 192.168.1.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 6
protocol TCP
real_server 192.168.1.10 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.20 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
配置备调度器
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_2
}
vrrp_instance v1 {
state BACKUP
interface ens33
virtual_router_id 1
priority 105
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.20.220
}
}
virtual_server 192.168.1.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 6
protocol TCP
real_server 192.168.1.10 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.20 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
配置NFS服务器
yum -y install nfs-utils rpcbind
mkdir web1
mkdir web2
vi /etc/exports
web1 192.168.1.10(ro)
web2 192.168.1.20(ro)
systemctl start nfs
配置web服务器1
yum -y install httpd
mount 192.168.1.50:/web1 /var/www/html
vi dr.sh
#!/bin/bash
ifconfig lo:0 192.168.1.100 broadcast 192.168.1.100 netmask 255.255.255.255 up
route add -host 192.168.1.100 dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p &> /dev/null
sh dr.sh
配置web服务器2
yum -y install httpd
mount 192.168.1.50:/web2 /var/www/html
vi dr.sh
#!/bin/bash
ifconfig lo:0 192.168.1.100 broadcast 192.168.1.100 netmask 255.255.255.255 up
route add -host 192.168.1.100 dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p &> /dev/null
sh dr.sh
结果