Install 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.
#Make a directory
#Download Consul :
$ 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
Informative blog. Thank you for sharing with us..
ReplyDeleteDevOps Online Training
ReplyDeleteI 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