Redis主从复制及使用Sentinel实现Redis高可用

Redis主从复制实现及如何利用Sentinel实现高可用

1、Redis复制:

         特点:

                   一个master可以有多个slaver;

                   支持链式复制;

                   master以非阻塞方式同步数据至slaver;

         slave:

                   > SLAVEOF MASTER_IP MASTER_PORT

         注意:如果master使用requirepass开启了认证功能,从服务器要使用masterauth <PASSWORD>来连入服务请求,并使用此密码进行认证;

复制过程

如下图:

 

 

相关配置参数:

#################################REPLICATION #################################

# slaveof<masterip> <masterport>

slaveof 192.168.88.1306379

# masterauth<master-password>

slave-serve-stale-datayes

#客户端请求数据时,从服务器上是否可以使用过期数据

slave-read-only yes

#是否只读

repl-diskless-sync no

#是否进行diskless同步

repl-diskless-sync-delay5

#diskless同步延迟时间

# repl-ping-slave-period10

# repl-timeout 60

repl-disable-tcp-nodelayno

# repl-backlog-size 1mb

# repl-backlog-ttl 3600

slave-priority 100

#salve优先级

# min-slaves-to-write 3

#只有当3个(或以上)的从库连接到主库时,主库才是可写的,否则会返回错误

# min-slaves-max-lag 10

#允许从库最长失去连接的时间,如果从库最后与主库联系(即发送“replconf ack”命令)的时间小于这个值,

#则认为从库还在保持与主库的连接

#即从服务器必须不能滞后于主服务器多长时间,否则主服务器拒绝执行写入操作。

# slave-announce-ip5.5.5.5

# slave-announce-port1234

#################################REPLICATION #################################

 

案例1:创建2个Redis实例,分别在不同服务器,使用不同IP,相同port做Redis主从服务器

Redis master192.168.88.130 6379 /etc/redis.conf  dir /var/lib/redis

Redis slaver192.168.88.131 6379 /etc/redis.conf  dir /var/lib/redis

 

[root@www ~]# vim /etc/redis.conf

bind 127.0.0.1 192.168.88.131

[root@www ~]# service redis restart

停止 redis-server:Could not connect to Redis at 127.0.0.1:6379: Connection refused

[确定]

启动:[确定]

[root@www ~]# redis-cli -h 192.168.88.131

192.168.88.131:6379> SLAVEOF192.168.88.130 6379

OK

192.168.88.131:6379> get ip

"172.16.100.2"

         [root@test~]# redis-cli -h 192.168.88.130

         192.168.88.130:6379>set ip 192.168.88.130

         OK

         192.168.88.130:6379>keys *

         1)"ip"

         2)"port"

192.168.88.131:6379> get ip

"192.168.88.130"

192.168.88.131:6379> keys *

1) "ip"

2) "port"

192.168.88.131:6379> exit

查看Redis日志:

[root@www ~]# tail /var/log/redis/redis.log

64115:S 26 Apr 01:24:17.761 * Connecting toMASTER 192.168.88.130:6379

64115:S 26 Apr 01:24:17.790 * MASTER<-> SLAVE sync started

64115:S 26 Apr 01:24:17.790 * Non blockingconnect for SYNC fired the event.

64115:S 26 Apr 01:24:17.791 * Masterreplied to PING, replication can continue...

64115:S 26 Apr 01:24:17.792 * Partialresynchronization not possible (no cached master)

64115:S 26 Apr 01:24:17.806 * Full resyncfrom master: e0e983bb317ef2a5fe9be232f4aa47d70223b3fc:1

64115:S 26 Apr 01:24:17.964 * MASTER<-> SLAVE sync: receiving 108 bytes from master

64115:S 26 Apr 01:24:17.964 * MASTER<-> SLAVE sync: Flushing old data

64115:S 26 Apr 01:24:17.964 * MASTER<-> SLAVE sync: Loading DB in memory

64115:S 26 Apr 01:24:17.964 * MASTER<-> SLAVE sync: Finished with success

