Setup Consul on a Single Server

How to setup Consul on one instance

Running Consul on one instance

 

This installation guide assumes Ubuntu 14.04 OS, tmux and nginx already installed. Follow the below instruction to complete the consul installation.

  • Run the following command to download and install consul
cd /usr/local/bin
sudo wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
sudo unzip consul_0.6.4_linux_amd64.zip
sudo rm consul_0.6.4_linux_amd64.zip


Now the consul command should be ready to use

  • Download the web-ui of consul in /home/ubuntu/consul-ui/
cd ~
mkdir -p consul-ui
wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_web_ui.zip
unzip consul_0.6.4_web_ui.zip
sudo rm consul_0.6.4_web_ui.zip


  • Create the file config.json in /home/ubuntu/consul-config/server/ directory and put the following configuration in it. Here P.P.P.P is the private IP of the instance
{
"bootstrap": true,
"server": true,
"log_level": "DEBUG",
"enable_syslog": true,
"datacenter": "dc1",
"addresses" : {
"http": "0.0.0.0"
},
"bind_addr": "P.P.P.P",
"node_name": "P.P.P.P",
"data_dir": "/home/ubuntu/consuldata",
"ui_dir": "/home/ubuntu/consul-ui",
"acl_datacenter": "dc1",
"acl_master_token": "4f3fa35a-h3ab-45a2-914f-f82a34fab0c45",
"acl_default_policy": "deny",
"encrypt": "pXoaLOJ816mO+da8y8zrsg=="
}


  • Make consul.conf file in /etc/nginx/conf.d/ directory and put the following configurations in it
server
{
listen 80 ;
server_name myconsul.com;
root /home/ubuntu/consul-ui;
location / {
proxy_pass http://127.0.0.1:8500;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
}


Change myconsul.com to the the desired domain, save and exit. Restart the nginx server sudo service nginx restart.

  • Open a tmux session by running tmux command. Run the following command to start consul
consul agent -config-dir ~/consul-config/server -ui-dir ~/consul-ui -bootstrap true -client=0.0.0.0


Now, the consul should be running. Leave the process running by running ctrl+b than d. This will leave the tmux session running in which consul process was running.
The web-ui must be running on the public-ip or domain mentioned in the consul.conf file.

Note – If the link to download consul and web-ui doesn’t work (in case of version of consul changed) than visit this page to get the right link.

The video Tutorial

 

5 thoughts on “Setup Consul on a Single Server

  • May 16, 2016 at 9:32 am
    Permalink

    I think it makes more sense to add another 2 sections into this article: how to use docker in order to run consul in a single command, and how to setup single consul via init, upstart or systemd, instead of tmux.

    Reply
  • January 11, 2017 at 10:16 am
    Permalink

    Do you have any documentation to setup two data center. getting some errors while adding with 1st data center.

    Reply
  • February 21, 2017 at 8:25 pm
    Permalink

    Hi Ajeet, Hope your day is going great. I am very new to Consul, do you have instructions on how to set this up on RHEL 7? Thanks.

    Reply
  • June 8, 2017 at 1:12 pm
    Permalink

    Hi,
    I need your help to read data like these values
    "configurationsettings/applicationsettings/configspecurl",
    "configurationsettings/applicationsettings/maxhitsallowed",
    "configurationsettings/applicationsettings/metadataserviceurl",
    "configurationsettings/filelogsettings/errorLogPath",
    "configurationsettings/filelogsettings/transactionLogPath",
    "configurationsettings/getaroomsettings/ProductionUrl",
    "configurationsettings/getaroomsettings/TestUrl"
    into hierarchical format into C# class format like this

    public class ConfigurationSettings
    {
    public ApplicationSettings applicationSettings { get; set; }
    public SupplierSettings supplierSettings { get; set; }
    }

    public class ApplicationSettings
    {
    public string MetadataServiceUrl { get; set; }
    }

    public class SupplierSettings
    {
    public string TestUrl { get; set; }
    }

    Please help me on this.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *