Install 2 Consul's client agents (separated clusters) on the same host

1.1k views Asked by At

I have 2 different HashiCorp Consul clusters (lets call them cluster A and cluster B) running on different hosts.

My Python app is running on a host which I already installed on 1 client agent configured to cluster A and I want my app will be able to send requests to cluster B also (somehow distinguish between the 2 agents)

Is it possible to install a second client agent (configured to cluster B) on that same host? and if so, how it can be done? Will I just need to change to a different port? Can't find documentation for that use case.

Any possible solutions will be helpful, Thanks!

1

There are 1 answers

2
Aslan Brooke On BEST ANSWER

Consul allows you to configure the ports for your agents so they don't conflict on a single host. I was able to do so in a file named:

consul.json

With contents:

{ 
  "ports": { 
    "dns": 9600,
    "http":9500,
    "serf_lan":9301,
    "serf_wan": 9401,
    "server":9300,
    "grpc":9502
  } 
}

I then started the agent with the following command:

consul agent -dev -bind 127.0.0.1 --config-file consul.json

I then had two agents on the same machine seen via command line tool ps x (output abbreviated):

7510 ... consul agent -dev -bind 127.0.0.1
7780 ... consul agent -dev -bind 127.0.0.1 --config-file consul.json

Lastly I used the --http-addr= option specied here to speak to the non-default port agent and clustered them together on the same host just to see if it was possible, sure was:

[vagrant@localhost ~]$ consul members
Node                       Address         Status  Type    Build   Protocol  DC   Segment
localhost.localdomain      127.0.0.1:8301  alive   server  1.10.2  2         dc1  <all>
localhost.localdomain.dc1  127.0.0.1:9401  alive   server  1.10.2  2         dc1  <all>

Therefore, I'm fairly confident you can run two agents on the same hosts with the proper settings in a configuration file for each agegnt (or use defaults on one and a configuration file on the other).