sivachinnayan / consul-cluster-setup

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

How to join a third party node to Consul #10

Open sivachinnayan opened 8 years ago

sivachinnayan commented 8 years ago

How to join a third party node to Consul, Example. I want to join my localbox to consul running on local network. I can follow the below steps to acheive it.

siva@user1:~$ consul agent  -data-dir /tmp/consul-tmp -bind 192.168.10.86
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
         Node name: 'user1'
        Datacenter: 'dc1'
            Server: false (bootstrap: false)
       Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
      Cluster Addr: 192.168.10.86 (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
             Atlas: <disabled>

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

Join to Consul Server running on local network


siva@user1:/etc/consul.d$ consul join 192.168.10.47
Successfully joined cluster by contacting 1 nodes.
siva@usuer1:/etc/consul.d$ echo '{"service": {"name": "web", "tags": ["rails"], "port": 80,"check": {"script": "curl localhost >/dev/null 2>&1", "interval": "10s"}}}' > /etc/consul.d/web.json^C
siva@user1:/etc/consul.d$ consul members 
Node                   Address             Status  Type    Build  Protocol  DC
user1                 192.168.10.86:8301  alive   client  0.6.4  2         dc1
localhost.localdomain  192.168.10.47:8301  alive   server  0.6.4  2         dc1
siva@user1:/etc/consul.d$ consul members ^C
siva@user1:/etc/consul.d$ sudo python -m SimpleHTTPServer 80 
Serving HTTP on 0.0.0.0 port 80 ...
127.0.0.1 - - [26/Aug/2016 18:13:19] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [26/Aug/2016 18:13:29] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [26/Aug/2016 18:13:39] "GET / HTTP/1.1" 200 -
byteshiva commented 8 years ago

Register local node to consul server via REST API.

curl -H "Content-Type: application/json" -X POST -d '{"Datacenter":"dc1","Node":"foobar","Address":"192.168.10.86","TaggedAddresses":{"lan":"192.168.30.76","wan":"10.0.10.10"},"Service":{"ID":"redis1","Service":"redis","Tags":["master","v1"],"Address":"127.0.0.1","Port":8000},"Check":{"Node":"foobar","CheckID":"service:redis1","Name":"Redis health check","Notes":"Script based health check","Status":"passing","ServiceID":"redis1"}}' http://192.168.30.79:8500/v1/catalog/register