总体部署

  • 一主二从三哨兵
  • 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 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6389
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6399

然后都在

# slaveof <masterip> <masterport>

一行的下面增加

slaveof 127.0.0.1 6379

这样主从的配置就ok了

三个哨兵的sentinel.conf配置

分别打开sentinel.conf配置文件

修改他们的端口为

26379 26389 26399

sentinel monitor mymaster 127.0.0.1 6379 2

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

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

启动

进入src目录

./redis-server ../redis.conf

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

进入src目录

./redis-server ../redis.conf

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

进入src目录

./redis-server ../redis.conf

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

进入src目录

./redis-sentinel ../sentinel.conf

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

验证

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

./redis-cli -p 26379

连接成功后运行如下命令

sentinel master mymaster

结果如下

127.0.0.1:26379> sentinel master mymaster
1) "name"
2) "mymaster"
3) "ip"
4) "127.0.0.1"
5) "port"
6) "6379"
7) "runid"
8) "b17cd8764974c68bedacb2e5927a04e9ff15f7df"
9) "flags"
10) "master"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "703"
19) "last-ping-reply"
20) "703"
21) "down-after-milliseconds"
22) "30000"
23) "info-refresh"
24) "1090"
25) "role-reported"
26) "master"
27) "role-reported-time"
28) "3253725"
29) "config-epoch"
30) "0"
31) "num-slaves"
32) "2"
33) "num-other-sentinels"
34) "2"
35) "quorum"
36) "2"
37) "failover-timeout"
38) "180000"
39) "parallel-syncs"
40) "1"

redis 一主二从三哨兵的更多相关文章

  1. docker-compose一键部署redis一主二从三哨兵模式(含密码,数据持久化)

    本篇基于centos7服务器进行部署开发 一.拉取redis镜像,使用如下命令 docker pull redis 1.查看镜像是否拉取成功,使用如下命令 docker images 显示如下则证明拉 ...

  2. springboot 集成Redis一主二从三哨兵

    1.Centos7 Redis一主二从三哨兵配置 Redis一主二从三哨兵环境搭建 2.接入过程 与集成redis单机不同的是jedis相关的配置做了修改,JedisPool换成了JedisSenti ...

  3. redis一主二从三哨兵

    redis做集群的时候有很多种配置方法,一主二从三哨兵这种模式是官网推荐的.,写配置文件链接的时候,写的是哨兵地址,不是IP,用户名,密码之类的. 一主二从很好理解,一个主的redis,实时备份到两个 ...

  4. Docker Compose搭建Redis一主二从三哨兵高可用集群

    一.Docker Compose介绍 https://docs.docker.com/compose/ Docker官方的网站是这样介绍Docker Compose的: Compose是用于定义和运行 ...

  5. redis环境搭建及一主二从三哨兵模式配置

    一.单机redis环境搭建 1.安装: OS:linux redhat6.5 下载redis 官网下载链接:https://redis.io/download 把安装包上传到服务器,进行解压 [roo ...

  6. docker compose搭建redis7.0.4高可用一主二从三哨兵集群并整合SpringBoot【图文完整版】

    一.前言 redis在我们企业级开发中是很常见的,但是单个redis不能保证我们的稳定使用,所以我们要建立一个集群. redis有两种高可用的方案: High availability with Re ...

  7. 实践 - 搭建Redis一主两从三哨兵

    实践 - 搭建Redis一主两从三哨兵 原因: 最近在复习Redis的时候,学习到了为了提高Redis集群的高可用性,有一个模式为哨兵模式.哨兵模式的作用是为了在主节点出现阻塞或者错误,无法接收数据的 ...

  8. redis一主二从加哨兵

    redis版本:redis-3.0.6.tar.gz master:192.168.3.180 slave:192.168.3.184 (机器原因,两从都在这上面) 一.redis安装 cd /roo ...

  9. Docker搭建Redis一主两从三哨兵

    作者:oscarwin juejin.im/post/5d26b03de51d454fa33b1960 这次实验准备了三台云主机,系统为Debian,ip分别为:35.236.172.131 ,35. ...

随机推荐

  1. 读《移山之道——VSTS软件开发指南》

    读<移山之道>这本书差不多用了一个星期的时间,感觉还是收获了一些知识的,以前只是会简单地编个小程序(虽然现在也是这样),但看过这本书之后我对软件开发这个概念的认识度有了从一片模糊到了解大体 ...

  2. Linux实践三:程序破解

    一.汇编指令机器码 二.反汇编与十六进制编程器 三.可执行文件的基本格式 hexdump -x login 用16进制数字显示login内容 objdump -x login 显示login中各个段以 ...

  3. LINUX内核分析第八周学习总结

    LINUX内核分析第八周学习总结 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.c ...

  4. 基于UML的需求分析和系统设计

    小序: 从学生时代就接触到UML,几年的工作中也没少使用,各种图形的概念.图形的元素和属性,以及图形的画法都不能说不熟悉.但是怎样在实际中有效地使用UML使之发挥应有的作用,怎样捕捉用户心中的需求并转 ...

  5. Github知识小结

    软件:计算机运行所需要的各种程序和数据的总成,包括操作系统,汇编语言,编译,程序,数据库,文字编辑和维护使用手册等. 软件的特性:(1)软件产品的主要生产是脑力劳动,还没有摆脱手工开发方式(2)软件是 ...

  6. opencv学习笔记(三)

    imread()读入图,第一个参数,const string&类型的filename,填我们需要载入的图片路径名, 第二个参数,int类型的flags,为载入标识,它指定一个加载图像的颜色类型 ...

  7. Sonatype Nexus 2.11.1-01 使用入门

    nexus安装与启动 linux下: 安装路径 /home/maven/nexus-2.11.1-01/ 启动方法 ./bin/nexus start windows下: 管理员模式运行cmd.exe ...

  8. 自定义Label控件

    最近开发过程中有一个需求就是修改label控件的模板,使其能够在鼠标移近的时候变成TextBox,从而方便输入,然后进行相应的修改,最终达到动态修改Label的目的,这里贴出相应的代码,并做简要的分析 ...

  9. chapter4 module and port

    如果模块和外界没有交换信号,则可以没有端口列表. 端口隐含声明为wire,如果输出端口需要保存数值,则必须显式声明为reg,如需要保持数值知道下一个时钟边沿

  10. 【长期更新】 PHP题目

    1.要求在一组数中,插入一个新数,并维护原来的排序方式不变 <?php //1.要求在一组数中,插入一个新数,并维护原来的排序方式不变 function insertArr($arr,$val) ...