redis6.09 集群安装(docker-compose)

1. docker-Compose构成

1.1 docker-redis-cluster文件夹准备明细

序号目录或文件作用

1./docker-redis-cluster总配置目录

2./docker-redis-cluster/docker-compose.yaml部署文件

3./docker-redis-cluster/redis/Dockerfile镜像配置文件

4./docker-redis-cluster/redis/redis.confredis配置文件

5./docker-redis-cluster/redis/start.shredis启动脚本

1.2 docker-compose.yaml

version:'3'networks:redisnet:driver:bridgeipam:config:-subnet:10.0.0.0/24services:redis-cluster:image:redis:6.0.9command:redis-cli-p6379--clustercreate10.0.0.10:637910.0.0.11:638010.0.0.12:638110.0.0.13:638210.0.0.14:638310.0.0.15:6384--cluster-replicas1--cluster-yesdepends_on:-redis-1-redis-2-redis-3-redis-4-redis-5-redis-6networks:redisnet:ipv4_address:10.0.0.2redis-1:build:./redisimage:redis-cluster-nodeenvironment:X_REDIS_PORT:6379networks:redisnet:ipv4_address:10.0.0.10ports:-6379:6379redis-2:image:redis-cluster-nodeenvironment:X_REDIS_PORT:6380networks:redisnet:ipv4_address:10.0.0.11ports:-6380:6379redis-3:image:redis-cluster-nodeenvironment:X_REDIS_PORT:6381networks:redisnet:ipv4_address:10.0.0.12ports:-6381:6379redis-4:image:redis-cluster-nodeenvironment:X_REDIS_PORT:6382networks:redisnet:ipv4_address:10.0.0.13ports:-6382:6379redis-5:image:redis-cluster-nodeenvironment:X_REDIS_PORT:6383networks:redisnet:ipv4_address:10.0.0.14ports:-6383:6379redis-6:image:redis-cluster-nodeenvironment:X_REDIS_PORT:6384networks:redisnet:ipv4_address:10.0.0.15ports:-6384:6379复制代码

1.3 配套文件Dockerfile

FROMredis:6.0.9MAINTAINERLu Dongsheng RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtimeRUNecho'Asia/Tokyo'>/etc/timezone# Dependent tool installationRUN apt-get updateRUN apt-get install -y gettext-base && apt-get install -y apt-utilsCOPY redis.conf /etc/redis/redis.conf.templateCOPY start.sh /start.shENTRYPOINT["/bin/bash","/start.sh"]复制代码

1.4 配套文件redis.conf

port $X_REDIS_PORTcluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000appendonly yes复制代码

1.5 配套文件start.sh

envsubst'$X_REDIS_PORT:$X_REDIS_PORT'< /etc/redis/redis.conf.template > /etc/redis/redis.confredis-server /etc/redis/redis.conf复制代码

2. 部署

2.1 构建并启动所有容器

$ docker-compose up --build -dCreating network"docker-redis-cluster_redisnet"with driver"bridge"Building redis-1Step 1/9 : FROM redis:6.0.9 ---> 6060df96cef3Step 2/9 : MAINTAINER Lu Dongsheng ---> Using cache ---> e20c87bd3cefStep 3/9 : RUN ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime ---> Using cache ---> f7e6083e6fb3Step 4/9 : RUNecho'Asia/Tokyo'>/etc/timezone ---> Using cache ---> ef5aa8bb6c22Step 5/9 : RUN apt-get update ---> Using cache ---> 362e0274a91cStep 6/9 : RUN apt-get install -y gettext-base && apt-get install -y apt-utils ---> Using cache ---> 5fbf8d44d5bdStep 7/9 : COPY redis.conf /etc/redis/redis.conf.template ---> Using cache ---> ed05230e6323Step 8/9 : COPY start.sh /start.sh ---> Using cache ---> 5e253f787309Step 9/9 : ENTRYPOINT ["/bin/bash","/start.sh"] ---> Using cache ---> 51f8529def29Successfully built 51f8529def29Successfully tagged redis-cluster-node:latestCreating docker-redis-cluster_redis-4_1 ...doneCreating docker-redis-cluster_redis-1_1 ...doneCreating docker-redis-cluster_redis-2_1 ...doneCreating docker-redis-cluster_redis-6_1 ...doneCreating docker-redis-cluster_redis-3_1 ...doneCreating docker-redis-cluster_redis-5_1 ...doneCreating docker-redis-cluster_redis-cluster_1 ...done复制代码

2.2 查看容器