[root@www ~]# redis-cli -h 192.168.88.131

192.168.88.131:6379> config get slaveof

1) "slaveof"

2) "192.168.88.130 6379"

192.168.88.131:6379> CONFIG GET SLAVEOF

1) "slaveof"

2) "192.168.88.130 6379"

192.168.88.131:6379> info Replication

# Replication

role:slave

master_host:192.168.88.130

master_port:6379

master_link_status:up

master_last_io_seconds_ago:5

master_sync_in_progress:0

slave_repl_offset:911

slave_priority:100

slave_read_only:1

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

查看主服务复制信息

192.168.88.130:6379> info Replication

# Replication

role:master

connected_slaves:1

slave0:ip=192.168.88.131,port=6379,state=online,offset=939,lag=1

master_repl_offset:939

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:938

192.168.88.130:6379> exit

查看主服务器日志

[root@test etc]# tail -f/var/log/redis/redis.log

43376:M 26 Apr 00:34:10.781 * Residualparent diff successfully flushed to the rewritten AOF (0.00 MB)

43376:M 26 Apr 00:34:10.781 * BackgroundAOF rewrite finished successfully

43376:M 26 Apr 01:24:17.804 * Slave192.168.88.131:6379 asks for synchronization

43376:M 26 Apr 01:24:17.804 * Full resyncrequested by slave 192.168.88.131:6379

43376:M 26 Apr 01:24:17.804 * StartingBGSAVE for SYNC with target: disk

43376:M 26 Apr 01:24:17.804 * Backgroundsaving started by pid 47067

47067:C 26 Apr 01:24:17.881 * DB saved ondisk

47067:C 26 Apr 01:24:17.882 * RDB: 0 MB ofmemory used by copy-on-write

43376:M 26 Apr 01:24:17.962 * Backgroundsaving terminated with success

43376:M 26 Apr 01:24:17.962 *Synchronization with slave 192.168.88.131:6379 succeeded

 

案例2:创建2个Redis实例,使用同个服务器,同个IP,不同port做Redis主从服务器

Redis master192.168.88.130 6379 /etc/redis.conf  dir /var/lib/redis

Redis slaver192.168.88.130 6380 /etc/redis.conf.2  dir /redis/db

 

[root@test ~]# mkdir /redis/db -pv

mkdir: 已创建目录"/redis"

mkdir: 已创建目录"/redis/db"

[root@test ~]# id redis

uid=495(redis) gid=492(redis) 组=492(redis)

[root@test ~]# chown -R redis:redis/redis/db

[root@test ~]# cp /etc/redis.conf/etc/redis.conf.2

[root@test ~]# vi /etc/redis.conf.2

port 6380

dir /redis/db

 

[root@test ~]# 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 <megabytes>

 

Examples:

      ./redis-server (run the server with default conf)

      ./redis-server /etc/redis/6379.conf

      ./redis-server --port 7777

      ./redis-server --port 7777 --slaveof 127.0.0.1 8888

      ./redis-server /etc/myredis.conf --loglevel verbose

 

Sentinel mode:

      ./redis-server /etc/sentinel.conf --sentinel

[root@test ~]# redis-server /etc/redis.conf

[root@test ~]# ss -tnl | grep 6379

0     128                                   192.168.88.130:6379                                              *:*    

0     128                                        127.0.0.1:6379                                              *:*      

[root@test ~]# redis-server/etc/redis.conf.2

[root@test ~]# ss -tnl | grep 6379

Recv-Q Send-Q                                  LocalAddress:Port                                   Peer Address:Port  

0     128                                   192.168.88.130:6379                                              *:*    

0     128                                        127.0.0.1:6379                                              *:*      

[root@test ~]# redis-cli -h 192.168.88.130-p 6380

设置Redis主从服务器

192.168.88.130:6380> SLAVEOF192.168.88.130 6379

OK

192.168.88.130:6380> info Replication

# Replication

role:slave

master_host:192.168.88.130

master_port:6379

