集群配置

  1. 新增从库
redis-server --port 6380 --slaveof 127.0.0.1 6379
  1. 配置哨兵
  • 新增哨兵配置文件sentinel.conf:
sentinel monitor master-name ip redis-port quorum
例如:sentinel monitor mymaster 127.0.0.1 6379 1
  • redis-sentinel /path/to/sentinel.conf
  1. 停止redis服务:redis-cli -h 127.0.0.1 -p 6379 shutdown //停止服务
  2. 每个哨兵会与主库建立2个连接,与每个从库也会建立2个连接,(哨兵与哨兵之间只建一个连接用于发送PING命令)
    1. 一个连接用于获取主库信息
    2. 一个连接用于订阅主库_sentinel_:hello频道,以获取其他哨兵信息
  3. 哨兵与主库连接后,定时执行3个操作:
    1. 每10秒(配置)向主、从库发送INFO命令
    2. 每2秒(配置)向主、从的_sentinel_:hello频道发送自己的信息,消息内容:<哨兵地址> <哨兵端口> <哨兵运行的ID> <哨兵配置版本> <主库名称> <主库地址> <主库端口> <主库配置版本>
    3. 每1秒向主、从、其他
    4. 哨兵节点发送PING命令
  4. 主库故障恢复流程:

redis恢复流

程.vsdx

33.87KB
 
  1. 启动集群命令
redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384
  1. 集群共有16384个插槽
  2. 迁移插槽,需要手动迁移插槽中的数据
MIGRATE 目标IP 目标端口 key 数据库号码 超时时间 COPY REPLACE
 
 
posted @ 2019-03-07 17:51  教主陈  阅读(144)  评论(0编辑  收藏  举报