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

  

  

Redis Sentinel用法的更多相关文章

  1. Redis Sentinel机制与用法说明【转】

    本文来自:https://segmentfault.com/a/1190000002680804 概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Ma ...

  2. Redis Sentinel机制与用法(一)

    Sentinel spring 集群配置: 概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕 ...

  3. Redis Sentinel机制与用法

    概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都 ...

  4. Redis Sentinel 机制与用法(二)

    概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如 master宕机了,Redis本身(包括它的很多客户端) ...

  5. Redis Sentinel机制与用法说明

    本文来自 https://www.cnblogs.com/zhoujinyi/p/5569462.html 概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Red ...

  6. Redis Sentinel 高可用服务搭建

    阅读目录: 关于 Redis 的概念 关于 Redis Sentinel 的概念 搭建 Redis Server(master) 搭建 Redis Server(slave) 搭建 Redis Sen ...

  7. 【转载】Redis Sentinel 高可用服务架构搭建

    作者:田园里的蟋蟀 出处:http://www.cnblogs.com/xishuai/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接. 阅读 ...

  8. Redis Sentinel哨兵配置

    概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都 ...

  9. Redis|Sentinel 高可用架构

    一 前言 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端 ...

随机推荐

  1. Vim使用taglist功能

    下载 wget http://www.vim.org/scripts/download_script.php?src_id=19574 -O taglist.zip 然后解压taglist.zip到~ ...

  2. Spring Cloud的简单介绍

    参考地址: https://mp.weixin.qq.com/s/wG4CTLORnvemkjUsZ7YP6Q 从一个例子开始 对于这样的"大"问题,通常需要拆解成小问题来回答.要 ...

  3. 转:父类私有变量是否被子类继承详细解说(答案:内存中存在,但sun公司定义为不继承)

    应作者要求,本处提供一个连接,表示对原作者版权尊重. https://blog.csdn.net/mr_duantao/article/details/50966471

  4. js中浅谈this对象(未补充完整)

    什么是this? 1.javascript语言中,一切皆为对象(除了 undefined 和 null 之外),运行环境也是对象,所以函数都是在某个对象之中运行,this就是这个对象(环境). 2.t ...

  5. Cocos2d 之FlyBird开发---GameData类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 现在是大数据的时代,绝大多数的游戏也都离不开游戏数据的控制,简单的就是一般记录游戏的得分情况,高端大气上档次一点的就是记录和保存各方面的游 ...

  6. 超強的Linux指令解釋網站《explainshell.com》,學Linux必備!

    ExplainShell 官方網站:http://explainshell.com/ 原始碼下載:https://github.com/idank/explainshell 用瀏覽器打該explain ...

  7. java虚拟机规范(se8)——class文件格式(六)

    4.7.4 StackMapTable 属性 StackMapTable 属性是一个变长属性,位于 Code(§4.7.3)属性的属性表中.这个属性会在虚拟机类加载的类型阶段(§4.10.1)被使用. ...

  8. C# 与 C++ 互操作(C# 调用 C++ 的动态链接库)

    1.新建 C++ 动态链接库项目 CPlus.cpp: #include "stdafx.h" extern "C" __declspec(dllexport) ...

  9. 小议ArcMap面转线的几种方式

    ArcMap是一个功能丰富的复杂系统,但凡对它有些认知的会同意这个观点. 它的丰富与复杂体现在一个objective有多种implementation,还体现在多种implementation有类似的 ...

  10. js转换成字符串

    有两种方法: 1.对于boolean, number, string类型,可调用toString()方法 2.用String(var)方法 其中,第二种方法使用范围更广,可将没有toString()方 ...