Redis是一个开源的内存数据结构存储系统,它可以用作数据库、缓存和消息代理,在分布式系统中,Redis集群可以提高数据的可用性和扩展性,本文将介绍如何使用Docker部署Redis集群。
环境准备
1、安装Docker:请参考Docker官方文档(https://docs.docker.com/engine/install/)安装适合您操作系统的Docker版本。
2、拉取Redis镜像:在命令行中执行以下命令,拉取官方提供的Redis镜像。
搭建Redis单节点
1、创建Redis配置文件:在本地创建一个名为redis.conf
的文件,添加以下内容:
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
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 ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-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 no
lua-time-limit 5000
slowlog-log-slower-than 100000
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 slave 256MB 64MB 60
client-output-bufferLimit minclients 1 maxclients autodeflate yes
hz 10
aofrewriteincrementalfsync yes
2、启动Redis单节点:在命令行中执行以下命令,启动Redis单节点。
docker run --name myredis -p 6379:6379 -v $(pwd)/redis.conf:/usr/local/etc/redis/redis.conf --rm redis:latest redis-server /usr/local/etc/redis/redis.conf --daemonize yes --port 6379 --bind 0.0.0.0 --protected-mode no --requirepass yourpassword --tlsdisable --tlsauth cacert.crt --tlsciphers HIGH:!aNULL:!MD5 --dbfilename dump.rdb --dir ./ --appendfilename "appendonly.aof" --appendfsync everysec --save "900 1" --save "300 10" --save "60 10000" --slaveof no --pidfile /var/run/redis_6379.pid --loglevel notice --logfile "" --databases 16 --always-show-logo yes --saveinfo returnerrors yes --slaveservesocket port=6380 --slavereadfrom socket=localhost:6379 --slavepriority priority=10 --slavepreservemaster yes --slavepreferredip srcip=127.127.1.1 --slavepreferredip srcip=::ffff:127.127.1.1 --slavepreferredip srcip=::ffff:127.127.1.2 --slavelistenip 127.127.1.156 --slavedns server=8.8.8.8,server=8.8.4.4 --dir "$(pwd)/6379_data" --replicaof no --cluster create IP=$(hostname):6380 IP=$(hostname):6381 IP=$(hostname):6382 IP=$(hostname):6383 IP=$(hostname):6384 IP=$(hostname):6385 IP=$(hostname):6386 IP=$(hostname):6387 IP=$(hostname):6388 IP=$(hostname):6389 --cluster-replicas 1 @masterip@@replicaip@@masterport@@replicaport@@masteralias@@replicaalias@ &>/dev/null & echo $! > cluster_id & exec cat cluster_id & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 & exec sleep infinity & exec tail \$(cat cluster_id) & exec kill %1 &exec exit;&exec cat cluster_id;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_id);&exec kill %1;&exec sleep infinity;&exec tail \$(cat cluster_server);--sentinel monitor mymaster mastername yourmastername host yourmasterip port yourmasterport quorum downafterseconds failovertimeout connectedslavesinsentinelstatesentinelfailover newstatesentinelupdatescript filesentinelupdatescript filesentinelparallelstartsec
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/143868.html