192.168.110.100
192.168.110.101
192.168.110.102
192.168.110.103
192.168.110.100
启动多个Redis sentinel服务,构成Redis sentinel集群
192.168.110.101
启动Redis服务,设置成主节点
192.168.110.102
启动Redis服务,设置成192.168.110.101的从节点
192.168.110.103
启动Redis服务,设置成192.168.110.101的从节点
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
# stop accepting writes if it appears to be not connected with at least
# a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
# master if the replication link is lost for a relatively small amount of
# time. You may want to configure the replication backlog size (see the next
# sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
#
# 主从同步。通过 slaveof 配置来实现Redis实例的备份。
# 注意,这里是本地从远端复制数据。也就是说,本地可以有不同的数据库文件、绑定不同的IP、监听不同的端口。
#
# slaveof <masterip> <masterport>
slaveof 192.168.110.101 6379
[lizhiwei@localhost bin]$ ./redis-server
./redis-server redis.conf
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.110.102,port=6379,state=online,offset=659,lag=1
slave1:ip=192.168.110.103,port=6379,state=online,offset=659,lag=0
master_repl_offset:659
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:658
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.101
master_port:6379
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:701
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
# Replication
role:slave
master_host:192.168.110.101
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_repl_offset:715
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
port 26379
# sentinel announce-ip <ip>
# sentinel announce-port <port>
dir /tmp
################################# master001 #################################
sentinel monitor master001 192.168.110.101 6379 2
# sentinel auth-pass <master-name> <password>
sentinel down-after-milliseconds master001 30000
sentinel parallel-syncs master001 1
sentinel failover-timeout master001 180000
# sentinel notification-script <master-name> <script-path>
# sentinel client-reconfig-script <master-name> <script-path>
# 可以配置多个master节点
################################# master002 #################################
./redis-sentinel sentinel001.conf
./redis-sentinel sentinel002.conf
./redis-sentinel sentinel003.conf
[7743] 01 Oct 06:20:38.162 # Sentinel runid is ba6c42e1accc31290e11d5876275e1562564295d
[7743] 01 Oct 06:20:38.162 # +monitor master master001 192.168.110.101 6379 quorum 2
[7743] 01 Oct 06:20:39.110 * +slave slave 192.168.110.102:6379 192.168.110.102 6379 @ master001 192.168.110.101 6379
[7743] 01 Oct 06:20:39.111 * +slave slave 192.168.110.103:6379 192.168.110.103 6379 @ master001 192.168.110.101 6379
[7743] 01 Oct 06:25:07.595 * +sentinel sentinel 192.168.110.100:36379 192.168.110.100 36379 @ master001 192.168.110.101 6379
[7743] 01 Oct 06:26:11.170 * +sentinel sentinel 192.168.110.100:46379 192.168.110.100 46379 @ master001 192.168.110.101 6379
[7795] 01 Oct 06:25:05.538 # Sentinel runid is 52c14768b15837fb601b26328acf150c6bd30682
[7795] 01 Oct 06:25:05.538 # +monitor master master001 192.168.110.101 6379 quorum 2
[7795] 01 Oct 06:25:06.505 * +slave slave 192.168.110.102:6379 192.168.110.102 6379 @ master001 192.168.110.101 6379
[7795] 01 Oct 06:25:06.515 * +slave slave 192.168.110.103:6379 192.168.110.103 6379 @ master001 192.168.110.101 6379
[7795] 01 Oct 06:25:07.557 * +sentinel sentinel 192.168.110.100:26379 192.168.110.100 26379 @ master001 192.168.110.101 6379
[7795] 01 Oct 06:26:11.168 * +sentinel sentinel 192.168.110.100:46379 192.168.110.100 46379 @ master001 192.168.110.101 6379
[7828] 01 Oct 06:26:09.076 # Sentinel runid is c8509594be4a36660b2122b3b81f4f74060c9b04
[7828] 01 Oct 06:26:09.076 # +monitor master master001 192.168.110.101 6379 quorum 2
[7828] 01 Oct 06:26:10.063 * +slave slave 192.168.110.102:6379 192.168.110.102 6379 @ master001 192.168.110.101 6379
[7828] 01 Oct 06:26:10.071 * +slave slave 192.168.110.103:6379 192.168.110.103 6379 @ master001 192.168.110.101 6379
[7828] 01 Oct 06:26:11.516 * +sentinel sentinel 192.168.110.100:26379 192.168.110.100 26379 @ master001 192.168.110.101 6379
[7828] 01 Oct 06:26:11.674 * +sentinel sentinel 192.168.110.100:36379 192.168.110.100 36379 @ master001 192.168.110.101 6379
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
Could not connect to Redis at 192.168.110.101:6379: Connection refused
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:29128
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.110.102,port=6379,state=online,offset=30456,lag=1
master_repl_offset:30456
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:30455
[lizhiwei@localhost bin]$
### 启动脚本,仍然使用默认配置
[lizhiwei@localhost bin]$ ./redis-server
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:57657
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:60751
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.110.102,port=6379,state=online,offset=63247,lag=1
slave1:ip=192.168.110.101,port=6379,state=online,offset=63247,lag=1
master_repl_offset:63393
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:63392
[lizhiwei@localhost bin]$
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:184231
master_link_down_since_seconds: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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:184231
master_link_down_since_seconds:52
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
Could not connect to Redis at 192.168.110.103:6379: Connection refused
原文:http://www.cnblogs.com/LiZhiW/p/4851631.html