master_link_status:up

master_last_io_seconds_ago:3

master_sync_in_progress:0

slave_repl_offset:2077

slave_priority:100

slave_read_only:1

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

192.168.88.130:6380> exit

[root@test ~]# redis-cli -h 192.168.88.130

192.168.88.130:6379> info Replication

# Replication

role:master

connected_slaves:2

slave0:ip=192.168.88.131,port=6379,state=online,offset=1779,lag=0

slave1:ip=127.0.0.1,port=6380,state=online,offset=1779,lag=0

master_repl_offset:1779

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:1778

192.168.88.130:6379> SET port 6380

OK

192.168.88.130:6379> SET day 0426

OK

192.168.88.130:6379> exit

测试同步

[root@test ~]# redis-cli -h 192.168.88.130-p 6380

192.168.88.130:6380> get port

"6380"

192.168.88.130:6380> get day

"0426"

192.168.88.130:6380> exit

[root@test ~]# redis-cli -h 192.168.88.131

192.168.88.131:6379> get day

"0426"

192.168.88.131:6379> get port

"6380"

192.168.88.131:6379> exit

 

2、Sentinel:

         用于管理多个Redis服务实现HA;

                   监控

                   通知

                   自动故障转移                

                   留言协议,投票协议

         程序:

                   redis-sentinel/path/to/file.conf

                   redis-server/path/to/file.conf --sentinel

                  

专业配置文件:/etc/redis-sentinel.conf

(1)sentinel monitor <master-name><ip> <redis-port> <quorum>

sentinel monitor mymaster 127.0.0.1 6379 2

(2)sentinel down-after-milliseconds<master-name> <milliseconds>

判断主节点不在线的超时时长,默认30s # Default is 30 seconds.

sentinel down-after-milliseconds mymaster30000

(3)sentinel parallel-syncs<master-name> <numslaves>

服务器在执行故障转移时至多可以有多少从服务器对新的主服务器进行同步请求

sentinel parallel-syncs mymaster 1

(4) sentinel failover-timeout<master-name> <milliseconds>

故障转移超时时间 Default is 3 minutes.

sentinel failover-timeout mymaster 180000

 

主观下线,客观下线

         主观下线:一个sentinel实例判断出某节点下线

         客观下线:多个sentinel节点协商后判断出某节点下线

 

专用命令:

         SENTINEL masters

         SENTINEL slaves <master name>

         SENTINEL get-master-addr-by-name <master name>

         SENTINEL reset

         SENTINEL failover <master name>

 

案例3、创建3个Redis实例,设置为一主两从模式,使用sentinel实现该模式高可用

Redis master192.168.88.131 6379 /etc/redis/redis.conf   dir /var/lib/redis

Redis slave1192.168.88.131 6380 /etc/redis/redis.conf.2 dir /redis/db2

Redis slave2192.168.88.131 6381 /etc/redis/redis.conf.3 dir /redis/db3

 

[root@www ~]# mkdir /etc/redis -pv

mkdir: 已创建目录"/etc/redis"

[root@www ~]# cp /etc/redis.conf /etc/redis

[root@www ~]# cd /etc/redis

[root@www redis]# ls

redis.conf

[root@www redis]# cp redis.confredis.conf.2

[root@www redis]# cp redis.confredis.conf.3

[root@www redis]# mkdir -pv/redis/db{1,2,3}

mkdir: 已创建目录"/redis"

mkdir: 已创建目录"/redis/db1"

mkdir: 已创建目录"/redis/db2"

mkdir: 已创建目录"/redis/db3"

[root@www redis]# chown -R redis:redis/redis/db*

[root@www redis]# ll

总用量 144

-rw-r-----. 1 root root 47332 4月  26 02:27 redis.conf

-rw-r-----. 1 root root 47332 4月  26 02:27 redis.conf.2

-rw-r-----. 1 root root 47332 4月  26 02:27 redis.conf.3

[root@www redis]# vi redis.conf

bind 0.0.0.0

daemonize yes

