Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consul.io - how to run multiple servers on same machine

Tags:

server

consul

This is probably a very basic question for you, but I'm just getting into consul and for testing purposes, I wanna run multiple servers on my PC. For example, I run the first server with

consul agent -server -bootstrap-expect=1 -dc=dev -data-dir=/tmp/consul -ui-dir="c:/consul 0.5.2/dist"

and then I try to run the second server with

consul agent -server -data-dir=/tmp/consul2 -dc=dc2

but it returns

==> Error starting agent: Failed to start Consul server: Failed to start RPC lay
er: listen tcp 0.0.0.0:8300: bind: Only one usage of each socket address (protoc
ol/network address/port) is normally permitted.

What am I missing from my command?

like image 430
KKO Avatar asked Jul 31 '15 07:07

KKO


People also ask

What is a cluster in Consul?

Consul is a distributed system designed to run on a cluster of nodes. A Consul node can be a physical server, cloud instance, virtual machine, or container. Connected together, the set of nodes Consul runs on is called a datacenter. A datacenter will have between 3 - 5 servers and many clients.


2 Answers

You are launching two consul servers using mostly default values. In this case the problem is that you use default ports.

When you read the error message you will notice that your second consul server tries to bind to port 8300. But your first server is already using this port, causing the second server to fail at startup. (note: consul binds to a variety of ports, each having another purpose and default setting. Take a look at the documentation).

As suggested by LenW, you can use Vagrant to set your environment. You could follow the consul tutorial.

If you do not want to use vagrant or set up any virtual machines on your own. You could change the defaults of the second server.

like image 130
Brrrr Avatar answered Oct 19 '22 23:10

Brrrr


If you are trying to simulate a production topology on your dev machine I would look at using Vagrant in combination with VirtualBox to simulate a couple of machines for testing.

like image 30
LenW Avatar answered Oct 19 '22 23:10

LenW