-
Notifications
You must be signed in to change notification settings - Fork 4
Set up the clusters
We will now set up Consul and Nomad. Both tools are developed by Hashicorp and so they have similar architecture.
They are a single binary file and you decide in which "mode" to start them up. You can find basic information about starting them up here and here but ideally we want 3 or 5 of these servers running that communicate with each other so that if one dies we don't lose availability.
We are going to start up only one Nomad and one Consul server. Don't do this in production. Seriously.
I'm using an Ubuntu 16.04 machine on my computer to install Consul and Nomad. Download the binaries here and here.
It would also help if you add the binaries to your path.
Now it's time to start the Consul server. Here is the magic command:
consul agent -server -data-dir="/tmp/consul" -node=agent-one -bind=127.0.0.1 -bootstrap-expect 1
-
consul agent
starts Consul.-server
dictates that the Consul starts in server mode -
-data-dir
is the directory Consul stores stuff. You need this, so just put it wherever you think it's appropriate -
-node=<name>
gives the server node a name. This can help if you have many servers and need a specific one -
-bind=<ip>
is the address that Consul will attach itself to. If another Consul agent wants to communicate with this server, that is the address that the agent needs to use. Just make it the address of your host machine, and make sure the machine has an IP address that you can access on your local network. -
-bootstrap-expect <number>
Consul expects the number you enter as the number of servers that are going to exist before Consul bootstraps them. If you are following this demo then use 1. The number should be 3 or 5. For more info go here
To check if this command worked, type consul members
to see all the servers that are detected from that machine.
Next is starting up the Nomad agent in server mode. We want the additional benefit of service discovery so that means that Nomad should know where the Consul server is. Unlike the previous command we will set up configurations for the agent through an HCL file, which is like Hashicorp's own version of JSON. You can have comments, so that's nice.
# Increase log verbosity
log_level = "DEBUG"
# Setup data directory
data_dir = "/tmp/nomad"
# To talk to this Nomad agent, use this IP. Put the IP of your host machine here
bind_addr = "127.0.0.1"
# Server configuration
server {
enabled = true
# Should be 3 or 5 for production. We only expect one server to bootstrap
bootstrap_expect = 1
}
In order to use this file (I'll assume the file is called server.hcl) to start the Nomad agent run the following:
nomad agent -config server.hcl
As long as you run both the Consul and Nomad agent on the same machine then you should get scheduling and service discovery working together for free!
Now if you run nomad server-members
you should get this:
Error querying servers: Get http://127.0.0.1:4646/v1/agent/members: dial tcp 127.0.0.1:4646: getsockopt: connection refused
We changed the bind address of this Nomad server, and in this case the nomad
command assumes it communicates to Nomad on localhost. All this means is we need to change the command to this:
nomad server-members -address=http://<bind address of Nomad server>:4646
And now we will see the list of Nomad servers that are connected. We should just have one.
This Ubuntu machine will have the servers running. Now it's time to start another Ubuntu machine that will have client agents that can communicate with the servers. I will explain why it's important to have agents in the next section.