Search code examples
consulservice-discovery

How to setup a single node Consul server/client?


What configuration is required to achieve this?

It's possible using the "development mode" mentioned here - https://learn.hashicorp.com/consul/getting-started/agent (but not recommended for production).

I've tried setting this up but I'm not sure how to set the client config. What I've tried is a config of:

{
  "data_dir": "/tmp2/consul-client",
  "log_level": "INFO",
  "server": false,
  "node_name": "master",
  "addresses": {
    "https": "127.0.0.1"
  },
  "bind_addr": "127.0.0.1"
}

Which results in a failure of:

consul agent -config-file=client.json
==> Starting Consul agent...
==> Error starting agent: Failed to start Consul client: Failed to start lan serf: Failed to create memberlist: Could not set up network transport: failed to obtain an address: Failed to start TCP listener on "127.0.0.1" port 8301: listen tcp 127.0.0.1:8301: bind: address already in use

Solution

  • No "client" agent is required to run for an operational Consul cluster.

    I had to set this server / master with the bootstrap_expect set to 1(number of nodes for boostrap process):

    {
      "retry_join" : ["127.0.0.1"],
      "data_dir": "/tmp2/consul",
      "log_level": "INFO",
      "server": true,
      "node_name": "master",
      "addresses": {
        "https": "127.0.0.1"
      },
      "bind_addr": "127.0.0.1",
      "ui": true,
      "bootstrap_expect": 1
    }