redis cluster的conf配置文件配置

master配置文件如下:

 1 bind 127.0.0.1
 2 port 6379
 3 tcp-backlog 511
 4 timeout 0
 5 tcp-keepalive 0
 6 loglevel notice
 7 logfile ""
 8 databases 16
 9 save 900 1
10 save 300 10
11 save 60 10000
12 stop-writes-on-bgsave-error yes
13 rdbcompression yes
14 rdbchecksum yes
15 dbfilename dump.rdb
16 dir ./
17 slave-serve-stale-data yes
18 slave-read-only yes
19 repl-diskless-sync no
20 repl-diskless-sync-delay 5
21 repl-disable-tcp-nodelay no
22 slave-priority 100
23 appendonly no
24 appendfilename "appendonly.aof"
25 appendfsync everysec
26 no-appendfsync-on-rewrite no
27 auto-aof-rewrite-percentage 100
28 auto-aof-rewrite-min-size 64mb
29 aof-load-truncated yes
30 lua-time-limit 5000
31 slowlog-log-slower-than 10000
32 slowlog-max-len 128
33 latency-monitor-threshold 0
34 notify-keyspace-events ""
35 hash-max-ziplist-entries 512
36 hash-max-ziplist-value 64
37 list-max-ziplist-size -2
38 list-compress-depth 0
39 set-max-intset-entries 512
40 zset-max-ziplist-entries 128
41 zset-max-ziplist-value 64
42 hll-sparse-max-bytes 3000
43 activerehashing yes
44 client-output-buffer-limit normal 0 0 0
45 client-output-buffer-limit slave 256mb 64mb 60
46 client-output-buffer-limit pubsub 32mb 8mb 60
47 hz 10
48 aof-rewrite-incremental-fsync yes
Master配置文件

slave配置文件如下:

 1 ################################## INCLUDES ###################################
 2 # include .\path\to\local.conf
 3 # include c:\path\to\other.conf
 4 ################################## NETWORK #####################################
 5 bind 127.0.0.1
 6 protected-mode yes
 7 port 6380
 8 tcp-backlog 511
 9 timeout 0
10 tcp-keepalive 0
11 ################################# GENERAL #####################################
12 loglevel notice
13 logfile ""
14 databases 16
15 ################################ SNAPSHOTTING  ################################
16 save 900 1
17 save 300 10
18 save 60 10000
19 stop-writes-on-bgsave-error yes
20 rdbcompression yes
21 rdbchecksum yes
22 dbfilename dump.rdb
23 dir ./
24 ################################# REPLICATION #################################
25 slaveof 127.0.0.1 6379
26 # masterauth <master-password>
27 slave-serve-stale-data yes
28 slave-read-only yes
29 repl-diskless-sync no
30 repl-diskless-sync-delay 5
31 repl-ping-slave-period 10
32 repl-timeout 60
33 repl-disable-tcp-nodelay no
34 repl-backlog-size 1mb
35 repl-backlog-ttl 3600
36 slave-priority 100
37 min-slaves-to-write 3
38 min-slaves-max-lag 10
39 ################################## SECURITY ###################################
40 # rename-command CONFIG ""
41 ################################### LIMITS ####################################
42 # maxclients 10000
43 # persistence-available [(yes)|no]
44 # maxmemory <bytes>
45 # maxmemory-policy noeviction
46 # maxmemory-samples 5
47 ############################## APPEND ONLY MODE ###############################
48 appendonly no
49 appendfilename "appendonly.aof"
50 # appendfsync always
51 appendfsync everysec
52 # appendfsync no
53 no-appendfsync-on-rewrite no
54 auto-aof-rewrite-percentage 100
55 auto-aof-rewrite-min-size 64mb
56 aof-load-truncated yes
57 ################################ LUA SCRIPTING  ###############################
58 lua-time-limit 5000
59 ################################ REDIS CLUSTER  ###############################
60 cluster-enabled no
61 # cluster-config-file nodes-6379.conf
62 # cluster-node-timeout 15000
63 # cluster-slave-validity-factor 10
64 # cluster-migration-barrier 1
65 # cluster-require-full-coverage yes
66 ################################## SLOW LOG ###################################
67 slowlog-log-slower-than 10000
68 ################################ LATENCY MONITOR ##############################
69 latency-monitor-threshold 0
70 ############################# EVENT NOTIFICATION ##############################
71 #  notify-keyspace-events Elg
72 #  notify-keyspace-events Ex
73 notify-keyspace-events ""
74 ############################### ADVANCED CONFIG ###############################
75 hash-max-ziplist-entries 512
76 hash-max-ziplist-value 64
77 list-max-ziplist-size -2
78 list-compress-depth 0
79 set-max-intset-entries 512
80 zset-max-ziplist-entries 128
81 zset-max-ziplist-value 64
82 hll-sparse-max-bytes 3000
83 activerehashing yes
84 client-output-buffer-limit normal 0 0 0
85 client-output-buffer-limit slave 256mb 64mb 60
86 client-output-buffer-limit pubsub 32mb 8mb 60
87 hz 10
88 aof-rewrite-incremental-fsync yes
slave配置文件

结果可以分别进入6379和6380的redis客户端进行查看:命令为 info Replication

 

 如果看到此处的role分别为master 和salve则说明现在已经基本配置成功了

 

使用哨兵模式,自动监视Master节点,当前挂掉后,自动将Slaver节点变为Master节点
       a) sentinel.conf配置文件,修改sentinel monitor host6379 127.0.0.1 6379 1,其它使用默认即可
           host6379 主机名称,随便起    主机IP 端口 1表示选举,某个slaver得到超过1票则成成为Master节点
       b) 启动sentinel: ./redis-sentinel ../sentinel.conf
 
6379 原来的Master节点重启后变成Slaver节点

另附几点声明:

  1. Master可读可写,Slaver只能读,不能写
  2. Master可以对应多个Slaver,但是数量越多压力越大,延迟就可能越严重
  3. Master写入后立即返回,几乎同时将写入异步同步到各个Slaver,所以基本上延迟可以忽略
  4. 可以通过slaveof no one命令将Slaver升级为Master(当Master挂掉时,手动将某个Slaver变为Master)
  5. 可以通过sentinel哨兵模式监控Master,当Master挂掉时自动选举Slaver变为Master,其它Slaver自动重连新的Master