Skip to content

Instantly share code, notes, and snippets.

@nacyot
Last active October 14, 2016 01:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nacyot/514b904f7ae569e801e4 to your computer and use it in GitHub Desktop.
Save nacyot/514b904f7ae569e801e4 to your computer and use it in GitHub Desktop.

Consul

Consul

  • Service Discovery
  • Failure Detection
  • Multi Datacenter
  • Key/Value Storage

Architecture

http://i.imgur.com/WhpMFFa.png

Install

$ mkdir consul
$ wget https://dl.bintray.com/mitchellh/consul/0.3.1_linux_amd64.zip
$ unzip -d consul 0.3.1_linux_amd64.zip
$ ln -s /opt/consul/consul /usr/local/

Server

$ consul agent -server -bootstrap -client=172.17.0.31 -dc=local -node=consul1 -data-dir=/root/consul -ui-dir=/opt/consul/dist -bind=172.17.0.31

Client

$ consul agent -dc=local -node=consul2 -data-dir=/tmp/consul2 -bind=172.17.0.32 -join=172.17.0.31

HTTP

$ curl -s http://172.17.0.62:8500/v1/catalog/nodes | jq .
$ curl -s http://172.17.0.62:8500/v1/health/node/consul2 | jq .

DNS

  • <node>.node.<datacenter>.<domain>
  • <tag>.<service>.service.<datacenter>.<domain>
$ dig @172.17.0.62 -p 8600 node.consul any
$ dig @172.17.0.62 -p 8600 consul.service.consul any

Service

$ curl -s http://172.17.0.62:8500/v1/health/checks/database | jq .
$ cat services/database.json 
{
  "service": {
    "name": "database",
    "tags": [ "mysql" ],
    "port": 5000,
    "check": {
      "script": "<Some Awesome Script>"
      "interval": "10s"
    }
  }
}

$ cat services/unicorn.json 
{
  "service": {
    "name": "unicorn",
    "tags": [ "ver1" ],
    "port": 3000
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment