Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Setting up Consul Cluster on 1 Node

Tanuja Shinde edited this page Jun 30, 2022 · 1 revision

Install Consul on CentOS 7

1. put SELinux in Permissive mode

sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

2. Install Consul RPM

sudo yum install -y wget unzip
export VER="1.6.2"
wget https://releases.hashicorp.com/consul/${VER}/consul_${VER}_linux_amd64.zip

3. Extract the file

unzip consul_${VER}_linux_amd64.zip

4. Move extracted consul binary to /usr/local/bin directory

sudo mv consul /usr/local/bin/
# To verify Consul is properly installed, run consul -v on your system.  
consul -v  
consul  --help

5. Enable bash completion

consul -autocomplete-install 
complete -C /usr/local/bin/consul consul

Bootstrap and start Consul Cluster

1. Create a consul system user/group

sudo groupadd --system consul  
sudo useradd -s /sbin/nologin --system -g consul consul

2. Create consul data and configurations directory and set ownership to consul user

sudo mkdir -p /var/lib/consul /etc/consul.d
sudo chown -R consul:consul /var/lib/consul /etc/consul.d
sudo chmod -R 775 /var/lib/consul /etc/consul.d

3. Setup DNS or edit /etc/hosts file to configure hostname

$ sudo vi /etc/hosts 

# Consul Cluster Servers
<eth-0-ip of node> <node-hostname> cortx-consul-server

# Example
10.230.241.63 ssc-vm-rhev4-2905.colo.seagate.com cortx-consul-server

4. create a system service file in /etc/systemd/system/consul.service with the following content

# Consul systemd service unit file
[Unit]
Description=Consul Service Discovery Agent
Documentation=https://www.consul.io/
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=consul
Group=consul
ExecStart=/usr/local/bin/consul agent -server -ui \
	-advertise=10.230.241.63 \
	-bind=10.230.241.63 \
	-data-dir=/var/lib/consul \
	-node=cortx-consul-server \
	-config-dir=/etc/consul.d

ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
TimeoutStopSec=5
Restart=on-failure
SyslogIdentifier=consul

[Install]
WantedBy=multi-user.target

Where:

10.230.241.63 is the eth0 IP address of the node -node: Consul Name of this node. Must be unique in the cluster.

5. Generate Consul secret

# consul keygen
pzDVYxESgPSkPhBFudHU5w==

6. Create a json configuration file for the node in /etc/consul.d/config.json

{
     "advertise_addr": "10.230.241.63",
     "bind_addr": "10.230.241.63",
     "bootstrap_expect": 1,
     "client_addr": "0.0.0.0",
     "datacenter": "DC1",
     "data_dir": "/var/lib/consul",
     "domain": "consul",
     "enable_script_checks": true,
     "dns_config": {
         "enable_truncate": true,
         "only_passing": true
     },
     "enable_syslog": true,
     "encrypt": "pzDVYxESgPSkPhBFudHU5w==",
     "leave_on_terminate": true,
     "log_level": "INFO",
     "rejoin_after_leave": true,
     "retry_join": [
         "cortx-consul-server"
     ],
     "server": true,
     "start_join": [
         "cortx-consul-server"
     ],
     "ui": true
 }

Note: Replace all occurrences of 10.230.241.63 with the correct eth0 IP address of the node and value of encrypt with your generated secret.

7. Validate consul configuration

$ consul validate /etc/consul.d/config.json 
Configuration is valid!

Start Consul Services

1. Start and enable consul

sudo systemctl start consul
sudo systemctl enable consul

2. Check Consul cluster members

consul members

3. Check consul service status

systemctl status consul

You will be able to access consul URL using below endpoint:

http://cortx-consul-server:8500

For Confstore API consul endpoint would look like:

consul://cortx-consul-server:8500
Clone this wiki locally