Redis_sentinel 哨兵模式

Redis 架构一般是一主多从;Sentinel 一般3组进行相互监控;

    Redis

wget http://download.redis.io/releases/redis-3.2.4.tar.gz

tar -zxvf redis-3.2.4.tar.gz

cd redis

make && make install

cp -rp redis/src/redis-trib.rb /usr/local/bin/

cp -rp redis/src/redis-sentinel /usr/local/bin/

mkdir -p redis/{redis_cluster,data,logs}

yum -y install ruby ruby-devel rubygems rpm-build

gem install redis

    配置 Redis 的主从模式;

Redis - Port 

master 6001

slave  6002/6003

日志目录:logs/redis/{6001,6002,6003}/redis.log

数据目录:data/redis/{6001,6002,6003}

配置目录:

master  — redis.conf  conf/6001/redis.conf

slave  —  redis.conf  conf/6002/redis.conf

slave  —  redis.conf  conf/6003/redis.conf

    Sentinel 配置示例

Sentinel - port 

sentinel 26001

数据目录:data/tmp/26001/

日志目录:logs/sentinel/{6001,6002,6003}/sentinel.log

配置目录:conf/26001/sentinel.conf

    # cat sentinel.conf

port 26001

dir "data/tmp/26001"


sentinel monitor mymaster 10.10.101.100 6001 2

# 监控判定 master 失效;需要 2组 sentinel 同意;


sentinel down-after-milliseconds mymaster 60000

# mymaster 设置未响应时间 SDOWN


sentinel failover-timeout mymaster 180000

# failover切换时间


sentinel parallel-syncs mymaster 1

# 指定最大同时同步新maser配置的salve数量


sentinel auth-pass myMaster 1234 

# 配置密码行


sentinel config-epoch mymaster 0   

# 确认mymater SDOWN时长

sentinel leader-epoch mymaster 2

# 同时一时间最多2个slave可同时更新配置.


指定配置文件进行启动;

    Redis 启动

src/redis-server conf/6001/redis.conf  &> redis/logs/6001/redis.log &

src/redis-server conf/6002/redis.conf  &> redis/logs/6002/redis.log &

src/redis-server conf/6003/redis.conf  &> redis/logs/6003/redis.log &

    Sentinel 哨兵启动 

src/redis-sentinel sentinel/26001/sentinel.conf --sentinel &> redis/logs/26001/sentinel.log &


    测试;

# ./redis-cli -h 10.10.101.100 -p 6001/6002/6003 

    > info 可以查看节点信息;

可以进行尝试切断master 端口测试;Sentinel会根据设置切换时间进行自动故障迁移;