Consul从服务器清空回复

时间:2017-07-07 23:38:07

标签: docker consul

我试图启动并运行一个consul服务器群集。我有3个dockerized consul服务器正在运行,但我无法访问Web UI,HTTP API和DNS。

$ docker logs net-sci_discovery-service_consul_1
==> WARNING: Expect Mode enabled, expecting 3 servers
==> Starting Consul agent...
==> Consul agent running!
           Version: 'v0.8.5'
           Node ID: 'ccd38897-6047-f8b6-be1c-2aa0022a1483'
         Node name: 'consul1'
        Datacenter: 'dc1'
            Server: true (bootstrap: false)
       Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600)
      Cluster Addr: 172.20.0.2 (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false

==> Log data will now stream in as it occurs:

    2017/07/07 23:24:07 [INFO] raft: Initial configuration (index=0): []
    2017/07/07 23:24:07 [INFO] raft: Node at 172.20.0.2:8300 [Follower] entering Follower state (Leader: "")
    2017/07/07 23:24:07 [INFO] serf: EventMemberJoin: consul1 172.20.0.2
    2017/07/07 23:24:07 [INFO] consul: Adding LAN server consul1 (Addr: tcp/172.20.0.2:8300) (DC: dc1)
    2017/07/07 23:24:07 [INFO] serf: EventMemberJoin: consul1.dc1 172.20.0.2
    2017/07/07 23:24:07 [INFO] consul: Handled member-join event for server "consul1.dc1" in area "wan"
    2017/07/07 23:24:07 [INFO] agent: Started DNS server 127.0.0.1:8600 (tcp)
    2017/07/07 23:24:07 [INFO] agent: Started DNS server 127.0.0.1:8600 (udp)
    2017/07/07 23:24:07 [INFO] agent: Started HTTP server on 127.0.0.1:8500
    2017/07/07 23:24:09 [INFO] serf: EventMemberJoin: consul2 172.20.0.3
    2017/07/07 23:24:09 [INFO] consul: Adding LAN server consul2 (Addr: tcp/172.20.0.3:8300) (DC: dc1)
    2017/07/07 23:24:09 [INFO] serf: EventMemberJoin: consul2.dc1 172.20.0.3
    2017/07/07 23:24:09 [INFO] consul: Handled member-join event for server "consul2.dc1" in area "wan"
    2017/07/07 23:24:10 [INFO] serf: EventMemberJoin: consul3 172.20.0.4
    2017/07/07 23:24:10 [INFO] consul: Adding LAN server consul3 (Addr: tcp/172.20.0.4:8300) (DC: dc1)
    2017/07/07 23:24:10 [INFO] consul: Found expected number of peers, attempting bootstrap: 172.20.0.2:8300,172.20.0.3:8300,172.20.0.4:8300
    2017/07/07 23:24:10 [INFO] serf: EventMemberJoin: consul3.dc1 172.20.0.4
    2017/07/07 23:24:10 [INFO] consul: Handled member-join event for server "consul3.dc1" in area "wan"
    2017/07/07 23:24:14 [ERR] agent: failed to sync remote state: No cluster leader
    2017/07/07 23:24:17 [WARN] raft: Heartbeat timeout from "" reached, starting election
    2017/07/07 23:24:17 [INFO] raft: Node at 172.20.0.2:8300 [Candidate] entering Candidate state in term 2
    2017/07/07 23:24:17 [INFO] raft: Election won. Tally: 2
    2017/07/07 23:24:17 [INFO] raft: Node at 172.20.0.2:8300 [Leader] entering Leader state
    2017/07/07 23:24:17 [INFO] raft: Added peer 172.20.0.3:8300, starting replication
    2017/07/07 23:24:17 [INFO] raft: Added peer 172.20.0.4:8300, starting replication
    2017/07/07 23:24:17 [INFO] consul: cluster leadership acquired
    2017/07/07 23:24:17 [INFO] consul: New leader elected: consul1
    2017/07/07 23:24:17 [WARN] raft: AppendEntries to {Voter 172.20.0.3:8300 172.20.0.3:8300} rejected, sending older logs (next: 1)
    2017/07/07 23:24:17 [WARN] raft: AppendEntries to {Voter 172.20.0.4:8300 172.20.0.4:8300} rejected, sending older logs (next: 1)
    2017/07/07 23:24:17 [INFO] raft: pipelining replication to peer {Voter 172.20.0.3:8300 172.20.0.3:8300}
    2017/07/07 23:24:17 [INFO] raft: pipelining replication to peer {Voter 172.20.0.4:8300 172.20.0.4:8300}
    2017/07/07 23:24:18 [INFO] consul: member 'consul1' joined, marking health alive
    2017/07/07 23:24:18 [INFO] consul: member 'consul2' joined, marking health alive
    2017/07/07 23:24:18 [INFO] consul: member 'consul3' joined, marking health alive
    2017/07/07 23:24:20 [INFO] agent: Synced service 'consul'
    2017/07/07 23:24:20 [INFO] agent: Synced service 'messaging-service-kafka'
    2017/07/07 23:24:20 [INFO] agent: Synced service 'messaging-service-zookeeper'


$ curl http://127.0.0.1:8500/v1/catalog/service/consul
curl: (52) Empty reply from server
dig @127.0.0.1 -p 8600 consul.service.consul

; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p 8600 consul.service.consul
; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached


$ dig @127.0.0.1 -p 8600 messaging-service-kafka.service.consul

; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p 8600 messaging-service-kafka.service.consul
; (1 server found)
;; global options: +cmd
;; connection timed out; no servers could be reached

我无法通过HTTP API注册我的服务;上面显示的那些是在容器启动时使用配置脚本注册的。

这是我的docker-compose.yml

version: '2'
services:
  consul1:
    image: "consul:latest"
    container_name: "net-sci_discovery-service_consul_1"
    hostname: "consul1"
    ports:
      - "8400:8400"
      - "8500:8500"
      - "8600:8600"
    volumes:
      - ./etc/consul.d:/etc/consul.d
    command: "agent -server -ui -bootstrap-expect 3 -config-dir=/etc/consul.d -bind=0.0.0.0"
  consul2:
    image: "consul:latest"
    container_name: "net-sci_discovery-service_consul_2"
    hostname: "consul2"
    command: "agent -server -join=consul1"
    links:
      - "consul1"
  consul3:
    image: "consul:latest"
    container_name: "net-sci_discovery-service_consul_3"
    hostname: "consul3"
    command: "agent -server -join=consul1"
    links:
      - "consul1"

我对码头工人和领事都比较新。我已经浏览了网络,上面的选项是我对所需内容的理解。对前进方向的任何建议都会非常受欢迎。

修改

docker container ps -all的结果:

$ docker container ps --all
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                                                                                            NAMES
e0a1c3bba165        consul:latest            "docker-entrypoint..."   38 seconds ago      Up 36 seconds       8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp                                                       net-sci_discovery-service_consul_3
7f05555e81e0        consul:latest            "docker-entrypoint..."   38 seconds ago      Up 36 seconds       8300-8302/tcp, 8500/tcp, 8301-8302/udp, 8600/tcp, 8600/udp                                                       net-sci_discovery-service_consul_2
9e2dedaa224b        consul:latest            "docker-entrypoint..."   39 seconds ago      Up 38 seconds       0.0.0.0:8400->8400/tcp, 8301-8302/udp, 0.0.0.0:8500->8500/tcp, 8300-8302/tcp, 8600/udp, 0.0.0.0:8600->8600/tcp   net-sci_discovery-service_consul_1
27b34c5dacb7        messagingservice_kafka   "start-kafka.sh"         3 hours ago         Up 3 hours          0.0.0.0:9092->9092/tcp                                                                                           net-sci_messaging-service_kafka
0389797b0b8f        wurstmeister/zookeeper   "/bin/sh -c '/usr/..."   3 hours ago         Up 3 hours          22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp                                                               net-sci_messaging-service_zookeeper

修改

更新docker-compose.yml以包含端口的长格式:

version: '3.2'
services:
  consul1:
    image: "consul:latest"
    container_name: "net-sci_discovery-service_consul_1"
    hostname: "consul1"
    ports:
      - target: 8400
        published: 8400
        mode: host
      - target: 8500
        published: 8500
        mode: host
      - target: 8600
        published: 8600
        mode: host
    volumes:
      - ./etc/consul.d:/etc/consul.d
    command: "agent -server -ui -bootstrap-expect 3 -config-dir=/etc/consul.d -bind=0.0.0.0 -client=127.0.0.1"
  consul2:
    image: "consul:latest"
    container_name: "net-sci_discovery-service_consul_2"
    hostname: "consul2"
    command: "agent -server -join=consul1"
    links:
      - "consul1"
  consul3:
    image: "consul:latest"
    container_name: "net-sci_discovery-service_consul_3"
    hostname: "consul3"
    command: "agent -server -join=consul1"
    links:
      - "consul1"

1 个答案:

答案 0 :(得分:0)

Consul Web Gui page,确保您已使用-ui参数启动了代理。

  

UI位于与HTTP API相同的端口上的/ ui路径中   默认情况下,这是http://localhost:8500/ui

我确实看到8500在广播时映射到你的主机(0.0.0.0)。

同时检查(如this answer中所述)client_addr是否有帮助(至少用于测试)