Redis主从加Sentinel模式部署
总体部署
- 一主二从三哨兵
- ip地址分配分别为
- 主 127.0.0.1:6379
- 从 127.0.0.1:6389
- 从 127.0.0.1:6399
- 哨兵 127.0.0.1:26379
- 哨兵 127.0.0.1:26389
- 哨兵 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模式部署的更多相关文章
- redis主从配置+sentinel哨兵
redis主从配置+sentinel哨兵 1:编译环境准备 1.1环境确认 Redis是一个开源.支持网络.基于内存.键值对存储数据库,使用ANSI C编写.所以在搭建Redis服务器时需要C语言的编 ...
- Redis学习之路(三)之Redis主从和哨兵模式
目录 一.Redis主从配置 1.环境说明 2.修改主从的redis配置文件 3.启动主从redis 3.数据同步验证 二.Redis哨兵模式 1.Redis sentinel介绍 2.Redis S ...
- redis 主从同步&哨兵模式&codis
主从同步 1.CPA原理 1. CPA原理是分布式存储理论的基石: C(一致性): A(可用性): P(分区容忍性); 2. 当主从网络无法连通时,修改操作无法同步到节点,所以“一致性”无法满足 ...
- 【Redis学习专题】- Redis主从+哨兵集群部署
集群版本: redis-4.0.14 集群节点: 节点角色 IP redis-master 10.100.8.21 redis-slave1 10.100.8.22 redis-slave2 10.1 ...
- Redis主从、哨兵模式的搭建
壹.Redis主从分离 准备三个redis配置文件(redis.conf),分别修改为redis6380.conf.redis6381.conf.redis6382.conf 一.配置Master 1 ...
- redis主从配置+哨兵模式
1.搭建redis主从,一个master两个slave,加一个哨兵监听(sentinel),可以新建三个虚拟机,模拟环境,我的电脑没那么多虚拟机,就在一台虚拟机上弄的. 2.安装redis,如果是三台 ...
- Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录
Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...
- 基于 docker 的redis 主从+哨兵(快速部署)
很简单(字多的步骤见:http://www.cnblogs.com/vipzhou/p/8580495.html) 1.直接启动3个容器 docker network create --subnet ...
- spring-data-redis,jedis和redis主从集成和遇到的问题
Redis主从加哨兵的部署详见http://www.cnblogs.com/dupang/p/6414365.html spring-data-redis和jedis集成代码总体结构 代码地址http ...
随机推荐
- JHipster - Generate your Spring Boot + Angular/React applications!
JHipster - Generate your Spring Boot + Angular/React applications!https://www.jhipster.tech/
- PHP + JS 实现大文件分割上传
服务器上传文件会有一定的限制.避免内存消耗过大影响性能,在 php.ini 配置文件中,有几个影响参数: upload_max_filesize = 2M //PHP最大能接受的文件大小 post_m ...
- Angular $interval
<!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...
- CSS 选择器继承和层叠
CSS选择器及其继承特性.层叠特性1.基本选择器 标记 id class 这个就不再作介绍了 2.复合选择器 交集 交集选择器由两个选择器直接连接构成,其结果是选中二者各自元素范围的交集 其 ...
- Java多线程之原子性 volatile、atomicInteger测试
原文链接:http://www.cnblogs.com/zhengbin/p/5653051.html 一.补充概念 1.什么是线程安全性? <Java Concurrency in Pract ...
- Python 零基础 快速入门 趣味教程 (咪博士 海龟绘图 turtle) 5. 参数
上一个教程中,咪博士带大家学习了函数的使用.例如,line_without_moving 函数,可以让海龟先画出一条线段,然后再回来起点. def line_without_moving(): tur ...
- Java之JSON操作(gson)
使用gson包操作JSON数据. 依赖包:gson-2.8.2.jar <dependency> <groupId>com.google.code.gson</group ...
- BZOJ1022[SHOI2008]小约翰的游戏——anti-SG(反尼姆博弈)
题目描述 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取,我们规定取到 ...
- JPQL设置自增长、只读、文本类型等的注解
JAVA中使用JPQL 一种设置id自动生成,自增长的方法 private long id; @Id @GeneratedValue(generator="_native") @G ...
- 实现 60fps 的网易云音乐首页
网易云音乐是一款很优秀的音乐软件,我也是它的忠实用户.最近在研究如何更好的开发TableView,接着我写了一个Model驱动的小框架 - MDTable.为了去验证框架的可用性,我选择了网易云音乐的 ...