Newbie question: 3 consul agents on a single machine

1,994 views
Skip to first unread message

Sandeep

unread,
Apr 18, 2015, 8:00:12 PM4/18/15
to consu...@googlegroups.com
Hi,

I am new to Consul and I am trying to build a prototype for service registry using Consul. In my prototype I plan to run 3 consul agents on the same machine. I am using the following configuration (see below) however when I start the second agent I get the following exception 

"Error starting agent: Failed to start Consul server: Failed to start RPC layer: listen tcp 0.0.0.0:8301: bind: address already in use"

Would someone be able to help and point me to what I need to address in the configuration to get this working?

Thanks for your time and patience,

Sandeep

-------------------------------------------------------------------------

Setup Details

-------------------------------------------------------------------------

Node1:

start-script: consul agent -config-dir /tmp/config-n1/consul.d -config-file /tmp/config-n1/consul.d/default.json
config:

{
  "data_dir": "/tmp/Consul/data-n1",
  "server": true,
  "node_name": "node1",
  "bootstrap_expect": 3,
  "client_addr": "0.0.0.0",
  "ports": {
    "dns": 8600,
    "http": 8500,
    "rpc": 8400,
    "serf_lan": 8301,
    "serf_wan": 8302,
    "server": 8300
  }
}

Node2:

start-script: consul agent -config-dir /tmp/config-n2/consul.d -config-file /tmp/config-n2/consul.d/default.json
config:

{
  "data_dir": "/tmp/Consul/data-n2",
  "server": true,
  "node_name": "node2",
  "bootstrap_expect": 3,
  "client_addr": "0.0.0.0",
  "ports": {
    "dns": 8601,
    "http": 8501,
    "rpc": 8401,
    "serf_lan": 8311,
    "serf_wan": 8312,
    "server": 8301
  }
}

Node3:

start-script: consul agent -config-dir /tmp/config-n3/consul.d -config-file /tmp/config-n3/consul.d/default.json
config:

{
  "data_dir": "/tmp/Consul/data-n3",
  "server": true,
  "node_name": "node3",
  "bootstrap_expect": 3,
  "client_addr": "0.0.0.0",
  "ports": {
    "dns": 8603,
    "http": 8503,
    "rpc": 8403,
    "serf_lan": 8331,
    "serf_wan": 8332,
    "server": 8303
  }
}

Michael Fischer

unread,
Apr 19, 2015, 6:16:19 AM4/19/15
to Sandeep, consu...@googlegroups.com
Absent exceptional circumstances, putting more than one Consul agent on a host is not a recommended practice.  It can be done, but it's a lot of effort.  What's your use case?

--
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sandeep

unread,
Apr 19, 2015, 2:54:26 PM4/19/15
to consu...@googlegroups.com, osgi...@gmail.com
Hi Michael,

Thanks for responding. I do not plan to run this in production. I was simply trying to do was run a quick service-registry prototype with 3 Consul agents. I did a similar prototype with ZooKeeper and wanted to run the same against Consul. 

You have partly answered my question that its a lot of effort to configure it for a single machine, so I will heed that input and wont invest time prototyping with a single machine and will try to do the same with 3 separate ones. Just out of curiosity, since you state it is possible but lot of effort is there any documentation on what the effort is? Or its just not worth the effort?

Thanks for taking the time to respond,

Best,

Sandeep

Armon Dadgar

unread,
Apr 19, 2015, 3:16:30 PM4/19/15
to Sandeep, consu...@googlegroups.com, osgi...@gmail.com
Hey Sandeep,

The root problem is that you are having IP/Port binding collisions. All of the agents are trying to bind to the same ports.
When I do this for testing purposes, I just do the following:

$ consul agent -node foo -bind 127.0.0.1 -client 127.0.0.1...
$ consul agent -node bar -bind 127.0.0.2 -client 127.0.0.2 …
$ consul agent -node zip -bind 127.0.0.3 -client 127.0.0.3 …

You need to provide the `-node` flag to prevent them from all using the hostname and colliding,
as well as `-bind` and `-client` to avoid address collisions.

However, for a simple demo or prototype, you can just run a single Consul server. It is not strictly
necessary to actually run 3.

Best Regards,
Armon Dadgar
Reply all
Reply to author
Forward
0 new messages