总体部署

  • 一主二从三哨兵
  • 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. Linux列举所有隐藏文件

    ll 命令是 ls -l的缩写 ls -a是列举所有(all)文件,包含隐藏文件,以.开头的文件. ls -l是以列表(list)方式列举文件. http://bbs.chinaunix.net/th ...

  2. [转载]linux段页式内存管理技术

    原始博客地址: http://blog.csdn.net/qq_26626709/article/details/52742470 一.概述 1.虚拟地址空间 内存是通过指针寻址的,因而CPU的字长决 ...

  3. Windows系统下PHP使用Redis

    参考链接:https://www.cnblogs.com/lhat/p/6402472.html 环境:windows 10  64位操作系统    php 5.4 redis 3.0 1.redis ...

  4. 使用Hexo搭建Github静态博客

    1. 环境环境 1.1 安装Git 默认配置就好 1.2 安装node.js 下载:http://nodejs.org/download/ 安装时直接保持默认配置即可. 2. 配置Github 1.1 ...

  5. 软件工程_7th weeks

    内聚和耦合(学习笔记) 一.内聚 内聚是一个模块内部各成分之间相关联程度的度量.把内聚按紧密程度从低到高排列次序为: 1.偶然内聚:指一个模块内各成分为完成一组功能而组合在一起,它们相互之间即使有关系 ...

  6. 关于utf8mb4的学习了解笔记

    占位下班写 据说可以存储emoji ..妈蛋今天大神又秀我一脸 大概意思是,我们整个后端数据库,最近都升级了编码格式.从以前久的utf-8整个升级到了utf8mb4的格式 该格式支持emoji表情. ...

  7. hashCode和equal

    转自:https://www.cnblogs.com/dolphin0520/p/3681042.html hashCode方法在Object类中: public native int hashCod ...

  8. jenkins--java配置

    进入jenkins然后-->系统配置-->Global Tool Configuration

  9. Java中的split函数拆分后变成null的问题

    对于一些特殊的情况,split拆分后并没有保留全的元素 如下例子: String x ="a,,,,,,"; String []y = x.split(",") ...

  10. 洛谷P2480 [SDOI2010]古代猪文(费马小定理,卢卡斯定理,中国剩余定理,线性筛)

    洛谷题目传送门 蒟蒻惊叹于一道小小的数论题竟能涉及这么多知识点!不过,掌握了这些知识点,拿下这道题也并非难事. 题意一行就能写下来: 给定\(N,G\),求\(G^{\sum \limits _{d| ...