连接到cassandra群集时出错

lh80um4z  于 2021-06-13  发布在  Cassandra
关注(0)|答案(1)|浏览(597)

我正在部署一个metrictank,以cassandra集群作为后端,使用docker compose文件:

version: '2'

services:
  metrictank0:
    hostname: metrictank0
    image: grafana/metrictank
    expose:
     - 6060
    ports:
     - "2003:2003"
    environment:
      WAIT_HOSTS: cassandra-seed:9042
      WAIT_TIMEOUT: 3000
      MT_CASSANDRA_CREATE_KEYSPACE: "true"
      MT_CASSANDRA_IDX_CREATE_KEYSPACE: "true"
      MT_CLUSTER_BIND_ADDR: "metrictank0:7946"
      MT_CLUSTER_MODE: shard
      MT_CLUSTER_PRIMARY_NODE: "true"
      MT_INSTANCE: metrictank0
      MT_LOG_LEVEL: info
    links:
     - cassandra-seed:9042

  metrictank-q0:
    hostname: metrictank-q0
    image: grafana/metrictank
    expose:
     - 6060
    environment:
      WAIT_HOSTS: metrictank0:6060
      WAIT_TIMEOUT: 3000
      MT_CARBON_IN_ENABLED: "false"
      MT_CASSANDRA_ENABLED: "false"
      MT_CASSANDRA_IDX_ENABLED: "false"
      MT_KAFKA_MDM_IN_ENABLED: "false"
      MT_KAFKA_CLUSTER_ENABLED: "false"
      MT_CLUSTER_BIND_ADDR: "metrictank-q0:7946"
      MT_CLUSTER_MODE: query
      MT_CLUSTER_PEERS: metrictank0,metrictank1
      MT_CLUSTER_PRIMARY_NODE: "false"
      MT_INSTANCE: metrictank-q0
      MT_LOG_LEVEL: info
      MT_CLUSTER_GOSSIP_SETTLE_PERIOD: "10s"
    links:
     - metrictank0

  cassandra-seed:
    hostname: cassandra
    image: cassandra
    ports:
     - "9042:9042"
    environment:
      - "CASSANDRA_CLUSTER_NAME=MyCluster"

# needed for setting up custom cluster name

      - "CASSANDRA_DC=datacenter1"
      - "CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch"

# restart: always

  cassandra1:
    hostname: cassandra
    image: cassandra
    environment:
      - "CASSANDRA_SEEDS=cassandra-seed"
      - "CASSANDRA_CLUSTER_NAME=MyCluster"

# needed for setting up custom cluster name

      - "CASSANDRA_DC=datacenter1"
      - "CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch"
    depends_on:
      - cassandra-seed

# restart: always

  cassandra2:
    hostname: cassandra
    image: cassandra
    environment:
      - "CASSANDRA_SEEDS=cassandra-seed"
      - "CASSANDRA_CLUSTER_NAME=MyCluster"

# needed for setting up custom cluster name

      - "CASSANDRA_DC=datacenter2"
      - "CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch"
    depends_on:
      - cassandra-seed

# restart: always

  graphite:
    hostname: graphite
    image: raintank/graphite-mt
    ports:
     - "8080:80"
    environment:
      GRAPHITE_CLUSTER_SERVERS: metrictank-q0:6060
      GRAPHITE_STATSD_HOST: statsdaemon
      SINGLE_TENANT: "true"
      WSGI_PROCESSES: 4
      WSGI_THREADS: 25

  statsdaemon:
    hostname: statsdaemon
    image: raintank/statsdaemon
    ports:
     - "8125:8125/udp"

但是metrictank docker在运行了几秒钟后停止了,它的日志显示:

2020/06/15 12:48:14 waiting for cassandra-seed:9042 to become up...
2020/06/15 12:48:17 cassandra-seed:9042 is up. maintained connection for 3 seconds!
2020-06-15 12:48:17.217 [INFO] logging level set to 'info'
2020-06-15 12:48:17.218 [INFO] Metrictank starting. version: v0.13.1 - runtime: go1.11.4
2020/06/15 12:48:17 gocql: dns error: lookup cassandra on 127.0.0.11:53: no such host
2020-06-15 12:48:17.221 [ERROR] cassandra_store: failed to create cassandra session. gocql: unable to create session: failed to resolve any of the provided hostnames
2020-06-15 12:48:17.222 [FATAL] failed to initialize cassandra backend store. gocql: unable to create session: failed to resolve any of the provided hostnames

所以metrictank可以连接到cassandra docker,但不能连接到gocql。有人能帮我解决这个问题吗。

wmtdaxz3

wmtdaxz31#

我认为每个cassandra节点都应该有唯一的主机名。 cassandra1 , cassandra-2 以及 cassandra-seed 似乎有相同的主机名。

相关问题