redis3哨兵配置

linux下安装redis 启动,停止,连接 编辑  删除

http://happyqing.iteye.com/blog/2348255

linux安装redis主备安装配置

http://happyqing.iteye.com/blog/2353516

建议最少配3个哨兵,

如果只有两台服务器,(一个服务器也可装多个redis,端口不同)

主redis服务器,1个哨兵

从redis服务器,2个哨兵

java端配置连接池,连接多个哨兵

http://blog.csdn.net/csolo/article/details/53196293

在一台机器上测试

sentinel26379.conf

#保护模式
protected-mode no

#端口
port 26379

#守护进程
#daemonize yes

#设置pid文件路径
pidfile /opt/redis/sentinel_26379.pid
	
#工作路径,不用改
dir /tmp
	
#设置日志文件路径
#logfile /opt/redis/logs/sentinel26379.log

# 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
# (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
# slaves是自动发现,不用指定slaves。
sentinel monitor mymaster 192.168.2.11 6379 2

# master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
sentinel down-after-milliseconds mymaster 10000

#选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长。
sentinel parallel-syncs mymaster 1

#若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
sentinel failover-timeout mymaster 180000

#设置master和slaves的密码
sentinel auth-pass mymaster redis2016

sentinel26380.conf

#保护模式
protected-mode no

#端口
port 26380

#守护进程
#daemonize yes

#设置pid文件路径
pidfile /opt/redis/sentinel_26380.pid
	
#工作路径,不用改
dir /tmp
	
#设置日志文件路径
#logfile /opt/redis/logs/sentinel26380.log

# 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
# (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
# slaves是自动发现,不用指定slaves。
sentinel monitor mymaster 192.168.2.11 6379 2

# master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
sentinel down-after-milliseconds mymaster 10000

#选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长。
sentinel parallel-syncs mymaster 1

#若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
sentinel failover-timeout mymaster 180000

#设置master和slaves的密码
sentinel auth-pass mymaster redis2016

sentinel26381.conf

#保护模式
protected-mode no

#端口
port 26381

#守护进程
#daemonize yes

#设置pid文件路径
pidfile /opt/redis/sentinel_26381.pid
	
#工作路径,不用改
dir /tmp
	
#设置日志文件路径
#logfile /opt/redis/logs/sentinel26381.log

# 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
# (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
# slaves是自动发现,不用指定slaves。
sentinel monitor mymaster 192.168.2.11 6379 2

# master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
sentinel down-after-milliseconds mymaster 10000

#选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长。
sentinel parallel-syncs mymaster 1

#若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
sentinel failover-timeout mymaster 180000

#设置master和slaves的密码
sentinel auth-pass mymaster redis2016

sentinel monitor mymaster 192.168.2.11 6379 2

这个要配局域网IP,否则远程连不上,

最后的quorum最后配成2,否则容易切换失败

模拟

可以同时结束redis6379,sentinel26379的进程

查看redis6380日志

查看sentinel26380和sentinel26381的日志,

可以看到主从切换的过程

启动

/opt/redis/bin/redis-sentinel /opt/redis/conf/sentinel26379.conf

/opt/redis/bin/redis-sentinel /opt/redis/conf/sentinel26380.conf

/opt/redis/bin/redis-sentinel /opt/redis/conf/sentinel26381.conf

连接

/opt/redis/bin/redis-cli -h 192.168.2.11 -p 26379 -a redis2016

停止

/opt/redis/bin/redis-cli -h 192.168.2.11 -p 26379 -a redis2016 shutdown

发布了67 篇原创文章 · 获赞 11 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/haveqing/article/details/84835858