下面是开发环境、测试环境,单台服务器搭建redis-sentinel集群
Redis端口:6379、6380、6381
Sentinel端口:16379、16380、16381
直接拿下面的配置文件就可以跑起来。
安装redis4.0
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
tar xvf redis-4.0.10.tar.gz -C /app
cd /app/redis-4.0.10
make MALLOC=libc
cd src
make install
进入/app/redis-4.0.10,原有的redis.conf、sentinel.conf文件不要动,添加集群所需的文件redis1.conf、redis2.conf、redis3.conf、sentinel1.conf、sentinel2.conf、sentinel3.conf,各个文件配置如下。
redis1.conf
bind 127.0.0.1
protected-mode yes
port 6379
daemonize no
supervised systemd
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/app/redis-data/redis-master/redis.log"
databases 16
#always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir "/app/redis-data/redis-master"
#replica-serve-stale-data yes
#replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
#replica-priority 100
#lazyfree-lazy-eviction no
#lazyfree-lazy-expire no
#lazyfree-lazy-server-del no
#replica-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
#aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
#stream-node-max-bytes 4096
#stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
#client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
#dynamic-hz yes
aof-rewrite-incremental-fsync yes
#rdb-save-incremental-fsync yes
masterauth 123456
requirepass 123456
redis2.conf
bind 127.0.0.1
protected-mode yes
port 6380
daemonize yes
supervised systemd
pidfile /var/run/redis_6380.pid
loglevel notice
logfile "/app/redis-data/redis-slave1/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir "/app/redis-data/redis-slave1"
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
masterauth 123456
requirepass 123456
slaveof 127.0.0.1 6379
redis3.conf
bind 127.0.0.1
protected-mode yes
port 6381
daemonize yes
supervised systemd
pidfile /var/run/redis_6381.pid
loglevel notice
logfile "/app/redis-data/redis-slave2/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir "/app/redis-data/redis-slave2"
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
masterauth 123456
requirepass 123456
slaveof 127.0.0.1 6379
下面是sentinel的配置文件
sentinel1.conf
port 16379
daemonize yes
bind 172.11.26.205
logfile "/app/redis-data/redis-master/redis-sentinel.log"
sentinel myid 454634552802f3864f3477883933e7aa803e4808
sentinel monitor mymaster 172.11.26.205 6379 2
sentinel failover-timeout mymaster 10000
sentinel auth-pass mymaster Bluesea#redis?123
protected-mode yes
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
dir "/root"
sentinel leader-epoch mymaster 377
sentinel known-slave mymaster 172.11.26.205 6381
sentinel known-slave mymaster 172.11.26.205 6380
sentinel known-sentinel mymaster 172.11.26.205 26381 962a9cf6afa20726baf3d97d326ce87d0469c4ae
sentinel known-sentinel mymaster 172.11.26.205 26380 1e48ed185e5e514510029c6dad49320b793d41b6
sentinel current-epoch 377
sentinel2.conf
port 16380
daemonize yes
bind 172.11.26.205
logfile "/app/redis-data/redis-slave1/redis-sentinel.log"
sentinel myid 1e48ed185e5e514510029c6dad49320b793d41b6
sentinel monitor mymaster 172.11.26.205 6379 2
sentinel failover-timeout mymaster 10000
protected-mode yes
sentinel auth-pass mymaster Bluesea#redis?123
# Generated by CONFIG REWRITE
dir "/root"
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 381
sentinel known-slave mymaster 172.11.26.205 6381
sentinel known-slave mymaster 172.11.26.205 6380
sentinel known-sentinel mymaster 172.11.26.205 26381 962a9cf6afa20726baf3d97d326ce87d0469c4ae
sentinel known-sentinel mymaster 172.11.26.205 26379 454634552802f3864f3477883933e7aa803e4808
sentinel current-epoch 381
sentinel3.conf
port 16381
daemonize yes
bind 172.11.26.205
logfile "/app/redis-data/redis-slave2/redis-sentinel.log"
sentinel myid 962a9cf6afa20726baf3d97d326ce87d0469c4ae
sentinel monitor mymaster 172.11.26.205 6379 2
sentinel failover-timeout mymaster 10000
protected-mode yes
sentinel auth-pass mymaster Bluesea#redis?123
# Generated by CONFIG REWRITE
dir "/root"
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 383
sentinel known-slave mymaster 172.11.26.205 6380
sentinel known-slave mymaster 172.11.26.205 6381
sentinel known-sentinel mymaster 172.11.26.205 26379 454634552802f3864f3477883933e7aa803e4808
sentinel known-sentinel mymaster 172.11.26.205 26380 1e48ed185e5e514510029c6dad49320b793d41b6
sentinel current-epoch 383
redis启动脚本—-redis.sh
#!/bin/bash
nohup /app/redis-4.0.10/src/redis-server /app/redis-4.0.10/redis1.conf >output 2>&1 &
nohup /app/redis-4.0.10/src/redis-server /app/redis-4.0.10/redis2.conf >output 2>&1 &
nohup /app/redis-4.0.10/src/redis-server /app/redis-4.0.10/redis3.conf >output 2>&1 &
sentinel启动脚本—-sentinel.sh
#!/bin/bash
nohup /app/redis-4.0.10/src/redis-sentinel /app/redis-4.0.10/sentinel1.conf > output 2>&1 &
nohup /app/redis-4.0.10/src/redis-sentinel /app/redis-4.0.10/sentinel2.conf > output 2>&1 &
nohup /app/redis-4.0.10/src/redis-sentinel /app/redis-4.0.10/sentinel3.conf > output 2>&1 &