Cassandra 与 docker swarm,“无法查找主机 cassandra-seed”

Posted

技术标签:

【中文标题】Cassandra 与 docker swarm,“无法查找主机 cassandra-seed”【英文标题】:Cassandra with docker swarm, "couldn't lookup host cassandra-seed" 【发布时间】:2018-02-01 21:37:39 【问题描述】:

docker-compose.yaml

   version: '3'
    services:  
      cassandra-seed:
        image: cassandra:latest
        deploy:
          replicas: 1
        ports:
          - "9042"
          - "7199"   
          - "9160"
          - "7000"
          - "7001"
        networks:
          default:
        volumes:
          - ./data:/var/lib/cassandra/data

      cassandra-node-1:
        image: cassandra:latest
        deploy:
          replicas: 1
        command: /bin/bash -c "echo 'Waiting for seed node' && sleep 120 && /docker-entrypoint.sh cassandra -f"
        environment:
          - "CASSANDRA_SEEDS=cassandra-seed"
        ports:
          - "9042"
          - "7199"   
          - "9160"
          - "7000"
          - "7001"

        networks:
          default:
        depends_on:
          - "cassandra-seed"

      cassandra-node-2:
        image: cassandra:latest
        deploy:
          replicas: 1
        command: /bin/bash -c "echo 'Waiting for seed node' && sleep 120 && /docker-entrypoint.sh cassandra -f"
        environment:
          - "CASSANDRA_SEEDS=cassandra-seed"
        depends_on:
          - "cassandra-seed"
        ports:
          - "9042"
          - "7199"   
          - "9160"
          - "7000"
          - "7001"
        networks:
          default:

    networks:
      default:
        external:
          name: cassandra-net
    docker network create --scope swarm cassandra-net 将所有节点添加到 swarm 中 docker stack deploy --compose-file docker-compose.yml cassandra-cluster

WARN [main] 2018-02-01 21:32:07,965 SimpleSeedProvider.java:60 - 种子提供者无法查找主机 cassandra-seed

【问题讨论】:

一年多过去了,您找到解决该问题的方法了吗?使用docker-compose 时,我在扩展到三节点集群时遇到了同样的问题。奇怪的是,一个额外的节点工作正常。 【参考方案1】:
- "CASSANDRA_SEEDS=cassandra-seed"

这是您设置种子的地方。 cassandra docker 映像入口点期望此值是一个带有 IP 地址的逗号分隔列表。您将不得不以某种方式找到ips。我建议阅读service discovery。然后使用自定义入口点创建自己的 docker 映像,在其中通过解析 dns 来设置 CASSANDRA_SEEDS host 命令。您还可以为此创建自定义种子提供程序。

【讨论】:

【参考方案2】:

我觉得你不应该写

- "CASSANDRA_SEEDS=cassandra-seed"

试试这个:

CASSANDRA_SEEDS: "cassandra-seed"

另外,如果要创建集群,还必须使用“CASSANDRA_BROADCAST_ADDRESS”。

例如:

environment:
  CASSANDRA_BROADCAST_ADDRESS: cassandra-1

参考:https://dzone.com/articles/swarmweek-part-1-multi-host-cassandra-cluster-with https://forums.docker.com/t/cassandra-on-docker-swarm/27923/3

【讨论】:

以上是关于Cassandra 与 docker swarm,“无法查找主机 cassandra-seed”的主要内容,如果未能解决你的问题,请参考以下文章

sh 与领事的Docker机器Docker Swarm

Docker Swarm集群部署实战

Docker swarm 集群搭建

docker swarm (三):overlay与docker_gwbridge网络详解

Docker Swarm Mode简介与核心概念

Docker Manager for Docker Swarm deploy