#slaveof 192.168.88.130 6379

[root@www redis]# vi redis.conf.2

bind 0.0.0.0

daemonize yes

port 6380

pidfile /var/run/redis_6380.pid

logfile /var/log/redis/redis2.log

dir /redis/db2

#slaveof 192.168.88.130 6379

[root@www redis]# vi redis.conf.3

bind 0.0.0.0

daemonize yes

port 6381

pidfile /var/run/redis_6381.pid

logfile /var/log/redis/redis3.log

dir /redis/db3

#slaveof 192.168.88.130 6379

[root@www redis]# redis-server/etc/redis/redis.conf

[root@www redis]# redis-server/etc/redis/redis.conf.2

[root@www redis]# redis-server/etc/redis/redis.conf.3

[root@www redis]# ss -tnl | grep 63

0     128                           *:6379                         *:*    

0     128                           *:6380                         *:*    

0     128                            *:6381                          *:*    

0     128                   127.0.0.1:631                          *:*    

0     128                         ::1:631                         :::*    

[root@www redis]#

[root@www redis]# killall redis-server

[root@www redis]# ss -tnl | grep 63

0     128                   127.0.0.1:631                          *:*    

0     128                         ::1:631                         :::*    

[root@www redis]#

[root@www redis]# redis-server /etc/redis/redis.conf

[root@www redis]# redis-server/etc/redis/redis.conf.2

[root@www redis]# redis-server/etc/redis/redis.conf.3

[root@www redis]# ss -tnl | grep 63

0     128                           *:6379                         *:*    

0     128                            *:6380                          *:*    

0     128                           *:6381                         *:*    

0     128                   127.0.0.1:631                          *:*    

0     128                         ::1:631                         :::*    

[root@www redis]# redis-cli -h192.168.88.131 -p 6379

192.168.88.131:6379> info replication

# Replication

role:master

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

 

[root@www ~]# redis-cli -h 192.168.88.131-p 6380

192.168.88.131:6380> info replication

# Replication

role:master

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

设置master服务器IP、port

192.168.88.131:6380> slaveof192.168.88.131 6379

OK

192.168.88.131:6380> info replication

# Replication

role:slave

master_host:192.168.88.131

master_port:6379

master_link_status:up

master_last_io_seconds_ago:1

master_sync_in_progress:0

slave_repl_offset:1

slave_priority:100

slave_read_only:1

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

[root@www redis]# redis-cli -h192.168.88.131 -p 6379

192.168.88.131:6379> info replication

# Replication

role:master

connected_slaves:1

slave0:ip=192.168.88.131,port=6380,state=online,offset=15,lag=1

master_repl_offset:15

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:14

[root@www ~]# redis-cli -h 192.168.88.131-p 6381

192.168.88.131:6381> info replication

# Replication

role:master

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

设置master服务器IP、port

192.168.88.131:6381> slaveof192.168.88.131 6379

OK

192.168.88.131:6381> info replication

# Replication

role:slave

master_host:192.168.88.131

master_port:6379

master_link_status:up

master_last_io_seconds_ago:1

master_sync_in_progress:0

slave_repl_offset:43

slave_priority:100

slave_read_only:1

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

192.168.88.131:6381>

查看主节点相关信息

[root@www redis]# redis-cli -h192.168.88.131 -p 6379

192.168.88.131:6379> info replication

# Replication

role:master

connected_slaves:2

slave0:ip=192.168.88.131,port=6380,state=online,offset=43,lag=0

slave1:ip=192.168.88.131,port=6381,state=online,offset=43,lag=0

master_repl_offset:43

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:42

192.168.88.131:6379>

验证同步功能:

192.168.88.131:6379> set ip 0.0.0.0.

OK

192.168.88.131:6379> set cache nginx

OK

192.168.88.131:6379> keys *

1) "cache"

2) "port"

3) "day"

4) "ip"

6380查看6379端口相关数据

192.168.88.131:6380> get ip

"0.0.0.0."

192.168.88.131:6380> get cache

