1

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!

Orel Yamin
  • 15
  • 4

1 Answers1

1

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).

Aslan Brooke
  • 497
  • 2
  • 8
  • Thank you for the detailed explanation! – Orel Yamin Sep 22 '21 at 15:59
  • First, just want to call out that running two agents on the same host is not a recommended deployment pattern. If you absolutely need to do it in production, do not use `-dev` mode, and configure a separate [`data_dir`](https://www.consul.io/docs/agent/options#_data_dir) for each agent so that they do not try to save data to the same directory. You *may* also need to explicitly specify different [`node_id`](https://www.consul.io/docs/agent/options#_node_id)s in the configuration as well. Aside from that, the other config suggestions offered by Aslan are correct. :-) – Blake Covarrubias Sep 23 '21 at 15:58