使用docker compose和docker swarm的Redis集群 [英] Redis cluster with docker swarm using docker compose

查看:870
本文介绍了使用docker compose和docker swarm的Redis集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在学习docker及其所有优点,例如集群和撰写。我的目的是在docker swarm中创建Redis集群。

I'm just learning docker and all of its goodness like swarm and compose. My intention is to create a Redis cluster in docker swarm.

这是我的撰写文件-

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

如果我添加网络:-主机然后没有一个容器启动,如果我将其删除,则容器启动,但是当我尝试连接时会抛出类似 CLUSTERDOWN Hash slot的错误消息

If I add the network: - host then none of the containers start, if I remove it then the containers start but when I try to connect it throws an error like 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


推荐答案

对于任何为此感到苦恼的人都无法通过 docker-compose.yml 还没有。请参考启动Redis群集#79 。唯一的方法是获取正在运行Redis的所有节点的IP地址和端口,然后在任何群集节点中运行此命令。

For anyone struggling with this unfortunately this can't be done via docker-compose.yml yet. Refer to this issue Start Redis cluster #79. The only way to do this is by getting the IP address and ports of all the nodes that are running Redis and then running this command in any of the swarm nodes.

# Gives you all the command help
docker run --rm -it thesobercoder/redis-trib 

# This creates all master nodes
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 slaves nodes. Note that this requires at least six nodes running master
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

这篇关于使用docker compose和docker swarm的Redis集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