"nginx"

192.168.88.131:6380> keys *

1) "ip"

2) "port"

3) "cache"

4) "day"

192.168.88.131:6380>

6381查看6379端口相关数据

192.168.88.131:6381> get ip

"0.0.0.0."

192.168.88.131:6381> get cache

"nginx"

192.168.88.131:6381> keys *

1) "ip"

2) "cache"

3) "day"

4) "port"

192.168.88.131:6381>

配置sentinel实现Redis高可用。

[root@www ~]# cp /etc/redis-sentinel.conf/etc/redis/

[root@www ~]# vi/etc/redis/redis-sentinel.conf

sentinel monitor mymaster 192.168.88.1316379 1

sentinel down-after-milliseconds mymaster5000

sentinel parallel-syncs mymaster 1

sentinel failover-timeout mymaster 20000

[root@www ~]# redis-sentinel/etc/redis/redis-sentinel.conf

 

[root@www ~]# redis-cli -h 192.168.88.131-p 26379

192.168.88.131:26379> info

DENIED Redis is running in protected modebecause protected mode is enabled, no bind address was specified, noauthentication password is requested to clients. In this mode connections areonly accepted from the loopback interface. If you want to connect from externalcomputers to Redis you may adopt one of the following solutions: 1) Justdisable protected mode sending the command 'CONFIG SET protected-mode no' fromthe loopback interface by connecting to Redis from the same host the server isrunning, however MAKE SURE Redis is not publicly accessible from internet ifyou do so. Use CONFIG REWRITE to make this change permanent. 2) Alternativelyyou can just disable the protected mode by editing the Redis configurationfile, and setting the protected mode option to 'no', and then restarting theserver. 3) If you started the server manually just for testing, restart it withthe '--protected-mode no' option. 4) Setup a bind address or an authenticationpassword. NOTE: You only need to do one of the above things in order for theserver to start accepting connections from the outside.

出现该报错的原因是protected mode下,监听地址没配或监听地址与Redis各服务器不在同一网段

可打开# protected-mode no注释或设置 bind 0.0.0.0

[root@www ~]# vi/etc/redis/redis-sentinel.conf

# protected-mode no

bind 0.0.0.0

[root@www ~]# redis-cli -h 192.168.88.131-p 26379

192.168.88.131:26379> 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=mymaster,status=ok,address=192.168.88.131:6379,slaves=2,sentinels=1

192.168.88.131:26379>

[root@www ~]# vi/etc/redis/redis-sentinel.conf

protected-mode no

# bind 0.0.0.0

[root@www ~]# redis-cli -h 192.168.88.131-p 26379

192.168.88.131:26379> 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=mymaster,status=ok,address=192.168.88.131:6379,slaves=2,sentinels=1

192.168.88.131:26379>

主节点对应配置的详细信息

192.168.88.131:26379> SENTINEL masters

1) 1) "name"

   2) "mymaster"

   3) "ip"

   4) "192.168.88.131"

   5) "port"

   6) "6379"

   7) "runid"

   8) "51fb03072235cbbfcb612a5612ad7c5413d6d779"

   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) "668"

  19) "last-ping-reply"

  20) "668"

  21) "down-after-milliseconds"

  22) "5000"

  23) "info-refresh"

  24) "180"

  25) "role-reported"

  26) "master"

  27) "role-reported-time"

  28) "120598"

  29) "config-epoch"

  30) "0"

  31) "num-slaves"

  32) "2"

  33) "num-other-sentinels"

  34) "0"

  35) "quorum"

  36) "1"

  37) "failover-timeout"

  38) "20000"

  39) "parallel-syncs"

  40) "1"

192.168.88.131:26379>

查看指定主节点的从服务器

192.168.88.131:26379> SENTINEL slavesmymaster

