#创建redis配置文件for port in $(seq 1 6); \do \mkdir -p /mydata/redis/node-${port}/conftouch /mydata/redis/node-${port}/conf/redis.confcat << EOF >>/mydata/redis/node-${port}/conf/redis.confport 6379bind 0.0.0.0cluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000cluster-announce-ip 172.38.0.1${port}cluster-announce-port 6379cluster-announce-bus-port 16379appendonly yesEOFdone#编写docker-compose.yml文件version: '2'services: redis-cluster-6371: image: redis:5.0.7 container_name: node-1 #节点名称 ports: - 6371:6379 - 16371:16379 volumes: - /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf - /mydata/redis/node-1/log:/var/log/redis - /mydata/redis/node-1/data:/data command: sh -c "redis-server /etc/redis/redis.conf" environment: # 设置时区为上海,否则时间会有问题 - TZ=Asia/Shanghai networks: redis: ipv4_address: 172.38.0.11 redis-cluster-6372: image: redis:5.0.7 container_name: node-2 #节点名称 ports: - 6372:6379 - 16372:16379 volumes: - /mydata/redis/node-2/conf/redis.conf:/etc/redis/redis.conf - /mydata/redis/node-2/log:/var/log/redis - /mydata/redis/node-2/data:/data command: sh -c "redis-server /etc/redis/redis.conf" environment: # 设置时区为上海,否则时间会有问题 - TZ=Asia/Shanghai networks: redis: ipv4_address: 172.38.0.12 redis-cluster-6373: image: redis:5.0.7 container_name: node-3 #节点名称 ports: - 6373:6379 - 16373:16379 volumes: - /mydata/redis/node-3/conf/redis.conf:/etc/redis/redis.conf - /mydata/redis/node-3/log:/var/log/redis - /mydata/redis/node-3/data:/data command: sh -c "redis-server /etc/redis/redis.conf" environment: # 设置时区为上海,否则时间会有问题 - TZ=Asia/Shanghai networks: redis: ipv4_address: 172.38.0.13 redis-cluster-6374: image: redis:5.0.7 container_name: node-4 #节点名称 ports: - 6374:6379 - 16374:16379 volumes: - /mydata/redis/node-4/conf/redis.conf:/etc/redis/redis.conf - /mydata/redis/node-4/log:/var/log/redis - /mydata/redis/node-4/data:/data command: sh -c "redis-server /etc/redis/redis.conf" environment: # 设置时区为上海,否则时间会有问题 - TZ=Asia/Shanghai networks: redis: ipv4_address: 172.38.0.14 redis-cluster-6375: image: redis:5.0.7 container_name: node-5 #节点名称 ports: - 6375:6379 - 16375:16379 volumes: - /mydata/redis/node-5/conf/redis.conf:/etc/redis/redis.conf - /mydata/redis/node-5/log:/var/log/redis - /mydata/redis/node-5/data:/data command: sh -c "redis-server /etc/redis/redis.conf" environment: # 设置时区为上海,否则时间会有问题 - TZ=Asia/Shanghai networks: redis: ipv4_address: 172.38.0.15 redis-cluster-6376: image: redis:5.0.7 container_name: node-6 #节点名称 ports: - 6376:6379 - 16376:16379 volumes: - /mydata/redis/node-6/conf/redis.conf:/etc/redis/redis.conf - /mydata/redis/node-6/log:/var/log/redis - /mydata/redis/node-6/data:/data command: sh -c "redis-server /etc/redis/redis.conf" environment: # 设置时区为上海,否则时间会有问题 - TZ=Asia/Shanghai networks: redis: ipv4_address: 172.38.0.16networks: redis: ipam: config: - subnet: 172.38.0.0/16 gateway: 172.38.0.1#将docker-compose文件移动到linux服务器上,使用docker-compose up #命令运行,会自动的下载并运行六个Redis。#配置redis集群docker run --rm -it --network redis_redis zvelo/redis-trib create --replicas 1 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379