Redis群集与码头工人使用码头工作者组成

时间:2018-04-23 10:47:41

标签: docker docker-compose docker-swarm alpine

我只是在学习码头工作者以及所有的善良,比如swarm和compose。我的目的是在docker swarm中创建一个Redis集群。

这是我的撰写文件 -

version: '3'

services:
  redis:
    image: redis:alpine
    command: ["redis-server","--appendonly yes","--cluster-enabled yes","--cluster-node-timeout 60000","--cluster-require-full-coverage no"]
    deploy:
      replicas: 5
      restart_policy:
        condition: on-failure
    ports:
      - 6379:6379
      - 16379:16379

networks:
  host:
    external: true

如果我添加network: - host,则没有任何容器启动,如果我将其删除,那么容器会启动,但是当我尝试连接它时会抛出类似CLUSTERDOWN Hash slot not served的错误。

规格 -

Windows 10

Docker Swarm Nodes -
2 Virtual Box VMs running Alpine Linux 3.7.0 with two networks

VirtualBox VM Network - 
eth0 - NAT
eth1 - VirtualBox Host-only network

Docker running inside the above VMs - 
17.12.1-ce

3 个答案:

答案 0 :(得分:1)

对于任何挣扎于此的人,不幸的是,这还不能通过docker-compose.yml来完成。请参阅此问题Start Redis cluster #79。唯一的方法是获取运行Redis的所有节点的IP地址和端口,然后在任何一个群集节点中运行此命令。

docker run --rm -it thesobercoder/redis-trib --Gives you all the command help
docker run --rm -it thesobercoder/redis-trib create 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000 --This creates all master nodes
docker run --rm -it thesobercoder/redis-trib create --replicas 1 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000 172.17.8.104:7000 172.17.8.105:7000 172.17.8.106:7000 --This creates slaves nodes. Note that this requires at least six nodes running master.

答案 1 :(得分:1)

答案 2 :(得分:0)

这似乎对我有用,来自here的网络配置:

version: '3.6'

services:
  redis:
    image: redis:5.0.3
    command:
      - "redis-server"
      - "--cluster-enabled yes"
      - "--cluster-config-file nodes.conf"
      - "--cluster-node-timeout 5000"
      - "--appendonly yes"
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
    networks:
      hostnet: {}

networks:
  hostnet:
    external: true
    name: host

然后运行例如:echo yes | docker run -i --rm --entrypoint redis-cli redis:5.0.3 --cluster create 1.2.3.4{1,2,3}:6379 --cluster-replicas 0

明显替换您的IP。