高可用HA
HighAvailable
1、 需要心跳机制探测后端RS是否提供服务。
a) 探测down,需要从lvs中删除该RS
b) 探测发送从down到up,需要从lvs中再次添加RS。
2、 Lvs DR,需要主从(HA)
Keepalived : 提供高可用
vrrp协议,实现IP的漂移
Zookeeper:
选举、心跳机制提供接管
Keepalived安装:
至少两台服务器需要安装
Yuminstall keepalived
Keepalived 配置文件
至少两台服务器
1、 地址:/etc/keepalived.conf
2、 帮助手册:man keepalived.conf
3、 编辑之前,需要备份:cp –a keepalived.conf backup. keepalived.conf
4、 编辑:
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]#发送提醒邮件的目标地址可有多个
}
notification_email_from [email protected]#发送邮件的from地址,可以随意写,邮件地址不存在都无所谓
smtp_server 127.0.0.1#邮件服务的地址,一般写本地
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP# MASTER主和从
interface eth0#VIP需要绑定的网卡名称
virtual_router_id 51
priority 101#优先级 主的优先级要高
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.200/24 dev eth0 label eth0:0 #设置VIP
}
}
virtual_server 192.168.1.200 80 {#设置虚拟lvs服务,VIP PORT
delay_loop 6
lb_algo rr#调度算法wrr
lb_kind DR#lvs的模式
nat_mask 255.255.255.0
persistence_timeout 50 同一个IP地址在50秒内lvs转发给同一个后端服务器
protocol TCP
real_server 192.168.1.139 80 {#设置真实服务器的心跳机制 RID PORT
weight 1#权重
HTTP_GET {#心跳检测的方式
url {
path /#心跳检查的地址
status_code 200#心跳检查返回的状态
}
connect_timeout 2 #超时时间
nb_get_retry 3#重复检查3次
delay_before_retry 1#每隔1秒钟再次检查
}
}
real_server 192.168.1.134 80 {#第二个真实服务器设置
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
}
Keepalived的启动和日志
Service keepalived start启动
keepalived 的配置文件配置(keepalived.conf)
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script check_nginx {
script "/home/check_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 199
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.239.100/24 dev eth0 label eth0:1
}
track_script {
check_nginx
}
}