1) 1) "name"

   2) "192.168.88.131:6381"

   3) "ip"

   4) "192.168.88.131"

   5) "port"

   6) "6381"

   7) "runid"

   8) "442435610152c92c5c36f89eedd86b207e1b219e"

   9) "flags"

  10) "slave"

  11) "link-pending-commands"

  12) "0"

  13) "link-refcount"

  14) "1"

  15) "last-ping-sent"

  16) "0"

  17) "last-ok-ping-reply"

  18) "528"

  19) "last-ping-reply"

  20) "528"

  21) "down-after-milliseconds"

  22) "5000"

  23) "info-refresh"

  24) "8231"

  25) "role-reported"

  26) "slave"

  27) "role-reported-time"

  28) "299156"

  29) "master-link-down-time"

  30) "0"

  31) "master-link-status"

  32) "ok"

  33) "master-host"

  34) "192.168.88.131"

  35) "master-port"

  36) "6379"

  37) "slave-priority"

  38) "100"

  39) "slave-repl-offset"

  40) "80690"

2) 1) "name"

   2) "192.168.88.131:6380"

   3) "ip"

   4) "192.168.88.131"

   5) "port"

   6) "6380"

   7) "runid"

   8) "708b690b500040a221da8f1388a1ebc4b5ae5b77"

   9) "flags"

  10) "slave"

  11) "link-pending-commands"

  12) "0"

  13) "link-refcount"

  14) "1"

  15) "last-ping-sent"

  16) "0"

  17) "last-ok-ping-reply"

  18) "528"

  19) "last-ping-reply"

  20) "528"

  21) "down-after-milliseconds"

  22) "5000"

  23) "info-refresh"

  24) "8231"

  25) "role-reported"

  26) "slave"

  27) "role-reported-time"

  28) "299156"

  29) "master-link-down-time"

  30) "0"

  31) "master-link-status"

  32) "ok"

  33) "master-host"

  34) "192.168.88.131"

  35) "master-port"

  36) "6379"

  37) "slave-priority"

  38) "100"

  39) "slave-repl-offset"

  40) "80690"

192.168.88.131:26379>

 

(1)让主节点下线,从节点会成为主节点

[root@www ~]# ps -ef |grep redis

root    14982     1  0 12:16 ?        00:00:06 redis-server 0.0.0.0:6379        

root    14996     1  0 12:16 ?        00:00:05 redis-server 0.0.0.0:6380          

root    15006     1  0 12:16 ?        00:00:10 redis-server 0.0.0.0:6381          

root    29192 24193  0 13:25 pts/0    00:00:00 redis-sentinel 0.0.0.0:26379[sentinel]     

root    29220 26157  0 13:25 pts/1    00:00:00 redis-cli -h 192.168.88.131 -p26379

root    30461 29297  0 13:32 pts/2    00:00:00 grep redis

[root@www ~]# kill -9 14982

[root@www ~]# ps -ef |grep redis

root    14996     1  0 12:16 ?        00:00:05 redis-server 0.0.0.0:6380          

root    15006     1  0 12:16 ?        00:00:10 redis-server 0.0.0.0:6381          

root    29192 24193  0 13:25 pts/0    00:00:01 redis-sentinel 0.0.0.0:26379[sentinel]     

root    29220 26157  0 13:25 pts/1    00:00:00 redis-cli -h 192.168.88.131 -p26379

root    30538 29297  0 13:32 pts/2    00:00:00 grep redis

[root@www ~]# redis-cli -h 192.168.88.131-p 26379

192.168.88.131:26379> 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=mymaster,status=ok,address=192.168.88.131:6381,slaves=2,sentinels=1

192.168.88.131:26379> SENTINEL masters

1) 1) "name"

   2) "mymaster"

   3) "ip"

   4) "192.168.88.131"

   5) "port"

   6) "6381"

   7) "runid"

   8) "442435610152c92c5c36f89eedd86b207e1b219e"

   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) "406"

  19) "last-ping-reply"

  20) "406"

  21) "down-after-milliseconds"

  22) "5000"

  23) "info-refresh"

  24) "6355"

  25) "role-reported"

  26) "master"

  27) "role-reported-time"

  28) "66734"

  29) "config-epoch"

  30) "1"

  31) "num-slaves"

  32) "2"

  33) "num-other-sentinels"

  34) "0"

  35) "quorum"

  36) "1"

  37) "failover-timeout"

  38) "20000"

  39) "parallel-syncs"

  40) "1"

