码迷,mamicode.com
首页 > 其他好文 > 详细

Docker部署redis主从+读写分离+哨兵

时间:2021-05-24 07:00:10      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:imu   priority   events   add   dev   logo   ble   需要   -name   

Docker部署redis主从+读写分离+哨兵

 前段时间给第三方部署了redis主从+读写分离+哨兵集群环境,开发想验证程序代码的稳定性,需要在测试环境搭建一套该redis系统,便用Docker持久化部署一套即可,用完即删!

一、规划

hostname
          ip
       port
         server
master.redis
   172.18.215.10
56379、46379
redis(master)(sentinel)
slave1.redis
   172.18.215.15
56379、46379
redis(slave)(sentinel)
slave2.redis
   172.18.215.16
56379、46379
redis(slave)(sentinel)
[root@dev templates]# tree /data/redis_test/
/data/redis_test/
├── data
├── redis.conf
└── sentinel.conf

二、redis集群(三台服务器一样的)

redis.conf
bind 0.0.0.0
protected-mode no
port 56379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel verbose
logfile stdout
databases 256
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 ./
requirepass 123456
masterauth 123456
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
maxmemory 2GB
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
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
slaveof 172.18.215.10 56379
slave-serve-stale-data yes
slave-read-only yes
#--------master.redis这台服务器不需要上面三行-------------#
min-replicas-to-write 1
min-replicas-max-lag 10

 

# docker run -d --privileged=true -p 56379:56379 -v /data/redis_test/redis.conf:/etc/redis/redis.conf -v /data/redis_test/data:/data --name redis_test redis:5.0.12 redis-server /etc/redis/redis.conf --appendonly yes

 

三、哨兵集群(三台服务器一样的)

sentinel.conf
port 46379
dir "/data"
logfile "sentinel-46379.log"
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 172.18.215.10 56379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 10000
sentinel failover-timeout mymaster 60000

 

# docker run -d -p 46379:46379 -v /data/redis_test/sentinel.conf:/etc/redis/sentinel.conf -v /data/redis_test/data:/data --name sentinel_test redis:5.0.12 redis-sentinel /etc/redis/sentinel.conf
 

四、验证

 
root@730228741a69:/data# redis-cli -a 123456 -h 172.18.215.10 -p 56379 info Replication
# Replication
role:master
connected_slaves:2
min_slaves_good_slaves:2
slave0:ip=172.18.215.15,port=56379,state=online,offset=1468523,lag=1
slave1:ip=172.18.215.16,port=56379,state=online,offset=1468384,lag=1
master_replid:50b3af6d1ca4bfe9ed7d501169df2b761513d94b
master_replid2:5f9e9940b5a42536de82211bebcb20e9a1b17cbd
master_repl_offset:1468523
second_repl_offset:120071
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:419948
repl_backlog_histlen:1048576
root@730228741a69:/data# redis-cli -a 123456 -h 172.18.215.10 -p 46379 info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=172.18.215.10:56379,slaves=2,sentinels=4

 

Docker部署redis主从+读写分离+哨兵

标签:imu   priority   events   add   dev   logo   ble   需要   -name   

原文地址:https://www.cnblogs.com/user-sunli/p/14759814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!