sivachinnayan / consul-cluster-setup

setup consul cluster setup
MIT License
0 stars 0 forks source link

consul-cluster-setup

setup consul cluster setup

In Node two follow the below instructions

$sudo -s
$ echo '{"service": {"name": "web", "tags": ["rails"], "port": 80,
  "check": {"script": "curl localhost >/dev/null 2>&1", "interval": "10s"}}}' > /etc/consul.d/web.json 

$ echo '{"services":[{"id":"webservice-poll","name":"webservice-poll","tags":["poll"],"port":80,"checks":[{"name":"Sys check ","script":"some_scripts.sh param1 param2","interval":"5s","timeout":"1s"},{"name":"Check if service is alive","http":"http://localhost:80/checkservice","interval":"5s","timeout":"1s"},{"name":"HTTP on port 80","http":"http://localhost:80/","interval":"5s","timeout":"1s"},{"id":"check particular tcp port","name":"check a port","tcp":"localhost:3415","interval":"10s","timeout":"1s"}]}]}' > /etc/consul.d/checkbservice.json

Run Node1 as Server

$consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -node=agent-one -bind=172.20.20.10 -client=0.0.0.0 -config-dir /etc/consul.d/ -ui

Notes: Expose client = 0.0.0.0 inorder to accomplish port forwarding to localhost

Run Node2 as client and join to cluster

$consul agent --data-dir /tmp/consul -node=agent-two -bind=172.20.20.11 -config-dir /etc/consul.d/

Note

Join Node2 from node1

Login to machine one - ie, node

$vagrant ssh node1
node1@$consul members 
node1@$consul join 172.20.20.11

The join command will make the node join to cluster and election process happens to elect cluster leader.

Run Node3 as client and join to cluster

$consul agent --data-dir /tmp/consul -node=agent-three -bind=172.20.20.12 -config-dir /etc/consul.d/
$vagrant ssh node1
node1@$consul members 
node1@$consul join 172.20.20.12

** DNS Setup on localhost

localhostmachine@user$sudo apt-get install dnsmasq -y
localhostmachine@user$sudo -s
localhostmachine@user@echo "server=/consul/127.0.0.1#8600" > /etc/dnsmasq.d/10-consul
localhostmachine@user@sudo service dnsmasq restart
 * Restarting DNS forwarder and DHCP server dnsmasq                           [ OK ]