192.168.88.131:26379>

[root@www ~]# redis-cli -h 192.168.88.131-p 6380

192.168.88.131:6380> info replication

# Replication

role:slave

master_host:192.168.88.131

master_port:6381

master_link_status:up

master_last_io_seconds_ago:1

master_sync_in_progress:0

slave_repl_offset:8629

slave_priority:100

slave_read_only:1

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

192.168.88.131:6380>

(2)旧主节点重新上线,主节点不会改变

[root@www ~]# redis-server/etc/redis/redis.conf

[root@www ~]# ps -ef |grep redis

root    14996     1  0 12:16 ?        00:00:06 redis-server 0.0.0.0:6380          

root    15006     1  0 12:16 ?        00:00:11 redis-server 0.0.0.0:6381          

root    29192 24193  0 13:25 pts/0    00:00:01 redis-sentinel 0.0.0.0:26379[sentinel]     

root    29220 26157  0 13:25 pts/1    00:00:00 redis-cli -h 192.168.88.131 -p26379

root    30922 30884  0 13:34 pts/3    00:00:00 redis-cli -h 192.168.88.131 -p6380

root    31134     1  0 13:35 ?        00:00:00 redis-server 0.0.0.0:6379        

root    31144 29297  0 13:35 pts/2    00:00:00 grep redis

[root@www ~]# redis-cli -h 192.168.88.131-p 26379

192.168.88.131:26379> 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=mymaster,status=ok,address=192.168.88.131:6381,slaves=2,sentinels=1

192.168.88.131:26379> SENTINEL slavesmymaster

1) 1) "name"

   2) "192.168.88.131:6379"

   3) "ip"

   4) "192.168.88.131"

   5) "port"

   6) "6379"

   7) "runid"

   8) "ad19279760f61cc6bb1a6aacae509172b07da6ff"

   9) "flags"

  10) "slave"

  11) "link-pending-commands"

  12) "0"

  13) "link-refcount"

  14) "1"

  15) "last-ping-sent"

  16) "0"

  17) "last-ok-ping-reply"

  18) "620"

  19) "last-ping-reply"

  20) "620"

  21) "down-after-milliseconds"

  22) "5000"

  23) "info-refresh"

  24) "4726"

  25) "role-reported"

  26) "slave"

  27) "role-reported-time"

  28) "125225"

  29) "master-link-down-time"

  30) "0"

  31) "master-link-status"

  32) "ok"

  33) "master-host"

  34) "192.168.88.131"

  35) "master-port"

  36) "6381"

  37) "slave-priority"

  38) "100"

  39) "slave-repl-offset"

  40) "22217"

2) 1) "name"

   2) "192.168.88.131:6380"

   3) "ip"

   4) "192.168.88.131"

   5) "port"

   6) "6380"

   7) "runid"

   8) "708b690b500040a221da8f1388a1ebc4b5ae5b77"

   9) "flags"

  10) "slave"

  11) "link-pending-commands"

  12) "0"

  13) "link-refcount"

  14) "1"

  15) "last-ping-sent"

  16) "0"

  17) "last-ok-ping-reply"

  18) "297"

  19) "last-ping-reply"

  20) "297"

  21) "down-after-milliseconds"

  22) "5000"

  23) "info-refresh"

  24) "7278"

  25) "role-reported"

  26) "slave"

  27) "role-reported-time"

  28) "318454"

  29) "master-link-down-time"

  30) "0"

  31) "master-link-status"

  32) "ok"

  33) "master-host"

  34) "192.168.88.131"

  35) "master-port"

  36) "6381"

  37) "slave-priority"

  38) "100"

  39) "slave-repl-offset"

  40) "22060"

192.168.88.131:26379>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值