redis(4) 集群

Mac brew
ls /usr/local/
Caskroom Homebrew etc lib remotedesktop share
Cellar bin include opt sbin var
cd /usr/local/Cellar/redis/5.0.0/bin
ls /usr/local/etc/
bash_completion.d mongod.conf openssl redis.conf
gitconfig my.cnf redis-sentinel.conf wgetrc

集群分类
主从复制 Replication
高可用 Sentinel
集群 Cluster
分布式 twemproxy

类似 mysql 主从结构:master -> binlog -> slave (写操作重演)/ mysql 允许多级主从结构
http://www.cnblogs.com/Aiapple/p/5792939.html
主从数据同步 -> 延时 -> 多级结构 -> 。。。

redis -> 只支持两级结构

**读操作分流

redis(4) 集群_第1张图片
image.png
redis(4) 集群_第2张图片
image.png

主从复制创建
redis-server --slaveof
配置当前服务称为某Redis服务的Slave
redis-server --port 6380 --slaveof 127.0.0.1 6379

SLAVEOF host port 命令,将当前服务器状态从Master修改为别的服务器的Slave
redis > SLAVEOF 192.168.1.1 6379 / -> slave
redis > SLAVEOF NO ONE / -> master 不会丢弃已同步数据

配置方式:启动时,服务器读取配置文件,并自动成为指定服务器的从服务器。
slaveof
slaveof 127.0.0.1 6379

指定配置文件,启动多个实例(redisd),则相同端口 -> 多个配置文件
端口冲突?? -> 6379 监听端口 instead of ...

$ redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory

Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --replicaof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel

$ redis-server --port 6379 &
[1] 2640
2640:C 23 Nov 2018 17:50:23.657 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2640:C 23 Nov 2018 17:50:23.657 # Redis version=5.0.0, bits=64, commit=00000000, modified=0, pid=2640, just started
2640:C 23 Nov 2018 17:50:23.657 # Configuration loaded
2640:M 23 Nov 2018 17:50:23.658 * Increased maximum number of open files to 10032 (it was originally set to 4864).
.
.-__ ''-._ _.- .. ''-._ Redis 5.0.0 (00000000/0) 64 bit
.-.-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.-.|'_.-'| Port: 6379 |-. ._ / _.-' | PID: 2640-._ -._-./ .-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' | http://redis.io-._ -._-..-'.-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' |-._ -._-..-'.-' .-'
-._-.
.-' .-'
-._ _.-'-.
_.-'

2640:M 23 Nov 2018 17:50:23.662 # Server initialized
2640:M 23 Nov 2018 17:50:23.662 * DB loaded from disk: 0.000 seconds
2640:M 23 Nov 2018 17:50:23.662 * Ready to accept connections
/
$ redis-server --port 6380 --slaveof 127.0.0.1 6379
2860:C 23 Nov 2018 17:55:24.452 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2860:C 23 Nov 2018 17:55:24.453 # Redis version=5.0.0, bits=64, commit=00000000, modified=0, pid=2860, just started
2860:C 23 Nov 2018 17:55:24.453 # Configuration loaded
2860:S 23 Nov 2018 17:55:24.454 * Increased maximum number of open files to 10032 (it was originally set to 4864).
.
.-__ ''-._ _.- .. ''-._ Redis 5.0.0 (00000000/0) 64 bit
.-.-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.-.|'_.-'| Port: 6380 |-. ._ / _.-' | PID: 2860-._ -._-./ .-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' | http://redis.io-._ -._-..-'.-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' |-._ -._-..-'.-' .-'
-._-.
.-' .-'
-._ _.-'-.
_.-'

2860:S 23 Nov 2018 17:55:24.455 # Server initialized
2860:S 23 Nov 2018 17:55:24.455 * DB loaded from disk: 0.000 seconds
2860:S 23 Nov 2018 17:55:24.455 * Before turning into a replica, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
2860:S 23 Nov 2018 17:55:24.455 * Ready to accept connections
2860:S 23 Nov 2018 17:55:24.455 * Connecting to MASTER 127.0.0.1:6379
2860:S 23 Nov 2018 17:55:24.455 * MASTER <-> REPLICA sync started
2860:S 23 Nov 2018 17:55:24.455 * Non blocking connect for SYNC fired the event.
2860:S 23 Nov 2018 17:55:24.455 * Master replied to PING, replication can continue...
2860:S 23 Nov 2018 17:55:24.456 * Trying a partial resynchronization (request a6137c80b386195f28fb8a0a3fd8eda291d2517e:1).
2640:M 23 Nov 2018 17:55:24.456 * Replica 127.0.0.1:6380 asks for synchronization
2640:M 23 Nov 2018 17:55:24.456 * Partial resynchronization request from 127.0.0.1:6380 accepted. Sending 70 bytes of backlog starting from offset 1.
2860:S 23 Nov 2018 17:55:24.456 * Successful partial resynchronization with master.
2860:S 23 Nov 2018 17:55:24.456 * MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization.
/
Connecting to MASTER 127.0.0.1:8888
MASTER <-> SLAVE sync started
Non blocking connect for SYNC fired the event.
Master replied to PING, replication can continue...
Partial resynchronization not possible (no cached master)
Full resync from master: 1aff09ecd70ca640e33083f8422018b29883b9d1:1
MASTER <-> SLAVE sync: receiving 76 bytes from master
MASTER <-> SLAVE sync: Flushing old data
MASTER <-> SLAVE sync: Loading DB in memory
MASTER <-> SLAVE sync: Finished with success
/
127.0.0.1:6380> set myk k
(error) READONLY You can't write against a read only replica.
127.0.0.1:6380> SLAVEOF NO ONE
2967:M 23 Nov 2018 18:13:34.238 # Setting secondary replication ID to a6137c80b386195f28fb8a0a3fd8eda291d2517e, valid up to offset: 463. New replication ID is 6fcaf9d80b46771dfa3f3b59a54eaabf5656ca3b
2967:M 23 Nov 2018 18:13:34.238 # Connection with master lost.
2967:M 23 Nov 2018 18:13:34.238 * Caching the disconnected master state.
2967:M 23 Nov 2018 18:13:34.238 * Discarding previously cached master state.
2967:M 23 Nov 2018 18:13:34.238 * MASTER MODE enabled (user request from 'id=4 addr=127.0.0.1:53304 fd=9 name= age=77 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=34 qbuf-free=32734 obl=0 oll=0 omem=0 events=r cmd=slaveof')
2640:M 23 Nov 2018 18:13:34.238 # Connection with replica 127.0.0.1:6380 lost.
OK
127.0.0.1:6380> set myk k
OK
127.0.0.1:6380> SLAVEOF 127.0.0.1 6379
2967:S 23 Nov 2018 18:16:53.488 * Before turning into a replica, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
2967:S 23 Nov 2018 18:16:53.488 * REPLICAOF 127.0.0.1:6379 enabled (user request from 'id=4 addr=127.0.0.1:53304 fd=9 name= age=276 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=42 qbuf-free=32726 obl=0 oll=0 omem=0 events=r cmd=slaveof')
OK
127.0.0.1:6380> 2967:S 23 Nov 2018 18:16:53.523 * Connecting to MASTER 127.0.0.1:6379
2967:S 23 Nov 2018 18:16:53.523 * MASTER <-> REPLICA sync started
2967:S 23 Nov 2018 18:16:53.523 * Non blocking connect for SYNC fired the event.
2967:S 23 Nov 2018 18:16:53.523 * Master replied to PING, replication can continue...
2967:S 23 Nov 2018 18:16:53.523 * Trying a partial resynchronization (request 21455cef808da3e3a191569a6f1685bdc37e6f0b:519).
2640:M 23 Nov 2018 18:16:53.523 * Replica 127.0.0.1:6380 asks for synchronization
2640:M 23 Nov 2018 18:16:53.523 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for '21455cef808da3e3a191569a6f1685bdc37e6f0b', my replication IDs are 'a6137c80b386195f28fb8a0a3fd8eda291d2517e' and '0000000000000000000000000000000000000000')
2640:M 23 Nov 2018 18:16:53.523 * Starting BGSAVE for SYNC with target: disk
2640:M 23 Nov 2018 18:16:53.524 * Background saving started by pid 3065
2967:S 23 Nov 2018 18:16:53.524 * Full resync from master: a6137c80b386195f28fb8a0a3fd8eda291d2517e:518
2967:S 23 Nov 2018 18:16:53.524 * Discarding previously cached master state.
3065:C 23 Nov 2018 18:16:53.525 * DB saved on disk
2640:M 23 Nov 2018 18:16:53.614 * Background saving terminated with success
2640:M 23 Nov 2018 18:16:53.615 * Synchronization with replica 127.0.0.1:6380 succeeded
2967:S 23 Nov 2018 18:16:53.615 * MASTER <-> REPLICA sync: receiving 176 bytes from master
2967:S 23 Nov 2018 18:16:53.615 * MASTER <-> REPLICA sync: Flushing old data
2967:S 23 Nov 2018 18:16:53.615 * MASTER <-> REPLICA sync: Loading DB in memory
2967:S 23 Nov 2018 18:16:53.615 * MASTER <-> REPLICA sync: Finished with success
/
127.0.0.1:6380> keys *
(empty list or set)
/
2967:S 23 Nov 2018 18:16:53.615 * MASTER <-> REPLICA sync: Flushing old data
**主从结构/slave先flushall 再sync,否则 master/slave 之间 keys 冲突??
/


redis(4) 集群_第3张图片
image.png
redis(4) 集群_第4张图片
image.png

**故障转移

Redis哨兵
高可用Sentinel
官方提供的高可用方案,可以用它管理多个Redis服务实例
编译后产生redis-sentinel程序文件/可执行文件(二进制/bin)
Redis Sentinel是一个分布式系统,可以在一个架构中运行多个Sentinel进程

$ file redis-sentinel
redis-sentinel: Mach-O 64-bit executable x86_64

redis(4) 集群_第5张图片
image.png
image.png

** sentinel通过master get slave状态
/ master 已知 其下 slave状态

redis(4) 集群_第6张图片
image.png
redis(4) 集群_第7张图片
image.png
image.png
redis(4) 集群_第8张图片
image.png
redis(4) 集群_第9张图片
image.png
redis(4) 集群_第10张图片
image.png

**不建议单一哨兵(网络闪断)
**一般,三台(过半)redisd && sentinel

Sentinel实验
编译安装3台redis,node1、node2、node3
node1为master
node2、node3是slaves,配置文件中slaveof ... ...
分别启动node1、node2、node3的redis服务
分别配置3个节点的sentinel.conf
vim sentinel.conf
port 26379
sentinel monitor node1 ... ... 2

redis-sentinel sentinel.conf

