Redis Cluster快速搭建
阿新 • • 發佈:2021-12-27
由於使用官方的redis映象在搭建起來容器之後還需要使用命令對啟動的多個容器建立主從關係, 從docker hub上發現了bitnami/redis-cluster這個神奇的映象.
根據bitnami/redis-cluster官方文件上提供的模板, 建立的叢集無法供docker外部呼叫. 通過提供的引數最終將埠成功映射了出來供外部使用;
version: "2" services: redis-node-0: image: docker.io/bitnami/redis-cluster:6.2 ports: - 7001:7001 # redis連線用埠 - 17001:17001 # redis之間訊息連線的埠 預設是redis連線埠+10000 restart: always environment: - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.10.248' # 當前redis使用的靜態IP(為了開放出來供外部使用這裡寫宿主機IP) - 'REDIS_PORT_NUMBER=7001' # 替換原始6379埠 - 'REDIS_CLUSTER_DYNAMIC_IPS=no' # 標明不使用動態IP - 'ALLOW_EMPTY_PASSWORD=yes' - 'REDIS_NODES=192.168.10.248:7001 192.168.10.248:7002 192.168.10.248:7003 192.168.10.248:7004 192.168.10.248:7005 192.168.10.248:7006' redis-node-1: image: docker.io/bitnami/redis-cluster:6.2 ports: - 7002:7002 - 17002:17002 restart: always environment: - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.10.248' - 'REDIS_PORT_NUMBER=7002' - 'REDIS_CLUSTER_DYNAMIC_IPS=no' - 'ALLOW_EMPTY_PASSWORD=yes' - 'REDIS_NODES=192.168.10.248:7001 192.168.10.248:7002 192.168.10.248:7003 192.168.10.248:7004 192.168.10.248:7005 192.168.10.248:7006' redis-node-2: image: docker.io/bitnami/redis-cluster:6.2 ports: - 7003:7003 - 17003:17003 restart: always environment: - 'ALLOW_EMPTY_PASSWORD=yes' - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.10.248' - 'REDIS_CLUSTER_DYNAMIC_IPS=no' - 'REDIS_PORT_NUMBER=7003' - 'REDIS_NODES=192.168.10.248:7001 192.168.10.248:7002 192.168.10.248:7003 192.168.10.248:7004 192.168.10.248:7005 192.168.10.248:7006' redis-node-3: image: docker.io/bitnami/redis-cluster:6.2 ports: - 7004:7004 - 17004:17004 restart: always environment: - 'ALLOW_EMPTY_PASSWORD=yes' - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.10.248' - 'REDIS_CLUSTER_DYNAMIC_IPS=no' - 'REDIS_PORT_NUMBER=7004' - 'REDIS_NODES=192.168.10.248:7001 192.168.10.248:7002 192.168.10.248:7003 192.168.10.248:7004 192.168.10.248:7005 192.168.10.248:7006' redis-node-4: image: docker.io/bitnami/redis-cluster:6.2 ports: - 7005:7005 - 17005:17005 restart: always environment: - 'ALLOW_EMPTY_PASSWORD=yes' - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.10.248' - 'REDIS_CLUSTER_DYNAMIC_IPS=no' - 'REDIS_PORT_NUMBER=7005' - 'REDIS_NODES=192.168.10.248:7001 192.168.10.248:7002 192.168.10.248:7003 192.168.10.248:7004 192.168.10.248:7005 192.168.10.248:7006' redis-node-5: image: docker.io/bitnami/redis-cluster:6.2 ports: - 7006:7006 - 17006:17006 restart: always depends_on: - redis-node-0 - redis-node-1 - redis-node-2 - redis-node-3 - redis-node-4 environment: - 'ALLOW_EMPTY_PASSWORD=yes' - 'REDIS_CLUSTER_ANNOUNCE_IP=192.168.10.248' - 'REDIS_CLUSTER_DYNAMIC_IPS=no' - 'REDIS_PORT_NUMBER=7006' - 'REDIS_CLUSTER_REPLICAS=1' - 'REDIS_NODES=192.168.10.248:7001 192.168.10.248:7002 192.168.10.248:7003 192.168.10.248:7004 192.168.10.248:7005 192.168.10.248:7006' - 'REDIS_CLUSTER_CREATOR=yes'