Docker-compose一键安装redis集群

vim redis.conf

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 ./
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
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

appendonly yes
bind 0.0.0.0
protected-mode no
port 6379
cluster-enabled yes
cluster-node-timeout 15000
masterauth mypassword
requirepass mypassword 

docker-compose.yml

version: '3'

services:
 redis1:
  image: redis:5.0.3
  restart: always  
  #container_name: redis1
  #network_mode: host  #需要为host模式
  volumes:
   - ./7001/config/redis.conf:/etc/redis/redis.conf
   - ./7001/data:/data
  environment:
   - TZ=Asia/Shanghai
   - LANG=en_US.UTF-8
  ports:
    - '7001:7001'     #服务端口
    - '17001:17001'   #集群端口
  command: ["redis-server", "/etc/redis/redis.conf"]
  privileged: true    #环境变量
  

 redis2:
  image: redis:5.0.3
  #network_mode: host
  restart: always
  volumes:
   - ./7002/config/redis.conf:/etc/redis/redis.conf
   - ./7002/data:/data
  environment:
   - TZ=Asia/Shanghai
   - LANG=en_US.UTF-8
  ports:
    - '7002:7002'     #服务端口
    - '17002:17002'   #集群端口
  command: ["redis-server", "/etc/redis/redis.conf"]
  privileged: true    #环境变量

 redis3:
  image: redis:5.0.3
  #network_mode: host
  restart: always
  volumes:
   - ./7003/config/redis.conf:/etc/redis/redis.conf
   - ./7003/data:/data
  environment:
   - TZ=Asia/Shanghai
   - LANG=en_US.UTF-8
  ports:
    - '7003:7003'     #服务端口
    - '17003:17003'   #集群端口
  command: ["redis-server", "/etc/redis/redis.conf"]
  privileged: true    #环境变量

 redis4:
  image: redis:5.0.3
  #network_mode: host
  restart: always
  volumes:
   - ./7004/config/redis.conf:/etc/redis/redis.conf
   - ./7004/data:/data
  environment:
   - TZ=Asia/Shanghai
   - LANG=en_US.UTF-8
  ports:
    - '7004:7004'     #服务端口
    - '17004:17004'   #集群端口
  command: ["redis-server", "/etc/redis/redis.conf"]
  privileged: true    #环境变量

 redis5:
  image: redis:5.0.3
  #network_mode: host
  restart: always
  volumes:
   - ./7005/config/redis.conf:/etc/redis/redis.conf
   - ./7005/data:/data
  environment:
   - TZ=Asia/Shanghai
   - LANG=en_US.UTF-8
  ports:
    - '7005:7005'     #服务端口
    - '17005:17005'   #集群端口
  command: ["redis-server", "/etc/redis/redis.conf"]
  privileged: true    #环境变量

 redis6:
  image: redis:5.0.3
  #network_mode: host
  restart: always
  volumes:
   - ./7006/config/redis.conf:/etc/redis/redis.conf
   - ./7006/data:/data
  environment:
   - TZ=Asia/Shanghai
   - LANG=en_US.UTF-8
  ports:
    - '7006:7006'     #服务端口
    - '17006:17006'   #集群端口
  command: ["redis-server", "/etc/redis/redis.conf"]
  privileged: true    #环境变量

vim cluster.sh

#!/bin/bash
BASEPATH='/usr/local/docker/redis'
IP=192.168.66.101
docker pull redis:5.0.3
for i in `seq 7001 7006`
do
 mkdir -p $BASEPATH/${i}/data/
 mkdir -p $BASEPATH/${i}/config/
 cp ./redis.conf $BASEPATH/${i}/config/
 sed -i "s/port 6379/port ${i}/" $BASEPATH/${i}/config/redis.conf
 echo "cluster-announce-ip 192.168.66.101" >> $BASEPATH/${i}/config/redis.conf
 echo "cluster-announce-port ${i}" >> $BASEPATH/${i}/config/redis.conf
 echo "cluster-announce-bus-port 1${i}" >> $BASEPATH/${i}/config/redis.conf
done
cp docker-compose.yml redis-cli $BASEPATH/
cd $BASEPATH
docker-compose up -d
chmod u+x redis-cli
./redis-cli -h $IP -p 7001 --cluster create $IP:7001 $IP:7002 $IP:7003 $IP:7004 $IP:7005 $IP:7006 --cluster-replicas 1

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值