How to set up Consul in AWS

turned on laptop computer
Reading Time: 4 minutes

Hello folks. In this blog, I’m gonna show you How to set up Consul in AWS

and to install Consul I’m going to set up one Server and one Client and then we’ll see how

this communication can happen.

Install Consul Connect:

I’ve 2 ec2 ubuntu instances and I’m gonna install consul on them by following commands.

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install consul

As you can see on both ubuntu ami consul is installed and to verify it.

consul -v
consul

Alright, we’ll some of them one by one but before it what we’re going to do is set up our Server

but here we’re not going to set it up in production mode.

e.g we can set up the Server in two modes:

Production Mode

It comes with its own security and restrictions.

Developer Mode :

In this mode, we have very less restrictions so you can see a lot of details and you can work a lot of things

Therefore, let’s set up a server in dev mode.

consul agent
consul agent -h

to set up the server in dev mode follow the below command.

consul agent -dev

as you can see it’s running as a server.

now open the other tab for same ami means server.

netstat
sudo apt install netstat

netstat is the command to see the statistics of your network. if you say “netstat” it’ll

give you which are the applications, running, and ports are connected.

netstat -ntlp

it shows me what are the applications running on which ports.

and you can see here a lot of consul applications are running along with those ports.

curl localhost:8500

but the problem here is it’s only listening within this server. and that’s definitely not our use case.

we want to access this application and to be exposed outside this machine as well.

that’s the limitations of that server command so I’ll stop the agent by pressing ctrl+c.

consul agent -dev -client=0.0.0.0 

After that, go to your browser and type the following command

<consul_server_ip>:8500

you’ll see the consul UI where one instance is running on this cluster like below:

you can see it also gave itself a name dc1 means datacenter 1 more like a cluster.

Similarly, if you want to set up a client, you need to join the client in this data center.

find the IP of server ami.

ip add sh
How to set up Consul Connect in AWS

now on client ami, to join the consul server:

consul agent --join <server-ip-add>
How to set up Consul Connect in AWS

In client mode, you have to specify a data directory where it can store its data.

some data which it syncs from the data center and all that.

consul agent --join 172.31.44.28 --data-dir /tmp/consul
How to set up Consul Connect in AWS

connection refused because of 8300 port bind to localhost. because we need to bind the server IP for the 8300 port.

consul agent -dev -client=0.0.0.0 -bind <172.31.44.28>
netstat -ntlp
How to set up Consul Connect in AWS

where 172.31.44.28 server ami public IP. and join the client again

consul agent --join 172.31.44.28 --data-dir /tmp/consul
How to set up Consul Connect in AWS

so you can see we’ve added the 2 nodes and IP are the private IP of cosul_server and consul_client

ec2 instances.

How to set up Consul Connect in AWS

Conclusion:

In this blog, we’ve seen how we can set up consul connect on aws ec2 instances, and then we’ve also seen that one consul_server connected with one consul_client in datacenter 1. If you find this blog helpful do share it with your friends.

Written by 

A curious DevOps Intern , love to learn and working on technical skills/tools, know the basics of Linux, Docker, Ansible , Kubernetes and more..

1 thought on “How to set up Consul in AWS6 min read

Comments are closed.