$ docker psCONTAINER ID  IMAGE                COMMAND                  CREATED          STATUS          PORTS                    NAMESd638dc1a8109  redis-cluster-node"/bin/bash /start.sh"37 seconds ago  Up 34 seconds  0.0.0.0:6384->6379/tcp  docker-redis-cluster_redis-6_132188654eedf  redis-cluster-node"/bin/bash /start.sh"37 seconds ago  Up 34 seconds  0.0.0.0:6380->6379/tcp  docker-redis-cluster_redis-2_17050bae336f1  redis-cluster-node"/bin/bash /start.sh"37 seconds ago  Up 34 seconds  0.0.0.0:6379->6379/tcp  docker-redis-cluster_redis-1_141bbf8d74f6c  redis-cluster-node"/bin/bash /start.sh"37 seconds ago  Up 34 seconds  0.0.0.0:6382->6379/tcp  docker-redis-cluster_redis-4_1f55577e67af7  redis-cluster-node"/bin/bash /start.sh"37 seconds ago  Up 34 seconds  0.0.0.0:6381->6379/tcp  docker-redis-cluster_redis-3_160bf1405fd3e  redis-cluster-node"/bin/bash /start.sh"37 seconds ago  Up 35 seconds  0.0.0.0:6383->6379/tcp  docker-redis-cluster_redis-5_1复制代码

2.3 日志

为了更好地了解如何创建群集,请检查其中一个容器日志。

$ docker logs docker-redis-cluster_redis-1_1$ docker logs docker-redis-cluster_redis-2_1$ docker logs docker-redis-cluster_redis-3_1$ docker logs docker-redis-cluster_redis-4_1$ docker logs docker-redis-cluster_redis-5_1$ docker logs docker-redis-cluster_redis-6_1复制代码

2.4 连接到Master其中之一

$ dockerexec-it docker-redis-cluster_redis-1_1 redis-cli -c -p 6379127.0.0.1:6379> cluster nodesb42c322538ca174995277ced98534a4253dd6948 10.0.0.13:6382@16382 slave d0429fa1e0ba3ece8898f7bd84969839d2d3c516 0 1611892729662 3 connectede5396fcd18de2126b1cc725a83308b944575704f 10.0.0.10:6379@16379 myself,master - 0 1611892729000 1 connected 0-546005f0201fbb705d0701c9c0da9175a7c22e25e030 10.0.0.11:6380@16380 master - 0 1611892729000 2 connected 5461-10922d0429fa1e0ba3ece8898f7bd84969839d2d3c516 10.0.0.12:6381@16381 master - 0 1611892728157 3 connected 10923-163831bf41a4c744c880ba7aaf70ae770f51cc139bedf 10.0.0.14:6383@16383 slave e5396fcd18de2126b1cc725a83308b944575704f 0 1611892728000 1 connectedb5d420d8461fcee9f73172752fc508c41c46a870 10.0.0.15:6384@16384 slave 05f0201fbb705d0701c9c0da9175a7c22e25e030 0 1611892730162 2 connected复制代码

2.5 查看集群槽位

127.0.0.1:6379> cluster slots1) 1) (integer) 0  2) (integer) 5460  3) 1)"10.0.0.10"2) (integer) 6379      3)"e5396fcd18de2126b1cc725a83308b944575704f"4) 1)"10.0.0.14"2) (integer) 6383      3)"1bf41a4c744c880ba7aaf70ae770f51cc139bedf"2) 1) (integer) 5461  2) (integer) 10922  3) 1)"10.0.0.11"2) (integer) 6380      3)"05f0201fbb705d0701c9c0da9175a7c22e25e030"4) 1)"10.0.0.15"2) (integer) 6384      3)"b5d420d8461fcee9f73172752fc508c41c46a870"3) 1) (integer) 10923  2) (integer) 16383  3) 1)"10.0.0.12"2) (integer) 6381      3)"d0429fa1e0ba3ece8898f7bd84969839d2d3c516"4) 1)"10.0.0.13"2) (integer) 6382      3)"b42c322538ca174995277ced98534a4253dd6948"复制代码

2.6 清空

$  docker-compose downStopping docker-redis-cluster_redis-4_1 ...doneStopping docker-redis-cluster_redis-6_1 ...doneStopping docker-redis-cluster_redis-2_1 ...doneStopping docker-redis-cluster_redis-5_1 ...doneStopping docker-redis-cluster_redis-1_1 ...doneStopping docker-redis-cluster_redis-3_1 ...doneRemoving docker-redis-cluster_redis-cluster_1 ...doneRemoving docker-redis-cluster_redis-4_1      ...doneRemoving docker-redis-cluster_redis-6_1      ...doneRemoving docker-redis-cluster_redis-2_1      ...doneRemoving docker-redis-cluster_redis-5_1      ...doneRemoving docker-redis-cluster_redis-1_1      ...doneRemoving docker-redis-cluster_redis-3_1      ...doneRemoving network docker-redis-cluster_redisnet复制代码

参考:https://itsmetommy.com/2018/05/24/docker-compose-redis-cluster/

你可能感兴趣的:(redis6.09 集群安装(docker-compose))