Skip to main content

How to Configure Consul in a Production Environment on Ubuntu 14.04

Install Consul :

#Download Consul :

Below are the available downloads for the latest version of Consul (0.8.5). Please download the proper package for your operating system and architecture.

$ cd /usr/local/bin

$ sudo wget https://releases.hashicorp.com/consul/0.8.5/consul_0.8.5_linux_amd64.zip

$ unzip *.zip

$ rm *.zip

#Create Consul User :  

$ adduser consul

#Make a directory 

$ mkdir -p /etc/consul.d/{bootstrap,server,client}

$ mkdir /var/consul

$ chown consul:consul /var/consul

$ chown consul:consul /var/consul

##  Creating the Bootstrap Configuration ##

$ sudo vi /etc/consul.d/bootstrap/config.json

##  Create the first file in the bootstrap subdirectory: 
{
    "bootstrap": true,
    "server": true,
    "datacenter": "nyc2",
    "data_dir": "/var/consul"
}


## In the terminal, we can use the consul command to generate a key of the necessary length and encoding. Type:

$ sudo consul keygen 

Output=> X4SYOinf2pTAcAHRhpj7dA==

##Copy the value that is generated and re-open the configuration file:

$ sudo vi /etc/consul.d/bootstrap/config.json

{
    "bootstrap": true,
    "server": true,
    "datacenter": "nyc2",
    "data_dir": "/var/consul",
    "encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
    "log_level": "INFO",
    "enable_syslog": true
}


$ sudo cp /etc/consul.d/bootstrap/config.json /etc/consul.d/server

## Open the file to make the necessary modifications:

$ sudo vi  /etc/consul.d/server/config.json
{
    "bootstrap": false,
    "server": true,
    "datacenter": "nyc2",
    "data_dir": "/var/consul",
    "encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
    "log_level": "INFO",
    "enable_syslog": true,
    "start_join": ["192.0.2.2", "192.0.2.3"]
}

Save and close the files you have created when you are finished.

## Creating the Client Configuration ##

$ sudo vi /etc/consul.d/client/config.json

## Finally, we want to adjust the start_join parameter to list all of our servers:

{
    "server": false,
    "datacenter": "nyc2",
    "data_dir": "/var/consul",
    "ui_dir": "/home/consul/dist",
    "encrypt": "X4SYOinf2pTAcAHRhpj7dA==",
    "log_level": "INFO",
    "enable_syslog": true,
    "start_join": ["192.0.2.1", "192.0.2.2", "192.0.2.3"]
}


## ---------Create an Upstart Script------##

$ sudo vi /etc/init/consul.conf

## INSERT SERVER File :

description "Consul server process"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

respawn

setuid consul
setgid consul

exec consul agent -config-dir /etc/consul.d/server


## INSERT CLINET FILE :

description "Consul client process"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

respawn

setuid consul
setgid consul

exec consul agent -config-dir /etc/consul.d/client


## Save the file when you are finished.


###-------- Getting a Cluster Started---- ##
$ sudo  su consul
$ sudo  consul agent -config-dir /etc/consul.d/bootstrap

$ start consul

$ consul members
Node                Address            Status  Type    Build     Protocol  DC
Armons-MacBook-Air  172.20.20.11:8301  alive   server  0.6.1dev  2         dc1

$ curl localhost:8500/v1/catalog/nodes

[{"Node":"Armons-MacBook-Air","Address":"127.0.0.1","TaggedAddresses":{"lan":"127.0.0.1","wan":"127.0.0.1"},"CreateIndex":4,"ModifyIndex":110}]

$ dig @127.0.0.1 -p 8600 Armons-MacBook-Air.node.consul
...

;; QUESTION SECTION:
;Armons-MacBook-Air.node.consul.    IN  A

;; ANSWER SECTION:
Armons-MacBook-Air.node.consul. 0 IN    A   127.0.0.1

$ sudo ps aux | grep 8500

Comments

  1. Informative blog. Thank you for sharing with us..
    DevOps Online Training

    ReplyDelete

  2. I like this post because it contains a lot of useful information to read about java maybe everyone will like me. I hope this post of yours will be more appreciated by it really excellent, i enjoyed it, thanks for posting it.
    DevOps Training in Chennai

    DevOps Online Training in Chennai

    DevOps Training in Bangalore

    DevOps Training in Hyderabad

    DevOps Training in Coimbatore

    DevOps Training

    DevOps Online Training

    ReplyDelete

Post a Comment

Popular posts from this blog

Java Currency Formatter Solution

Given a  double-precision  number,  , denoting an amount of money, use the  NumberFormat  class'  getCurrencyInstance  method to convert   into the US, Indian, Chinese, and French currency formats. Then print the formatted values as follows: US: formattedPayment India: formattedPayment China: formattedPayment France: formattedPayment where   is   formatted according to the appropriate  Locale 's currency. Note:  India does not have a built-in Locale, so you must  construct one  where the language is  en  (i.e., English). Input Format A single double-precision number denoting  . Constraints Output Format On the first line, print  US: u  where   is   formatted for US currency.  On the second line, print  India: i  where   is   formatted for Indian currency.  On the third line...

Java Loops II print each element of our series as a single line of space-separated values.

We use the integers  ,  , and   to create the following series: You are given   queries in the form of  ,  , and  . For each query, print the series corresponding to the given  ,  , and   values as a single line of   space-separated integers. Input Format The first line contains an integer,  , denoting the number of queries.  Each line   of the   subsequent lines contains three space-separated integers describing the respective  ,  , and   values for that query. Constraints Output Format For each query, print the corresponding series on a new line. Each series must be printed in order as a single line of   space-separated integers. Sample Input 2 0 2 10 5 3 5 Sample Output 2 6 14 30 62 126 254 510 1022 2046 8 14 26 50 98 Explanation We have two queries: We use  ...

Java Date and Time Solution | Returns the day on that date.

The  Calendar class  is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. You are given a date. To simplify your task, we have provided a portion of the code in the editor. You just need to write the method,  , which returns the  day  on that date. For example, if you are given the date  , the method should return   as the day on that date. Input Format A single line of input containing the space separated month, day and year, respectively, in      format. Constraints Output Format Output the correct day in capital letters. Sample Input 08 05 2015 Sample Output WEDNESDAY Explanation The day on August  th    was  WEDNESDAY . impo...