Redis哨兵环境部署

哨兵:

原理:

在主从基础上再加上一个监控实时对服务器状态进行看管。

但主服务器宕机后再次上线则不能再变为主服务器,只能作为从服务器。

配置文件:

[root@rhel7 ~]# vim /etc/redis/sentinel.conf

#内容(只在主服务器上配置)
69行 sentinel monitor mymaster 192.168.110.138 6379 2

开启服务器:

[root@rhel7 ~]# redis-server /etc/redis/redis.conf
[root@redis2 ~]# redis-server /etc/redis/redis.conf
[root@redis3 ~]# redis-server /etc/redis/redis.conf

开启哨兵:

#主上开启:
[root@rhel7 ~]# redis-sentinel /etc/redis/sentinel.conf 

image-20230717150400387

在从上指定主服务器:

[root@redis2 ~]# redis-cli -h 192.168.110.140
192.168.110.140:6379> SLAVEOF 192.168.110.138 6379
OK
192.168.110.141:6379> SLAVEOF 192.168.110.138 6379
OK
主服务器上的变化

image-20230717150653975

在主上设置键:
192.168.110.138:6379> set sent 'send msg'
OK
192.168.110.140:6379> keys *
1) "sent"
2) "words"
192.168.110.141:6379> keys *
1) "words"
2) "sent"

关闭主服务器验证哨兵:

192.168.110.138:6379> SHUTDOWN

image-20230717151924392

192.168.110.140:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.110.141,port=6379,state=online,offset=49987,lag=1
master_replid:ded5e6de69c12d3358b2909153fc5cb4ce68a699
master_replid2:a714d964ddfc4d616b3a3027d4395b28b094bca5
master_repl_offset:50132
second_repl_offset:48487
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:42248
repl_backlog_histlen:7885

我们发现140变为了主服务器,那么哨兵正常工作。

192.168.110.140:6379> set name 140
OK
192.168.110.141:6379> keys *
1) "words"
2) "name"
3) "sent"
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值