前期准备:配置6个redis,同时进行好文件挂载。
1-6
mkdir -p /home/redis/myredis7001/data
mkdir -p /home/redis/myredis7001/conf
touch /home/redis/myredis7001/conf/redis.conf
Reids 集群搭建命令:
至少3主3从
创建6个redis示例对象每个服务器上创建两个。
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 7001:6379--name myredis7001 -v /home/redis/myredis7001/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/myredis7001/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 7002:6379 --name myredis7002 -v /home/redis/myredis7002/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/myredis7002/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 7003:6379 --name myredis7003 -v /home/redis/myredis7003/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/myredis7003/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 7004:6379 --name myredis7004 -v /home/redis/myredis7004/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/myredis7004/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 7005:6379 --name myredis7005 -v /home/redis/myredis7005/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/myredis7005/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 7006:6379 --name myredis7006 -v /home/redis/myredis7006/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/myredis7006/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
redis.conf的文件内容
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#bind 127.0.0.1
protected-mode no
port 6379
tcp-backlog 511
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 30
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 ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
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 yes
appendfilename "appendonly.aof"
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-max-len 128
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
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
创建集群:
docker exec -it myredis7001 \
redis-cli --cluster create \
124.223.201.237:7001 120.76.118.111:7003 121.40.227.209:7005 \
124.223.201.237:7002 120.76.118.111:7004 121.40.227.209:7006 \
--cluster-replicas 1