Cluster configuration requires a minimum of three machines, then I have three virtual machines, three virtual machines installed the same Redis environment
IP respectively:
192.168.1.78 (Redis Sentinel cluster monitoring)
192.168.1.62 (Redis Master)
192.168.1.68 (Redis slave)
Redis configuration:
Master configuration file: Modify Bind
Bind 127.0.0.1 192.168.1.62daemonize Yes the rest of the default can be
From the configuration file:
Bind 127.0.0.1 192.168.1.68daemonize yesslave-read-only yesslaveof 192.168.1.62 6379
Note: The main difference between Redis configuration master and slave is that one more slaveof xxxxxxxx
Launcher and slave Redis
[[email protected] ~]# netstat-luntp|grep redis-servertcp 0 0 192.168.1.62:6379 0.0.0.0:* LISTEN 1980/redis-server 1 tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1980/redis-server 1
[[email protected] ~]# netstat-lnutp|grep redis-servertcp 0 0 192.168.1.68:6379 0.0.0.0:* LISTEN 1958/redis-server 1 tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
View from Redis information
[Email protected] conf]# redis-cli-h 192.168.1.68 info replication# replicationrole:slavemaster_host : 192.168.1.62master_port:6379master_link_status:upmaster_last_io_seconds_ago:1master_sync_in_progress:0slave_ Repl_offset:394966slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_active : 0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
View Master Redis Information
[Email protected] conf]# redis-cli-h 192.168.1.62info replication# replicationrole:masterconnected_slaves:1slave0: Ip=192.168.1.68,port=6379,state=online,offset=400791,lag=0master_repl_offset:400791repl_backlog_active:1repl_ backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_histlen:400790
Configuring the Redis Sentinel Cluster monitoring service 1. Add a redis Sentinel configuration file
#mymasterport 26379sentinel Monitor MyMaster 192.168.1.62 6379 1sentinel down-after-milliseconds mymaster 5000sentinel Failover-timeout mymaster 900000sentinel parallel-syncs mymaster 1#mymaster02 (multiple sets of master-slave Redis monitoring can be added)
It is now possible to verify:
[Email protected] ~]# redis-cli-h 192.168.1.62 shutdown
[Email protected] ~]# redis-cli-h 192.168.1.68 info replication# replicationrole:masterconnected_slaves:1slave0:ip= 192.168.1.62,port=6379,state=online,offset=19598,lag=0master_repl_offset:19598repl_backlog_active:1repl_ backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_histlen:19597
[Email protected] ~]# service Redis startstarting Redis server ... [Email protected] ~]# redis-cli-h 192.168.1.62 info replication# replicationrole:slavemaster_host:192.168.1.68master _port:6379master_link_status:upmaster_last_io_seconds_ago:1master_sync_in_progress:0slave_repl_offset : 23421slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_active:0repl_ backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
[Email protected] ~]# redis-cli-h 192.168.1.68 shutdown
[[email protected] bin]# redis-sentinel/app/server/redis/conf/sentinel.conf &8785:X Jul 01:06:25.531 # + Sdown Master MyMaster 192.168.1.68 63798785:x Jul 01:06:25.531 # +odown Master mymaster 192.168.1.68 6379 #quorum 1/187 85:x Jul 01:06:25.532 # +new-epoch 68785:x Jul 01:06:25.532 # +try-failover Master MyMaster 192.168.1.68 63798785:x 01:06:25.642 # +vote-for-leader 0efacb4ca1b82a290a86a15cf1229f23896c2fe5 68785:x Jul 01:06:25.642 # +elected-le Ader Master MyMaster 192.168.1.68 63798785:x Jul 01:06:25.642 # +failover-state-select-slave Master MyMaster 192.168.1. 63798785:x Jul 01:06:25.705 # +selected-slave slave 192.168.1.62:6379 192.168.1.62 6379 @ mymaster 192.168.1.68 6379 8785:x Jul 01:06:25.705 * +failover-state-send-slaveof-noone slave 192.168.1.62:6379 192.168.1.62 6379 @ mymaster 192.1 68.1.68 63798785:x-Jul 01:06:25.771 * +failover-state-wait-promotion slave 192.168.1.62:6379 192.168.1.62 6379 @ mymast ER 192.168.1.68 63798785:x 07Jul 01:06:26.759 # +promoted-slave slave 192.168.1.62:6379 192.168.1.62 6379 @ mymaster 192.168.1.68 63798785:x Jul 01: 06:26.759 # +failover-state-reconf-slaves Master mymaster 192.168.1.68 63798785:x Jul 01:06:26.760 # +failover-end Mast Er mymaster 192.168.1.68 63798785:x Jul 01:06:26.760 # +switch-master MyMaster 192.168.1.68 6379 192.168.1.62 63798785: X 01:06:26.760 * +slave slave 192.168.1.68:6379 192.168.1.68 6379 @ mymaster 192.168.1.62 63798785:x-Jul 01:06:3 1.837 # +sdown slave 192.168.1.68:6379 192.168.1.68 6379 @ mymaster 192.168.1.62 63798788:x Jul 01:06:47.530 * Increase d Maximum number of open files to 10032 (it is originally set to 1024x768). 8788:x-Jul 01:06:47.531 # Creating Server TCP L Istening socket *:26379:bind:address already in use
[Email protected] bin]# redis-cli-h 192.168.1.62-p 6379 info replication# replicationrole:masterconnected_slaves:0 Master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog _histlen:0
[Email protected] ~]# service Redis startstarting Redis server ...
[Email protected] bin]# redis-cli-h 192.168.1.68-p 6379 info replication# replicationrole:slavemaster_host : 192.168.1.62master_port:6379master_link_status:upmaster_last_io_seconds_ago:1master_sync_in_progress:0slave_ repl_offset:2999slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_active:0 repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
[[email protected] ~]# service Redis stopstopping ... Waiting for Redis to shutdown ... Redis stopped[[email protected] bin]# 8785:x Jul 01:12:45.927 # +sdown Master mymaster 192.168.1.62 63798785:x 07 Jul 01:12:45.927 # +odown Master mymaster 192.168.1.62 6379 #quorum 1/18785:x Jul 01:12:45.927 # +new-epoch 78785:x 07 Jul 01:12:45.927 # +try-failover Master mymaster 192.168.1.62 63798785:x Jul 01:12:45.968 # +vote-for-leader 0EFACB4CA1 B82a290a86a15cf1229f23896c2fe5 78785:x-Jul 01:12:45.968 # +elected-leader master MyMaster 192.168.1.62 63798785:x L 01:12:45.968 # +failover-state-select-slave Master mymaster 192.168.1.62 63798785:x Jul 01:12:46.068 # +selected-slav e slave 192.168.1.68:6379 192.168.1.68 6379 @ mymaster 192.168.1.62 63798785:x Jul 01:12:46.068 * +failover-state-send- Slaveof-noone slave 192.168.1.68:6379 192.168.1.68 6379 @ mymaster 192.168.1.62 63798785:x Jul 01:12:46.140 * +failover -state-wait-promotion slave 192.168.1.68:6379 192.168.1.6379 @ mymaster 192.168.1.62 63798785:x Jul 01:12:47.082 # +promoted-slave slave 192.168.1.68:6379 192.168.1.68 637 9 @ mymaster 192.168.1.62 63798785:x Jul 01:12:47.082 # +failover-state-reconf-slaves master MyMaster 192.168.1.62 6379 8785:x Jul 01:12:47.082 # +failover-end Master mymaster 192.168.1.62 63798785:x Jul 01:12:47.082 # +switch-master my Master 192.168.1.62 6379 192.168.1.68 63798785:x Jul 01:12:47.086 * +slave slave 192.168.1.62:6379 192.168.1.62 6379 @ MyMaster 192.168.1.68 63798785:x Jul 01:12:52.102 # +sdown slave 192.168.1.62:6379 192.168.1.62 6379 @ mymaster 192.168 .1.68 6379
[Email protected] bin]# redis-cli-h 192.168.1.68-p 6379 info replication# replicationrole:masterconnected_slaves:0 Master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog _histlen:0
[Email protected] ~]# service Redis startstarting Redis server ...
[Email protected] bin]# 8785:x Jul 01:13:53.100 #-sdown slave 192.168.1.62:6379 192.168.1.62 6379 @ mymaster 192.168. 1.68 63798785:x-Jul 01:14:03.127 * +convert-to-slave slave 192.168.1.62:6379 192.168.1.62 6379 @ mymaster 192.168.1.68 6379
[Email protected] bin]# redis-cli-h 192.168.1.62-p 6379 info replication# replicationrole:slavemaster_host : 192.168.1.68master_port:6379master_link_status:upmaster_last_io_seconds_ago:1master_sync_in_progress:0slave_ repl_offset:1859slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_active:0 repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
==============================================================================================
[[email protected] conf]# egrep-v "(^#|^$)" 6379.conf bind 127.0.0.1 192.168.1.62protected-mode yesport 6379tcp-backlog 511timeout 300tcp-keepalive 0daemonize yessupervised nopidfile "/var/run/redis_6379.pid" loglevel Noticelogfile "/app/server/redis/logs/6379.log" databases 16save 1save 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename "Dump.rdb" dir "/" Slave-serve-stale-data yesslave-read-only Yesrepl-diskless-sync Norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100maxmemory-policy volatile-lruappendonly noappendfilename " Appendonly.aof "Appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated Yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" Hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing Yesclient-output-buffer-limit Normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit PubSub 32MB 8MB 60hz 10aof-rewrite-incremental-fsync Yes
[[email protected] ~]# egrep-v "(^#|^$)"/app/server/redis/conf/6379.conf bind 127.0.0.1 192.168.1.68protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile "/ Var/run/redis_6379.pid "LogLevel noticelogfile"/app/server/redis/logs/6379.log "Databases 16save 1save 10save 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename "Dump.rdb" dir "/" Slave-serve-stale-data yesslave-read-only Yesrepl-diskless-sync Norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof" Appendfsync Everysecno-appendfsync-on-rewrite Noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated Yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" Hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-Entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit Normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32MB 8MB 60hz 10aof-rewrite-incremental-fsync yesslaveof 192.168.1.62 6379# Note that the most important thing in the main switchover is that the system will add the previous line to the Redis configuration file (which is from the server) must be the primary outage before the master-slave switch occurs.
Cluster Management for Redis master-slave switching