部署Redis哨兵,Redis哨兵测试

环境准备

准备3台机器,其中每台机器上都有两个角色,分配如下:

主机名IP:Port角色
aming01192.168.222.128:6379Redis Master
aming02192.168.222.129:6379Redis Slave1
aming03192.168.222.130:6379Redis Slave2
aming01192.168.222.128:26379Sentinel1
aming02192.168.222.129:26379Sentinel2
aming03192.168.222.130:26379Sentinel3

 

部署

安装Redis

步骤略

部署Redis主从

步骤略

部署Sentinel

三台Sentinel配置文件是一样的,编辑配置文件

vi /etc/sentinel.conf #内容如下

# 端口
port 26379

# 是否后台启动
daemonize yes

# pid文件路径
pidfile /var/run/redis-sentinel.pid

# 日志文件路径
logfile "/var/log/sentinel.log"

# 定义工作目录
dir /tmp

# 定义Redis主的别名, IP, 端口,这里的2指的是需要至少2个Sentinel认为主Redis挂了才最终会采取下一步行为
sentinel monitor mymaster 127.0.0.1 6379 2

# 如果mymaster 30秒内没有响应,则认为其主观失效
sentinel down-after-milliseconds mymaster 30000

# 如果master重新选出来后,其它slave节点能同时并行从新master同步数据的台数有多少个,显然该值越大,所有slave节
##点完成同步切换的整体速度越快,但如果此时正好有人在访问这些slave,可能造成读取失败,影响面会更广。最保守的设置
##为1,同一时间,只能有一台干这件事,这样其它slave还能继续服务,但是所有slave全部完成缓存更新同步的进程将变慢。
sentinel parallel-syncs mymaster 1

# 该参数指定一个时间段,在该时间段内没有实现故障转移成功,则会再一次发起故障转移的操作,单位毫秒
sentinel failover-timeout mymaster 180000

# 不允许使用SENTINEL SET设置notification-script和client-reconfig-script。
sentinel deny-scripts-reconfig yes

启动服务

启动顺序:主Redis -> 从Redis -> Sentinel1/2/3

Sentinel 启动命令

redis-sentinel /etc/sentinel.conf 

 

Sentinel操作

  • sentinel master mymaster

    输出被监控的主节点的状态信息

  • sentinel slaves mymaster

    查看mymaster的从信息

  • sentinel sentinels mymaster

    查看其他Sentinel信息

 

测试

停止Redis从

停止Redis主

停止sentinel1

 

客户端连接问题

使用sentinel后,客户端(如,php)如何连Redis呢?

参考:https://blog.51cto.com/chenql/1958910

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值