Redis Sentinel用法

Stella981
• 阅读 811

1 Redis Sentinel

1.1 哨兵的作用

  • 1. 监控:监控主从是否正常
  • 2. 通知:出现问题时,可以通知相关人员
  • 3. 故障迁移:自动主从切换
  • 4. 统一的配置管理:连接者询问sentinel取得主从的地址

1.2 搭建redis主从

  •  主redis配置文件

    [root@redis01 conf]# cat /usr/local/redis/conf/redis.conf bind 0.0.0.0 protected-mode no port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile "/var/run/redis_6379.pid" requirepass "abc" masterauth "abc" loglevel notice logfile "" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename "dump.rdb" dir "/usr/local/redis/conf" slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes

    Generated by CONFIG REWRITE

  • 主sentinel配置文件

    [root@redis01 conf]# cat sentinel.conf sentinel monitor mymaster 10.0.0.61 6379 2 sentinel down-after-milliseconds mymaster 15000 sentinel failover-timeout mymaster 80000 sentinel auth-pass mymaster abc bind 10.0.0.61 protected-mode yes daemonize yes logfile "/usr/local/redis/conf/sentinel.log"

1.3 从节点配置 

[root@redis02 conf]# cat redis.conf 
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
cluster-enabled no
cluster-config-file "nodes_6379.conf"
cluster-node-timeout 15000
daemonize yes
supervised no
pidfile "/var/run/redis_6379.pid"
masterauth "abc"
requirepass "abc"
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/usr/local/redis/conf"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
  • sentinel配置  

    [root@redis02 conf]# cat sentinel.conf sentinel monitor mymaster 10.0.0.62 6379 2 #监控主节点 sentinel down-after-milliseconds mymaster 15000
    sentinel failover-timeout mymaster 80000 sentinel auth-pass mymaster abc #密码 bind 10.0.0.62 daemonize yes #后台 protected-mode yes #使用安全 logfile "/usr/local/redis/conf/sentinel.log"

  • 切换日志

    5104:X 03 Feb 22:49:01.306 # +try-failover master mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.308 # +vote-for-leader de08855c7e8920b21ae90cb716280882dd519558 4 5104:X 03 Feb 22:49:01.313 # 18e37e8ca155d107964e8c9cf64f2d15e4729826 voted for de08855c7e8920b21ae90cb716280882dd519558 4 5104:X 03 Feb 22:49:01.364 # +elected-leader master mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.364 # +failover-state-select-slave master mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.431 # +selected-slave slave 10.0.0.62:6379 10.0.0.62 6379 @ mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.431 * +failover-state-send-slaveof-noone slave 10.0.0.62:6379 10.0.0.62 6379 @ mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.508 * +failover-state-wait-promotion slave 10.0.0.62:6379 10.0.0.62 6379 @ mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.512 # +promoted-slave slave 10.0.0.62:6379 10.0.0.62 6379 @ mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.512 # +failover-state-reconf-slaves master mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.599 # +failover-end master mymaster 10.0.0.61 6379 5104:X 03 Feb 22:49:01.599 # +switch-master mymaster 10.0.0.61 6379 10.0.0.62 6379 5104:X 03 Feb 22:49:01.599 * +slave slave 10.0.0.61:6379 10.0.0.61 6379 @ mymaster 10.0.0.62 6379 5104:X 03 Feb 22:49:16.661 # +sdown slave 10.0.0.61:6379 10.0.0.61 6379 @ mymaster 10.0.0.62 6379 5104:signal-handler (1517669370) Received SIGINT scheduling shutdown... 5104:X 03 Feb 22:49:30.193 # User requested shutdown... 5104:X 03 Feb 22:49:30.193 # Sentinel is now ready to exit, bye bye...

  •  重置主从

    [root@redis01 conf]# redis-cli -a abc 127.0.0.1:6379> INFO replication

    Replication

    role:slave master_host:10.0.0.62 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:47568 slave_priority:100 slave_read_only:1 connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0 127.0.0.1:6379> slaveof no one OK [root@redis02 conf]# redis-cli -a abc 127.0.0.1:6379> SLAVEOF 10.0.0.61 6379 OK

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Redis缓存高可用集群
在redis3.0以前的版本要实现集群一般是借助哨兵sentinel工具来监控master节点的状态,如果master节点异常,则会做主从切换,将某一台slave作为master,哨兵的配置略微复杂,并且性能和高可用性等各方面表现一般。
Stella981 Stella981
3年前
Redis 集群演进探讨和总结
Redis为什么需要集群?首先Redis单实例主要有单点,容量有限,流量压力上限的问题。Redis单点故障,可以通过主从复制replication,和自动故障转移sentinel哨兵机制。但Redis单Master实例提供读写服务,仍然有容量和压力问题,因此需要数据分区,构建多个Master实例同时提供读写服务(不仅限于从rep
Stella981 Stella981
3年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Stella981 Stella981
3年前
Nginx + lua +[memcached,redis]
精品案例1、Nginxluamemcached,redis实现网站灰度发布2、分库分表/基于Leaf组件实现的全球唯一ID(非UUID)3、Redis独立数据监控,实现订单超时操作/MQ死信操作SelectPollEpollReactor模型4、分布式任务调试Quartz应用
Stella981 Stella981
3年前
Redis主从模式的常用类型
本文介绍Redis主从模式的常用类型。Redis的可靠性主要有主从模式和集群模式。对于主从模式而言,Redis有以下方案:Sentinel方案;Keepalived方案。Sentinel方案作为Redis主推的官方方案,主要的实现原理是通过引入哨兵sentinel节点,来投标决定master节点故障后,
Stella981 Stella981
3年前
Redis系列
Redis的主从复制模式下,一旦主节点由于故障不能提供服务,需要人工将从节点晋升为主节点,同时还要通知应用方更新主节点地址,对于很多应用场景这种故障处理的方式是无法接受的。可喜的是Redis从2.8开始正式提供了RedisSentinel(哨兵)架构来解决这个问题。总结:Redis主从复制的缺点:没有办法对master进行动态
Stella981 Stella981
3年前
Redis Sentinel 哨兵模式
RedisSentinel哨兵模式Sentinel介绍Redis的主从模式下,主节点一旦发生故障不能提供服务,需要人工干预,将从节点晋升为主节点,同时还需要修改客户端配置。对于很多应用场景这种方式无法接受。Sentinel(哨兵)架构解决了redis主从人工干预的问题。Redis
Stella981 Stella981
3年前
Redis(1.7)Redis高可用架构(理论篇)
【0】常用架构种类  (0.1)单机Redis  (0.2)单纯的Redis主从复制  (0.3)哨兵SentinelRedis主从复制集群(实现高可用自动故障转移)  (0.4)RedisCluster分布式数据库集群  (0.5)第三方中间件Redis主从复制【1】Redis主从复制