Public Repository

Last pushed: 9 months ago
Short Description
Short description is empty for this repo.
Full Description

Environment

We need to assgin those param when we start a consul container:

  1. NETWORK_INTERFACE:the newtwork interface name, such as "etho", we use the name to get Cluster Addr
  2. CONSUL_SERVER: Is server agent or not
  3. SERVER_NUMS: the consul cluster server agent numbers
  4. DATACENTER: the consul cluster datacenter name
  5. CLIENT_IP: the consul cluster client ip, in order to separate from other consul cluster
  6. CONSUL_NODENAME: the consul node name
  7. SERVER_IP: the consul cluster server ip, by the way, we can join to a consul cluster

Running consul as server

$ docker run -d --name test --net host \
             -e "NETWORK_INTERFACE=bond1.101" \
             -e "CONSUL_SERVER=true" \
             -e "SERVER_NUMS=1" \
             -e "DATACENTER=dc_manage" \   
             greedywolf/consul

$ docker logs test 
[Warnning] Not assign CLIENT_IP, default use 127.0.0.1 as consul Client Addr
[Warnning] Not assign CONSUL_NODENAME, default use hostname as consul nodename
==> WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode.
==> WARNING: Bootstrap mode enabled! Do not enable unless necessary
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
         Node name: 'controller'
        Datacenter: 'dc_manage'
            Server: true (bootstrap: true)
       Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
      Cluster Addr: 10.20.101.1 (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
             Atlas: <disabled>

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

    2016/11/10 02:15:37 [INFO] raft: Node at 10.20.101.1:8300 [Follower] entering Follower state
    2016/11/10 02:15:37 [INFO] serf: EventMemberJoin: controller 10.20.101.1
    2016/11/10 02:15:37 [INFO] consul: adding LAN server controller (Addr: 10.20.101.1:8300) (DC: dc_manage)
    2016/11/10 02:15:37 [INFO] serf: EventMemberJoin: controller.dc_manage 10.20.101.1
    2016/11/10 02:15:37 [INFO] consul: adding WAN server controller.dc_manage (Addr: 10.20.101.1:8300) (DC: dc_manage)
    2016/11/10 02:15:37 [ERR] agent: failed to sync remote state: No cluster leader
    2016/11/10 02:15:39 [WARN] raft: Heartbeat timeout reached, starting election
    2016/11/10 02:15:39 [INFO] raft: Node at 10.20.101.1:8300 [Candidate] entering Candidate state
    2016/11/10 02:15:39 [INFO] raft: Election won. Tally: 1
    2016/11/10 02:15:39 [INFO] raft: Node at 10.20.101.1:8300 [Leader] entering Leader state
    2016/11/10 02:15:39 [INFO] consul: cluster leadership acquired
    2016/11/10 02:15:39 [INFO] consul: New leader elected: controller
    2016/11/10 02:15:39 [INFO] raft: Disabling EnableSingleNode (bootstrap)
    2016/11/10 02:15:39 [INFO] consul: member 'controller' joined, marking health alive

$ docker exec -it test consul members
Node        Address           Status  Type    Build  Protocol  DC
controller  10.20.101.1:8301  alive   server  0.6.3  2         dc_manage

Running consul as client

Just to assign the environment "CONSUL_SERVER=false". For example

$ docker run -d --name test --net host \
             -e "NETWORK_INTERFACE=bond1.101" \
             -e "CONSUL_SERVER=false" \
             -e "DATACENTER=dc_manage" \
             greedywolf/consul

$ docker exec -it test consul members
Node        Address           Status  Type    Build  Protocol  DC
controller  10.20.101.1:8301  alive   client  0.6.3  2         dc_manage
Docker Pull Command
Owner
greedywolf

Comments (0)