Redis 多主写多从度 配置启动OK ;直接配 keepalived  相关配置;

redis
默认路径 :/usr/local/redis keepalived
默认路径 :/etc/keepalived

检测监控 redis_backup.sh,redis_check.sh,redis_fault.sh redis_master.sh,redis_stop.sh脚本默认 /etc/keepalived/script

实现VIP 地址检测漂移;VRRP 组播地址是必须要通信的 ;

iptables 设置添加 需要开放的端口和地址
224.0.0.18 是vrrp组播地址 ;
iptables -A INPUT -d 224.0.0.18 -j ACCEPT

Master - redis  主节点1  keepalived.conf  配置:

global_defs {
router_id redis1
}
vrrp_script chk_redis
{
script "/etc/keepalived/scripts/redis_check.sh 127.0.0.1 6379"
interval
timeout
fall
} vrrp_instance redis {
state MASTER
interface bond0
virtual_router_id
priority
nopreempt # no seize,must add
advert_int
authentication { #all node must same
auth_type PASS
auth_pass
} virtual_ipaddress {
1.2.3.4/
}
track_script {
chk_redis
} notify_master "/etc/keepalived/scripts/redis_master.sh 127.0.0.1 1.2.3.1 6379"
notify_backup "/etc/keepalived/scripts/redis_backup.sh 127.0.0.1 1.2.3.1 6379"
notify_fault /etc/keepalived/scripts/redis_fault.sh
notify_stop /etc/keepalived/scripts/redis_stop.sh
}

Salve - redis  主节点2  keepalived.conf  配置:

 global_defs {
router_id redis101
} vrrp_script chk_redis
{
script "/etc/keepalived/scripts/redis_check.sh 127.0.0.1 6379"
interval
timeout
fall
} vrrp_instance redis {
state BACKUP
interface bond0
virtual_router_id
priority
advert_int
authentication { #all node must same
auth_type PASS
auth_pass
} virtual_ipaddress {
1.2.3.4/
} track_script {
chk_redis
} notify_master "/etc/keepalived/scripts/redis_master.sh 127.0.0.1 1.2.3.2 6379"
notify_backup "/etc/keepalived/scripts/redis_backup.sh 127.0.0.1 1.2.3.2 6379"
notify_fault /etc/keepalived/scripts/redis_fault.sh
notify_stop /etc/keepalived/scripts/redis_stop.sh
}  

VIP 检测 漂移

redis 备份脚本:

# redis_backup.sh

#!/bin/bash
REDISCLI="/usr/local/redis/src/redis-cli -h $1 -p $3"
LOGFILE="/etc/keepalived/log/keepalived-redis-state.log"
echo "[backup]" >> $LOGFILE
date >> $LOGFILE
echo "Run SLAVEOF cmd ..." >> $LOGFILE
$REDISCLI SLAVEOF $ $ >> $LOGFILE >&
# echo "Being slave...." >> $LOGFILE >&
sleep
#delay s wait data sync exchange role

-----

Redis 检测脚本 :

# redis_check.sh

#!/bin/bash
ALIVE=`/usr/local/redis/src/redis-cli -h $ -p $ PING`
LOGFILE="/etc/keepalived/log/keepalived-redis-check.log"
echo "[CHECK]" >> $LOGFILE
date >> $LOGFILE if [ $ALIVE == "PONG" ]; then :
echo "Success: redis-cli -h $1 -p $2 PING $ALIVE" >> $LOGFILE >&
exit
else
echo "Failed:redis-cli -h $1 -p $2 PING $ALIVE " >> $LOGFILE >&
exit
fi

-----

redis 故障判断脚本:

# redis_fault.sh

#!/bin/bash
LOGFILE=/etc/keepalived/log/keepalived-redis-state.log
echo "[fault]" >> $LOGFILE
date >> $LOGFILE

-----

redis 主节点检测脚本:

# redis_master.sh

#!/bin/bash
REDISCLI="/usr/local/redis/src/redis-cli -h $1 -p $3"
LOGFILE="/etc/keepalived/log/keepalived-redis-state.log"
echo "[master]" >> $LOGFILE
date >> $LOGFILE
echo "Being master...." >> $LOGFILE >&
echo "Run MASTER cmd ..." >> $LOGFILE >&
$REDISCLI SLAVEOF $ $ >> $LOGFILE
sleep
#delay s wait data async cancel sync echo "Run SLAVEOF NO ONE cmd ..." >> $LOGFILE
$REDISCLI SLAVEOF NO ONE >> $LOGFILE >&

  -----

redis 检测停止脚本:

# redis_stop.sh

#!/bin/bash
LOGFILE=/etc/keepalived/log/keepalived-redis-state.log
echo "[stop]" >> $LOGFILE
date >> $LOGFILE