$ redis-sentinel sentinel.conf &
[4] 4187
4187:X 23 Nov 21:40:37.287 * Increased maximum number of open files to 10032 (it was originally set to 4864).
.
.-__ ''-._ _.- .. ''-._ Redis 3.2.0 (00000000/0) 64 bit
.-.-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in sentinel mode |`-._`-...-` __...-.-.|'_.-'| Port: 26379 |-. ._ / _.-' | PID: 4187-._ -._-./ .-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' | http://redis.io-._ -._-..-'.-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' |-._ -._-..-'.-' .-'
-._-.
.-' .-'
-._ _.-'-.
_.-'

4187:X 23 Nov 21:40:37.288 # Sentinel ID is e0806fdeee73a14dc5006243c130c352ea09b277
4187:X 23 Nov 21:40:37.288 # +monitor master node1 127.0.0.1 6379 quorum 2

分别在3个节点使用redis-cli
测试redis主从复制效果

**sentinel1、2、3,monitor master

4458:X 23 Nov 21:50:27.421 * +slave slave 127.0.0.1:6380 127.0.0.1 6380 @ node1 127.0.0.1 6379
4458:X 23 Nov 21:50:27.422 * +slave slave 127.0.0.1:6381 127.0.0.1 6381 @ node1 127.0.0.1 6379
4458:X 23 Nov 21:50:29.228 * +sentinel sentinel e0806fdeee73a14dc5006243c130c352ea09b277 127.0.0.1 26379 @ node1 127.0.0.1 6379
4458:X 23 Nov 21:50:37.252 * +sentinel sentinel 6de57187858906e088cbbaf345423f749ceea3c5 127.0.0.1 26381 @ node1 127.0.0.1 6379

kill master

-> sentinel -> 启动failover

2640:signal-handler (1542981388) Received SIGTERM scheduling shutdown...
2640:M 23 Nov 2018 21:56:28.699 # User requested shutdown...
2640:M 23 Nov 2018 21:56:28.699 # Redis is now ready to exit, bye bye...
3934:S 23 Nov 2018 21:56:28.700 # Connection with master lost.
3934:S 23 Nov 2018 21:56:28.700 * Caching the disconnected master state.
2967:S 23 Nov 2018 21:56:28.700 # Connection with master lost.
2967:S 23 Nov 2018 21:56:28.700 * Caching the disconnected master state.
[1] 2640 done redis-server --port 6379
2967:S 23 Nov 2018 21:56:28.831 * Connecting to MASTER 127.0.0.1:6379
2967:S 23 Nov 2018 21:56:28.831 * MASTER <-> REPLICA sync started
2967:S 23 Nov 2018 21:56:28.832 # Error condition on socket for SYNC: Connection refused
3934:S 23 Nov 2018 21:56:29.193 * Connecting to MASTER 127.0.0.1:6379
3934:S 23 Nov 2018 21:56:29.193 * MASTER <-> REPLICA sync started
3934:S 23 Nov 2018 21:56:29.193 # Error condition on socket for SYNC: Connection refused
/
4417:X 23 Nov 21:56:58.773 # +sdown master node1 127.0.0.1 6379
4417:X 23 Nov 21:56:58.924 # +new-epoch 1
4417:X 23 Nov 21:56:58.924 # +vote-for-leader 6de57187858906e088cbbaf345423f749ceea3c5 1
3934:S 23 Nov 2018 21:56:58.989 * Connecting to MASTER 127.0.0.1:6379
3934:S 23 Nov 2018 21:56:58.989 * MASTER <-> REPLICA sync started
3934:S 23 Nov 2018 21:56:58.989 # Error condition on socket for SYNC: Connection refused
2967:S 23 Nov 2018 21:56:59.650 * Connecting to MASTER 127.0.0.1:6379
2967:S 23 Nov 2018 21:56:59.650 * MASTER <-> REPLICA sync started
2967:S 23 Nov 2018 21:56:59.650 # Error condition on socket for SYNC: Connection refused
4417:X 23 Nov 21:56:59.866 # +odown master node1 127.0.0.1 6379 #quorum 3/2
4417:X 23 Nov 21:56:59.866 # Next failover delay: I will not start a failover before Fri Nov 23 22:02:59 2018
3934:M 23 Nov 2018 21:56:59.879 # Setting secondary replication ID to a6137c80b386195f28fb8a0a3fd8eda291d2517e, valid up to offset: 126511. New replication ID is 6ef5a61ca4a6a41e1d1ae0f01818e79851ab640c
3934:M 23 Nov 2018 21:56:59.879 * Discarding previously cached master state.
3934:M 23 Nov 2018 21:56:59.879 * MASTER MODE enabled (user request from 'id=17 addr=127.0.0.1:55801 fd=13 name=sentinel-6de57187-cmd age=384 idle=0 flags=x db=0 sub=0 psub=0 multi=3 qbuf=140 qbuf-free=32628 obl=36 oll=0 omem=0 events=r cmd=exec')
2967:S 23 Nov 2018 21:56:59.999 * REPLICAOF 127.0.0.1:6381 enabled (user request from 'id=23 addr=127.0.0.1:55803 fd=13 name=sentinel-6de57187-cmd age=384 idle=0 flags=x db=0 sub=0 psub=0 multi=3 qbuf=278 qbuf-free=32490 obl=36 oll=0 omem=0 events=r cmd=exec')
4417:X 23 Nov 21:56:59.999 # +config-update-from sentinel 6de57187858906e088cbbaf345423f749ceea3c5 127.0.0.1 26381 @ node1 127.0.0.1 6379
4417:X 23 Nov 21:56:59.999 # +switch-master node1 127.0.0.1 6379 127.0.0.1 6381
4417:X 23 Nov 21:56:59.999 * +slave slave 127.0.0.1:6380 127.0.0.1 6380 @ node1 127.0.0.1 6381
4417:X 23 Nov 21:56:59.999 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ node1 127.0.0.1 6381
2967:S 23 Nov 2018 21:57:00.669 * Connecting to MASTER 127.0.0.1:6381
2967:S 23 Nov 2018 21:57:00.669 * MASTER <-> REPLICA sync started
2967:S 23 Nov 2018 21:57:00.669 * Non blocking connect for SYNC fired the event.
2967:S 23 Nov 2018 21:57:00.669 * Master replied to PING, replication can continue...
2967:S 23 Nov 2018 21:57:00.669 * Trying a partial resynchronization (request a6137c80b386195f28fb8a0a3fd8eda291d2517e:126511).
3934:M 23 Nov 2018 21:57:00.669 * Replica 127.0.0.1:6380 asks for synchronization
3934:M 23 Nov 2018 21:57:00.669 * Partial resynchronization request from 127.0.0.1:6380 accepted. Sending 283 bytes of backlog starting from offset 126511.
2967:S 23 Nov 2018 21:57:00.670 * Successful partial resynchronization with master.
2967:S 23 Nov 2018 21:57:00.670 # Master replication ID changed to 6ef5a61ca4a6a41e1d1ae0f01818e79851ab640c
2967:S 23 Nov 2018 21:57:00.670 * MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization.
4417:X 23 Nov 21:57:30.006 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ node1 127.0.0.1 6381

$ redis-server --port 6379

4821:M 23 Nov 22:05:00.346 * Increased maximum number of open files to 10032 (it was originally set to 4864).
.
.-__ ''-._ _.- .. ''-._ Redis 3.2.0 (00000000/0) 64 bit
.-.-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.-.|'_.-'| Port: 6379 |-. ._ / _.-' | PID: 4821-._ -._-./ .-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' | http://redis.io-._ -._-..-'.-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' |-._ -._-..-'.-' .-'
-._-.
.-' .-'
-._ _.-'-.
_.-'

4821:M 23 Nov 22:05:00.347 # Server started, Redis version 3.2.0
4821:M 23 Nov 22:05:00.348 * The server is now ready to accept connections on port 6379
4821:S 23 Nov 22:05:10.525 * SLAVE OF 127.0.0.1:6381 enabled (user request from 'id=2 addr=127.0.0.1:59019 fd=6 name=sentinel-e0806fde-cmd age=10 idle=0 flags=x db=0 sub=0 psub=0 multi=3 qbuf=0 qbuf-free=32768 obl=36 oll=0 omem=0 events=r cmd=exec')
4821:S 23 Nov 22:05:10.656 * Connecting to MASTER 127.0.0.1:6381
4821:S 23 Nov 22:05:10.657 * MASTER <-> SLAVE sync started
4821:S 23 Nov 22:05:10.657 * Non blocking connect for SYNC fired the event.
4821:S 23 Nov 22:05:10.657 * Master replied to PING, replication can continue...
4821:S 23 Nov 22:05:10.657 * Partial resynchronization not possible (no cached master)
4821:S 23 Nov 22:05:10.658 * Full resync from master: 6ef5a61ca4a6a41e1d1ae0f01818e79851ab640c:220042
4821:S 23 Nov 22:05:15.664 # Opening the temp file needed for MASTER <-> SLAVE synchronization: Operation timed out
/
5543:S 23 Nov 22:20:33.195 # Can't handle RDB format version 9
5543:S 23 Nov 22:20:33.195 # Failed trying to load the MASTER synchronization DB from disk
5543:S 23 Nov 22:20:34.125 * Connecting to MASTER 127.0.0.1:6381
5543:S 23 Nov 22:20:34.125 * MASTER <-> SLAVE sync started
5543:S 23 Nov 22:20:34.125 * Non blocking connect for SYNC fired the event.
5543:S 23 Nov 22:20:34.126 * Master replied to PING, replication can continue...
5543:S 23 Nov 22:20:34.126 * Partial resynchronization not possible (no cached master)
5543:S 23 Nov 22:20:34.127 * Full resync from master: 6ef5a61ca4a6a41e1d1ae0f01818e79851ab640c:378166
5543:S 23 Nov 22:20:34.230 * MASTER <-> SLAVE sync: receiving 191 bytes from master
5543:S 23 Nov 22:20:34.231 * MASTER <-> SLAVE sync: Flushing old data
5543:S 23 Nov 22:20:34.231 * MASTER <-> SLAVE sync: Loading DB in memory
/
sentinel 6379
/
$ redis-sentinel sentinel.conf
5628:X 23 Nov 22:19:56.580 * Increased maximum number of open files to 10032 (it was originally set to 4864).
.
.-__ ''-._ _.- .. ''-._ Redis 3.2.0 (00000000/0) 64 bit
.-.-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in sentinel mode |`-._`-...-` __...-.-.|'_.-'| Port: 26379 |-. ._ / _.-' | PID: 5628-._ -._-./ .-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' | http://redis.io-._ -._-..-'.-' .-'
|-._-.
-.__.-' _.-'_.-'| |-.
-._ _.-'_.-' |-._ -._-..-'.-' .-'
-._-.
.-' .-'
-._ _.-'-.
_.-'

