简介
Redis高可用方案,保障两台Redis任意节点故障可正常使用。
方案:Redis主从复制+Redis哨兵+Keepalived
环境
系统:Centos/Radhat 7
服务1:Redis 3.2.12
服务2:Keepalived 1.3.5
服务器数量:两台
主:192.168.1.151
备:192.168.1.152
VIP:192.168.1.153
部署
Redis:主从复制+哨兵:https://www.cnblogs.com/xiangsikai/p/11995552.html
安装 Keepalived
1、主备服务器同时安装通过yum安装Keepalived
yum -y install keepalived
配置 Keepalived
1、主:配置Keepalived 配置文件
vim /etc/keepalived/keepalived.conf
global_defs { router_id Redis-HA } vrrp_instance VI_1 { state BACKUP interface eno16777728 virtual_router_id 51 priority 200 advert_int 1 nopreempt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.153 } } virtual_server 192.168.1.153 6379 { delay_loop 2 protocol TCP real_server 192.168.1.151 6379 { notify_down /redis.sh TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
2、备:配置Keepalived配置文件
vim /etc/keepalived/keepalived.conf
global_defs { router_id Redis-HA } vrrp_instance VI_1 { state BACKUP interface eno16777728 virtual_router_id 51 priority 190 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.153 } } virtual_server 192.168.1.153 6379 { delay_loop 2 protocol TCP real_server 192.168.1.150 6379 { notify_down /redis.sh TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
3、主备:创建执行脚本并加入权限
vim /redis.sh
#!/bin/bash pkill keepalived
chmod +x /redis.sh
4、主备:启动Keepalived服务。
注:Redis Master 端优先启动获取VIP
systemctl start keepalived
systemctl enable keepalived
5、查看vip
ip a