单台服务器实现redis-sentinel集群

下面是开发环境、测试环境,单台服务器搭建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 &

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值