总体部署

  • 一主二从三哨兵
  • ip地址分配分别为
  1. 主 127.0.0.1:6379
  2. 从 127.0.0.1:6389
  3. 从 127.0.0.1:6399
  4. 哨兵 127.0.0.1:26379
  5. 哨兵 127.0.0.1:26389
  6. 哨兵 127.0.0.1:26399

一主二从的配置文件 redis.conf设置

主的保持默认的不变

二个从的分别打开配置文件

找到设置端口的地方

分别设置为 6389 和6399

# Accept connections on the specified port, default is  (IANA #).
# If port is specified Redis will not listen on a TCP socket.
port
# Accept connections on the specified port, default is  (IANA #).
# If port is specified Redis will not listen on a TCP socket.
port

然后都在

# slaveof <masterip> <masterport>

一行的下面增加

slaveof 127.0.0.1 

这样主从的配置就ok了

三个哨兵的sentinel.conf配置

分别打开sentinel.conf配置文件

修改他们的端口为

26379 26389 26399

sentinel monitor mymaster 127.0.0.1  

配置中的这一行表示 我们要监视的主的ip和端口,mymaster是主的名称,因为我们的主是127.0.0.1:6379,所以三个哨兵中的这个地方都不用修改。

然后所有的配置就ok了,本地测试环境貌似需要改动的地方不多。

启动

进入src目录

./redis-server ../redis.conf

:M  Feb ::12.616 * Increased maximum number of open files to  (it was originally set to ).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 25496
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :M Feb ::12.618 # Server started, Redis version 3.2.
:M Feb ::12.618 * DB loaded from disk: 0.000 seconds
:M Feb ::12.618 * The server is now ready to accept connections on port
:M Feb ::21.196 * Slave 127.0.0.1: asks for synchronization
:M Feb ::21.196 * Full resync requested by slave 127.0.0.1:
:M Feb ::21.196 * Starting BGSAVE for SYNC with target: disk
:M Feb ::21.197 * Background saving started by pid
:C Feb ::21.198 * DB saved on disk
:M Feb ::21.198 * Background saving terminated with success
:M Feb ::21.198 * Synchronization with slave 127.0.0.1: succeeded
:M Feb ::28.979 * Slave 127.0.0.1: asks for synchronization
:M Feb ::28.979 * Full resync requested by slave 127.0.0.1:
:M Feb ::28.979 * Starting BGSAVE for SYNC with target: disk
:M Feb ::28.980 * Background saving started by pid
:C Feb ::28.986 * DB saved on disk
:M Feb ::29.044 * Background saving terminated with success
:M Feb ::29.044 * Synchronization with slave 127.0.0.1: succeeded
  • 从1

进入src目录

./redis-server ../redis.conf

:S  Feb ::21.194 * Increased maximum number of open files to  (it was originally set to ).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 25497
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :S Feb ::21.196 # Server started, Redis version 3.2.
:S Feb ::21.196 * DB loaded from disk: 0.000 seconds
:S Feb ::21.196 * The server is now ready to accept connections on port
:S Feb ::21.196 * Connecting to MASTER 127.0.0.1:
:S Feb ::21.196 * MASTER <-> SLAVE sync started
:S Feb ::21.196 * Non blocking connect for SYNC fired the event.
:S Feb ::21.196 * Master replied to PING, replication can continue...
:S Feb ::21.196 * Partial resynchronization not possible (no cached master)
:S Feb ::21.197 * Full resync from master: b17cd8764974c68bedacb2e5927a04e9ff15f7df:
:S Feb ::21.198 * MASTER <-> SLAVE sync: receiving bytes from master
:S Feb ::21.198 * MASTER <-> SLAVE sync: Flushing old data
:S Feb ::21.198 * MASTER <-> SLAVE sync: Loading DB in memory
:S Feb ::21.199 * MASTER <-> SLAVE sync: Finished with success
  • 从2

进入src目录

./redis-server ../redis.conf

:S  Feb ::28.975 * Increased maximum number of open files to  (it was originally set to ).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 25499
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :S Feb ::28.977 # Server started, Redis version 3.2.
:S Feb ::28.977 * DB loaded from disk: 0.000 seconds
:S Feb ::28.977 * The server is now ready to accept connections on port
:S Feb ::28.979 * Connecting to MASTER 127.0.0.1:
:S Feb ::28.979 * MASTER <-> SLAVE sync started
:S Feb ::28.979 * Non blocking connect for SYNC fired the event.
:S Feb ::28.979 * Master replied to PING, replication can continue...
:S Feb ::28.979 * Partial resynchronization not possible (no cached master)
:S Feb ::28.980 * Full resync from master: b17cd8764974c68bedacb2e5927a04e9ff15f7df:
:S Feb ::29.044 * MASTER <-> SLAVE sync: receiving bytes from master
:S Feb ::29.045 * MASTER <-> SLAVE sync: Flushing old data
:S Feb ::29.045 * MASTER <-> SLAVE sync: Loading DB in memory
:S Feb ::29.045 * MASTER <-> SLAVE sync: Finished with success
  • 哨兵1

进入src目录

./redis-sentinel ../sentinel.conf

:X  Feb ::35.300 * Increased maximum number of open files to  (it was originally set to ).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 25501
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :X Feb ::35.301 # Sentinel ID is 6f3360c06cafe7807e2c1ae00fe7c791354b8b24
:X Feb ::35.301 # +monitor master mymaster 127.0.0.1 quorum
  • 哨兵2和哨兵3启动过程相同

