赞
踩
redis配置文件中不支持系统变量,所以我们自己基于alpine自己做个镜像
protected-mode no tcp-backlog 511 timeout 0 tcp-keepalive 300 loglevel notice save 3600 1 stop-writes-on-bgsave-error no rdbcompression yes rdbchecksum no dbfilename _dump.rdb appendonly no bind 0.0.0.0 cluster-enabled yes cluster-node-timeout 15000 cluster-require-full-coverage no activerehashing yes port REDIS_PORT cluster-announce-port REDIS_PORT cluster-announce-bus-port 1REDIS_PORT maxmemory 2gb maxmemory-policy allkeys-lru maxclients 10000 dir /home/data
#!/bin/sh
mkdir -p /home/data
sed -i "s/REDIS_PORT/${REDIS_PORT}/g" /etc/redis/redis.conf
sed -i "s/MS_PS/${MS_PS}/g" /etc/redis/redis.conf
sed -i "s/PASSWORD/${PASSWORD}/g" /etc/redis/redis.conf
/usr/bin/redis-server /etc/redis/redis.conf
FROM alpine:3.13.1
MAINTAINER xusiwang@wondertek.com.cn
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && apk update && apk add redis
COPY redis.conf /etc/redis/redis.conf
COPY start.sh /home
RUN chmod +x /home/start.sh
ENV REDIS_PORT=6379
EXPOSE 6379
#CMD ["redis-server","/etc/redis/redis.conf"]
ENTRYPOINT /home/start.sh
docker build -t redis:6.0 .
version: '3' networks: bestv: driver: bridge ipam: config: - subnet: 172.23.0.0/16 services: redis1: image: redis:6.0 restart: unless-stopped hostname: redis1 container_name: redis1 ports: - 7001:7001 environment: REDIS_PORT: 7001 privileged: true volumes: - ./redis/7001/data:/home/data networks: bestv: ipv4_address: 172.23.0.2 redis2: image: redis:6.0 restart: unless-stopped hostname: redis2 container_name: redis2 ports: - 7002:7002 environment: REDIS_PORT: 7002 privileged: true volumes: - ./redis/7002/data:/home/data depends_on: - redis1 networks: bestv: ipv4_address: 172.23.0.3 redis3: image: redis:6.0 restart: unless-stopped hostname: redis3 container_name: redis3 ports: - 7003:7003 environment: REDIS_PORT: 7003 privileged: true volumes: - ./redis/7003/data:/home/data depends_on: - redis1 - redis2 networks: bestv: ipv4_address: 172.23.0.4 redis4: image: redis:6.0 restart: unless-stopped hostname: redis4 container_name: redis4 ports: - 7004:7004 environment: REDIS_PORT: 7004 privileged: true volumes: - ./redis/7004/data:/home/data depends_on: - redis1 - redis2 - redis3 networks: bestv: ipv4_address: 172.23.0.5 redis5: image: redis:6.0 restart: unless-stopped hostname: redis5 container_name: redis5 ports: - 7005:7005 environment: REDIS_PORT: 7005 privileged: true volumes: - ./redis/7005/data:/home/data depends_on: - redis1 - redis2 - redis3 - redis4 networks: bestv: ipv4_address: 172.23.0.6 redis6: image: redis:6.0 restart: unless-stopped hostname: redis6 container_name: redis6 ports: - 7006:7006 environment: REDIS_PORT: 7006 privileged: true volumes: - ./redis/7006/data:/home/data depends_on: - redis1 - redis2 - redis3 - redis4 - redis5 networks: bestv: ipv4_address: 172.23.0.7
docker-compose -f redis-clu.yml up -d
redis对主机名的支持不太友好,所以我们换成ip方式
docker exec -it redis-1 sh
redis-cli --cluster create 172.23.0.2:7001 172.23.0.3:7002 172.23.0.4:7003 172.23.0.5:7004 172.23.0.6:7005 172.23.0.7:7006 --cluster-replicas 1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。