Monday 21 September 2015

Consul setup : Tutorial

Consul Installation 


This is a quick guide for setting up consul on ubuntu instances.
This tutorial uses aws instances. We will create three consul servers and one client machine.
Three Servers -  Use to handle queries and maintain consistent view of the system. Also store information about services and key-value information.
One Client - Can connect to other three members of the system for information about infrastructure


Server  - IP
server1 - P1.P1.P1.P1
server2 - P2.P2.P2.P2
server3 - P3.P3.P3.P3
client    - P4.P4.P4.P4

Consul Members configuration: common for all server

To start with, install consul on all the four instances using the following steps after logging in to your instances.

Intall unzip and screen

apt-get update
apt-get install unzip screen

Now, screen and unzip are installed.
To start screen session
 
$screen

Hit Enter and you are in a new screen session
You can copy the download link of consul from this page and use it in the wget command

$cd /usr/local/bin
$sudo wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip

The above URL might have changed but you can still get the link from here.
Now unzip the downloaded package

$sudo unzip *.zip
$rm *.zip

Now you should have consul command ready

$consul

We are done with the basic installation

Preparing server1 in bootstrap mode

Start the server in bootstrap mode (bootstrap mode will allow the server to elect itself as a leader)

$consul agent -server -bootstrap -data-dir /tmp/consul

Since we have started the consul server in bootstrap mode it will acquire itself as a leader which you can see in the output after running the above command.
type  CTRL-A C to start new screen session and than run the following command to see if the consul server is running or not.

$consul members

Joining server2 and server3 to the cluster

On server2 and server3, we can now start the consul service without the bootstrap option by running following command.

$consul agent -server -data-dir /tmp/consul

To join server2 and server3 on with server1. Type the following command in the fresh terminal (CTRL-A C) of screen session of window one. To switch between screen session use CTRL-A N

$consul join p2.p2.p2.p2 p3.p3.p3.p3

where p2.p2.p2.p2 is the private IP of server2 and p3.p3.p3.p3 is the private IP of server3
Now you can again run to check the consul members in the cluster

$consul members

Now, we have three servers, so we can rejoin the server1 without bootstrap option so that a leader can be appointed by the election between three server

$consul agent -server -data-dir /tmp/consul
 

Client configuration

Client will serve the request being received and will also serve the web-ui of consul.
Download and unzip the web-ui of consul
In the wget command, you can copy the link location from the download-web-ui button of this page

$cd ~
$wget https://dl.bintray.com/mitchellh/consul/0.5.2_web_ui.zip
$unzip *.zip
$rm *.zip 

This will leave "dist" directory in the home folder
Now we will start the client with the following command by specifying the client flag and the web-ui directory "dist" and make it to join the cluster

$consul agent -data-dir /tmp/consul -client p4.p4.p4.p4 -ui-dir /home/your-username/dist/ -join p1.p1.p1.p1

This will join our client machine to the cluster as a regular, non-server agent.
Now run the "consul members" command in the server1 fresh terminal screen session to see if the client has join the cluster or not.

Now we can access the web-ui on the public ip of our client after running the following command
   
$consul members -rpc-addr=p4.p4.p4.p4:8400

Now we can access the web-ui on the following url

http://p4.p4.p4.p4:8500/ui

Now we are done with the basic configuration of consul with 3+1 members.

2 comments:

  1. Do we need to require open all below ports?

    Consul requires up to 5 different ports to work properly, some on TCP, UDP, or both protocols. Below we document the requirements for each port.

    · Server RPC (Default 8300). This is used by servers to handle incoming requests from other agents. TCP only.

    · Serf LAN (Default 8301). This is used to handle gossip in the LAN. Required by all agents. TCP and UDP.

    · Serf WAN (Default 8302). This is used by servers to gossip over the WAN to other servers. TCP and UDP.

    · CLI RPC (Default 8400). This is used by all agents to handle RPC from the CLI. TCP only.

    · HTTP API (Default 8500). This is used by clients to talk to the HTTP API. TCP only.

    · DNS Interface (Default 8600). Used to resolve DNS queries. TCP and UDP.

    You can configure consul services to run on different ports by editing the config file. For example setting the dns interface on port 53 and the HTTP API on port 80.

    ReplyDelete
  2. Hi, Can we use Consul for UI- Recat.js ? Like i need to keep few of my properties to be dynamic and shall b outside my application so on chnaging those props I dont need to deploy my whole app again.
    Thanks

    ReplyDelete

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel