Skip to content
Franklin Wise edited this page Mar 1, 2015 · 4 revisions

Notes on consul.io

Nodes use gossip protocol to communicate with each other in a distributed fashion.

Default Ports

  'dns'      => 8600,
  'http'     => 8500,
  'rpc'      => 8400,
  'serf_lan' => 8301,
  'serf_wan' => 8302,
  "server"   => 8300,

Agents

  • agent installed on every machine
  • agent can function as server or client
  • every agent runs (listening on 127.0.0.1 as the default):
  • DNS Server
  • Http Server
  • Rpc Server
  • every agent needs to be spoon fed at least one other agent IP to get started, except servers have extra requirement
  • each agent can declare what services the machine it is hosted on offers, this information is queryable by local DNS or HTTP on each other server

Clients

Throw Away Example - Start a client (172.20.20.11), joined to an existing server (172.20.20.10)

consul agent -data-dir /tmp/consul -node=n2 -bind=172.20.20.11 -config-dir=/etc/consul.d -join=172.20.20.10
  • data-dir : is where the files are stored
  • node : the name of the node, defaults to hostname if not specified (can not have a dot in the name because of dns)
  • config-dir : where to look for both the agent config and the service configs
  • join : says the name of another node to spoon feed getting started
  • bind : what nic ip to bind to (there are other options to bind to a device interface instead of ip)

Servers

  • servers require quorum, like zookeeper
  • prod servers have either 3 (survives 1 node fail) or 5 (survives 2 node failure)
  • strongly consistent like zookeeper CP
  • servers participate in leader elections and require some trickery to get up and going
$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -node=n1 -bind=172.20.20.10 -config-dir /etc/consul.d
  • server : enables the agent to act as a server that participates in leader election etc
  • bootstrap-expect : communicates how many servers are expected so that leader election waits for this many servers before electing a leader
  • other settings are the same meaning as the client

DNS - dig

$ dig @127.0.0.1 -p 8600 web.service.consul SRV
  • where web is a named service

Consul members

$ consul members

views the status, ips and names of all agents

Multiple Datacenters

  • natively supports multiple datacenters
  • uses optimized gossip protocol across regions

Health Checks

  • you can write your own health checks that can be run by the agents to determine node availability

Web UI

  • Consul comes with a client side modern js web site that can be hosted on any webserver, but by default is hosted internally.

Clone this wiki locally