5628:X 23 Nov 22:19:56.581 # Sentinel ID is e0806fdeee73a14dc5006243c130c352ea09b277
5628:X 23 Nov 22:19:56.581 # +monitor master node1 127.0.0.1 6381 quorum 2
5628:X 23 Nov 22:20:06.596 * +convert-to-slave slave 127.0.0.1:6379 127.0.0.1 6379 @ node1 127.0.0.1 6381
3934:M 23 Nov 2018 22:20:07.446 * Replica 127.0.0.1:6379 asks for synchronization
3934:M 23 Nov 2018 22:20:07.446 * Full resync requested by replica 127.0.0.1:6379
3934:M 23 Nov 2018 22:20:07.446 * Starting BGSAVE for SYNC with target: disk
3934:M 23 Nov 2018 22:20:07.447 * Background saving started by pid 5629
5629:C 23 Nov 2018 22:20:07.454 * DB saved on disk
3934:M 23 Nov 2018 22:20:07.527 * Background saving terminated with success
3934:M 23 Nov 2018 22:20:07.528 * Synchronization with replica 127.0.0.1:6379 succeeded
3934:M 23 Nov 2018 22:20:07.528 # Connection with replica 127.0.0.1:6379 lost.

**主节点(master)变动问题

$ redis-cli -h 127.0.0.1 -p 26380 info sentinel