验证

新开一个命令行窗口进入redis的src目录,用redis-cli工具登录其中一个哨兵

./redis-cli -p 

连接成功后运行如下命令

sentinel master mymaster

结果如下

127.0.0.1:> sentinel master mymaster
) "name"
) "mymaster"
) "ip"
) "127.0.0.1"
) "port"
) ""
) "runid"
) "b17cd8764974c68bedacb2e5927a04e9ff15f7df"
) "flags"
) "master"
) "link-pending-commands"
) ""
) "link-refcount"
) ""
) "last-ping-sent"
) ""
) "last-ok-ping-reply"
) ""
) "last-ping-reply"
) ""
) "down-after-milliseconds"
) ""
) "info-refresh"
) ""
) "role-reported"
) "master"
) "role-reported-time"
) ""
) "config-epoch"
) ""
) "num-slaves"
) ""
) "num-other-sentinels"
) ""
) "quorum"
) ""
) "failover-timeout"
) ""
) "parallel-syncs"
) ""

参考

https://redis.io/topics/sentinel

插播个广告


老丈人家的粉皮儿,农产品,没有乱七八糟的添加剂,欢迎惠顾
 

Redis主从加Sentinel模式部署的更多相关文章

  1. redis主从配置+sentinel哨兵

    redis主从配置+sentinel哨兵 1:编译环境准备 1.1环境确认 Redis是一个开源.支持网络.基于内存.键值对存储数据库,使用ANSI C编写.所以在搭建Redis服务器时需要C语言的编 ...

  2. Redis学习之路(三)之Redis主从和哨兵模式

    目录 一.Redis主从配置 1.环境说明 2.修改主从的redis配置文件 3.启动主从redis 3.数据同步验证 二.Redis哨兵模式 1.Redis sentinel介绍 2.Redis S ...

  3. redis 主从同步&哨兵模式&codis

    主从同步 1.CPA原理 1. CPA原理是分布式存储理论的基石: C(一致性):   A(可用性):  P(分区容忍性); 2. 当主从网络无法连通时,修改操作无法同步到节点,所以“一致性”无法满足 ...

  4. 【Redis学习专题】- Redis主从+哨兵集群部署

    集群版本: redis-4.0.14 集群节点: 节点角色 IP redis-master 10.100.8.21 redis-slave1 10.100.8.22 redis-slave2 10.1 ...

  5. Redis主从、哨兵模式的搭建

    壹.Redis主从分离 准备三个redis配置文件(redis.conf),分别修改为redis6380.conf.redis6381.conf.redis6382.conf 一.配置Master 1 ...

  6. redis主从配置+哨兵模式

    1.搭建redis主从,一个master两个slave,加一个哨兵监听(sentinel),可以新建三个虚拟机,模拟环境,我的电脑没那么多虚拟机,就在一台虚拟机上弄的. 2.安装redis,如果是三台 ...

  7. Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录

    Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...

  8. 基于 docker 的redis 主从+哨兵(快速部署)

    很简单(字多的步骤见:http://www.cnblogs.com/vipzhou/p/8580495.html) 1.直接启动3个容器 docker network create --subnet ...

  9. spring-data-redis,jedis和redis主从集成和遇到的问题

    Redis主从加哨兵的部署详见http://www.cnblogs.com/dupang/p/6414365.html spring-data-redis和jedis集成代码总体结构 代码地址http ...

随机推荐

  1. Golang的panic和recover

    panic 关键字panic的作用是制造一次宕机,宕机就代表程序运行终止,但是已经“生效”的延迟函数仍会执行(即已经压入栈的defer延迟函数,panic之前的). 为什么要制造宕机呢?是因为宕机不容 ...

  2. Undertow的InMemorySessionManager

    https://github.com/undertow-io/undertow/blob/master/core/src/main/java/io/undertow/server/session/In ...

  3. Eclipse的Jar包解压出System.js里String与Boolean定义分号可有可无吗?

    Eclipse的Jar包解压出System.js里String与Boolean定义分号可有可无吗? org.eclipse.wst.jsdt.core_1.3.300.v201410221502\li ...

  4. hive 远程管理

  5. 周刷题第一期总结(two sum and two numbers)

    由于深深的知道自己是事件驱动型的人,一直想补强自己的薄弱环节算法,却完全不知道从哪里入手.所以只能采用最笨的办法,刷题.从刷题中遇到问题就解决问题,最后可能多多少少也能提高一下自己的渣算法吧. 暂时的 ...

  6. Delphi2007卸载后无法再安装

    Win7下卸载delphi2007后重新安装问题: 1.Delphi/C++ must be installed first 2.could not access network loacation/ ...

  7. python之发送HTML内容的邮件

    # 发送html内容的邮件 import smtplib, time, os from email.mime.text import MIMEText from email.header import ...

  8. maven 引用另一个jar包 需要先打包在仓库里面 并在pom里面配置 才可以引用

    maven 引用另一个jar包 需要先打包在仓库里面 并在pom里面配置 才可以引用

  9. Flask-sqlacodegen

    ORM操作有两种方式. 1.模型迁移到数据库中生成表,codefirst:使用flask-migrate: 需要flask-script: from flask_script import Manag ...

  10. BZOJ3261最大异或和——主席树

    题目描述 给定一个非负整数序列{a},初始长度为N. 有M个操作,有以下两种操作类型: 1.Ax:添加操作,表示在序列末尾添加一个数x,序列的长度N+1. 2.Qlrx:询问操作,你需要找到一个位置p ...