Redis 主从 keepalived高可用 实现 VIP 自动漂移的更多相关文章

  1. Redis+Keepalived高可用方案详细分析

    背景 目前,Redis集群的官方方案还处在开发测试中,未集成到稳定版中.且目前官方开发中的Redis Cluster提供的功能尚不完善(可参考官方网站或http://www.redisdoc.com/ ...

  2. Nginx反向代理,负载均衡,redis session共享,keepalived高可用

    相关知识自行搜索,直接上干货... 使用的资源: nginx主服务器一台,nginx备服务器一台,使用keepalived进行宕机切换. tomcat服务器两台,由nginx进行反向代理和负载均衡,此 ...

  3. (转)基于Redis Sentinel的Redis集群(主从&Sharding)高可用方案

    转载自:http://warm-breeze.iteye.com/blog/2020413 本文主要介绍一种通过Jedis&Sentinel实现Redis集群高可用方案,该方案需要使用Jedi ...

  4. 基于Redis Sentinel的Redis集群(主从Sharding)高可用方案(转)

    本文主要介绍一种通过Jedis&Sentinel实现Redis集群高可用方案,该方案需要使用Jedis2.2.2及以上版本(强制),Redis2.8及以上版本(可选,Sentinel最早出现在 ...

  5. LVS+Keepalived 高可用环境部署记录(主主和主从模式)

    之前的文章介绍了LVS负载均衡-基础知识梳理, 下面记录下LVS+Keepalived高可用环境部署梳理(主主和主从模式)的操作流程: 一.LVS+Keepalived主从热备的高可用环境部署 1)环 ...

  6. 基于Redis Sentinel的Redis集群(主从&Sharding)高可用方案

    本文主要介绍一种通过Jedis&Sentinel实现Redis集群高可用方案,该方案需要使用Jedis2.2.2及以上版本(强制),Redis2.8及以上版本(可选,Sentinel最早出现在 ...

  7. Nginx+keepalived 高可用双机热备(主从模式/双主模式)

    基础介绍负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行. 关于负载均衡介绍,可以参考:li ...

  8. Nginx知多少系列之(十四)Linux下.NET Core项目Nginx+Keepalived高可用(主从模式)

    目录 1.前言 2.安装 3.配置文件详解 4.工作原理 5.Linux下托管.NET Core项目 6.Linux下.NET Core项目负载均衡 7.负载均衡策略 8.加权轮询(round rob ...

  9. nginx keepalived 高可用方案(转)

    转自: https://www.cnblogs.com/leeSmall/p/9356535.html 一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含 ...

随机推荐

  1. chart.js & canvas

    chart.js & canvas https://www.chartjs.org/samples/latest/ https://www.chartjs.org/samples/latest ...

  2. Mysql 乐观锁

    转载:http://chenzhou123520.iteye.com/blog/1863407 乐观锁介绍: 乐观锁( Optimistic Locking ) 相对悲观锁而言,乐观锁假设认为数据一般 ...

  3. unorder_map 自定义KEY

    1. boost::unorder_map 实现自定义KEY // boostLibTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...

  4. BZOJ2173 整数的lqp拆分(生成函数)

    首先有序整数拆分有个显然的递推式是g(n)=Σg(i) (i=0~n-1),即枚举加入最后一个数之前和是多少.(虽然不用递推式也能显然地知道答案是2n-1). 类似地,lqp拆分有递推式f(n)=Σf ...

  5. webservice 测试页面

    转载:http://www.cnblogs.com/JuneZhang/archive/2013/01/24/net.html 解决WebService 测试窗体只能用于来自本地计算机的请求 问题: ...

  6. 有源汇有上下界最小流 DInic + 各种优化 模板

    例题:loj117 : https://loj.ac/problem/117 //其实就是判断可行流后倒着求一遍最大流 #include <iostream> #include <c ...

  7. DP的各种优化(动态规划,决策单调性,斜率优化,带权二分,单调栈,单调队列)

    前缀和优化 当DP过程中需要反复从一个求和式转移的话,可以先把它预处理一下.运算一般都要满足可减性. 比较naive就不展开了. 题目 [Todo]洛谷P2513 [HAOI2009]逆序对数列 [D ...

  8. intent.setFlags方法中的参数值含义

     一. intent.setFlags()方法中的参数值含义: 1.FLAG_ACTIVITY_CLEAR_TOP:例如现在的栈情况为:A B C D .D此时通过intent跳转到B,如果这个int ...

  9. C# try catch语句&获取随机数的方法

    try catch语句: try{ //无论如何都会走,必须写: } catch(Exception a){ //Exception报异常,需要定义,需要写输出语句: //如果上面执行失败走,必须写: ...

  10. centos7配置本地yum源 使用安装镜像安装软件

    1. 在cdrom挂载安装镜像.(物理机则插入光盘,虚拟机则在CD/DVD中选择iso镜像.如果虚拟机mount时提示找不到则在选择iso镜像上方勾选“已连接”和“启动时连接”,或者点击 虚拟机下方状 ...