Sentinel

sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=node1,status=ok,address=127.0.0.1:6381,slaves=2,sentinels=3

$ redis-cli -p 26380 sentinel get-master-addr-by-name node1

  1. "127.0.0.1"
  2. "6381"

$ redis-cli -p 26380 sentinel master node1

  1. "name"
  2. "node1"
  3. "ip"
  4. "127.0.0.1"
  5. "port"
  6. "6381"
  7. "runid"
  8. "20ed85210c7be907f2d35749c7b2bc0874451fb2"
  9. "flags"
  10. "master"
  11. "link-pending-commands"
  12. "28"
  13. "link-refcount"
  14. "1"
  15. "last-ping-sent"
  16. "0"
  17. "last-ok-ping-reply"
  18. "833"
  19. "last-ping-reply"
  20. "833"
  21. "down-after-milliseconds"
  22. "30000"
  23. "info-refresh"
  24. "82"
  25. "role-reported"
  26. "master"
  27. "role-reported-time"
  28. "2410793"
  29. "config-epoch"
  30. "1"
  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-cli -p 26380 sentinel slaves node1

    1. "name"
    2. "127.0.0.1:6379"
    3. "ip"
    4. "127.0.0.1"
    5. "port"
    6. "6379"
    7. "runid"
    8. "2db54e0800adf683f009a12e1d3f38367bcb40ad"
    9. "flags"
  1. "s_down,slave,disconnected"
  2. "link-pending-commands"
  3. "29"
  4. "link-refcount"
  5. "1"
  6. "last-ping-sent"
  7. "947640"
  8. "last-ok-ping-reply"
  9. "1062434"
  10. "last-ping-reply"
  11. "1062434"
  12. "s-down-time"
  13. "917635"
  14. "down-after-milliseconds"
  15. "30000"
  16. "info-refresh"
  17. "1211255"
  18. "role-reported"
  19. "slave"
  20. "role-reported-time"
  21. "1746256"
  22. "master-link-down-time"
  23. "1542982657000"
  24. "master-link-status"
  25. "err"
  26. "master-host"
  27. "127.0.0.1"
  28. "master-port"
  29. "6381"
  30. "slave-priority"
  31. "100"
  32. "slave-repl-offset"
  33. "1"
    1. "name"
    2. "127.0.0.1:6380"
    3. "ip"
    4. "127.0.0.1"
    5. "port"
    6. "6380"
    7. "runid"
    8. "7dc7dfa138c39b4e6f7a843551c8f8cfec2e2ac1"
    9. "flags"
  34. "slave"
  35. "link-pending-commands"
  36. "0"
  37. "link-refcount"
  38. "1"
  39. "last-ping-sent"
  40. "0"
  41. "last-ok-ping-reply"
  42. "430"
  43. "last-ping-reply"
  44. "430"
  45. "down-after-milliseconds"
  46. "30000"
  47. "info-refresh"
  48. "9278"
  49. "role-reported"
  50. "slave"
  51. "role-reported-time"
  52. "2449071"
  53. "master-link-down-time"
  54. "0"
  55. "master-link-status"
  56. "ok"
  57. "master-host"
  58. "127.0.0.1"
  59. "master-port"
  60. "6381"
  61. "slave-priority"
  62. "100"
  63. "slave-repl-offset"
  64. "510379"
redis(4) 集群_第11张图片
image.png

你可能感兴趣的:(redis(4) 集群)