Before starting deployment, it is recommended to switch to the domestic image source according to Ubuntu, which can save a lot of precious time!

Single deployment

As usual, we’ll start with a single deployment, get our hands on it

sudo mkdir -p /data/consul/{current/{bin,etc},data} sudo wget https://releases.hashicorp.com/consul/1.10.1/consul_1.10.1_linux_amd64.zip - O/data/consul/consul_1. 10.1 _linux_amd64. Zip Sudo apt-get install unzip sudo unzip /data/consul/ consul_1.10._linux_amd64.zip -d /data/ consul_consul /current/bin sudo vim /data/consul/current/etc/consul.json {"bootstrap": true."datacenter": "test-datacenter"."data_dir": "/data/consul/data"."log_level": "INFO"."server": true."client_addr": "0.0.0.0"."ui": true."start_join": ["ip:8301"]."enable_syslog": true
}
# # more reference: https://www.consul.io/docs/agent/options.html#configuration_files

sudo ln -s /data/consul/current/etc /data/consul/etc

sudo vi /etc/systemd/system/consul.service
[Unit]
Description=consul service
[Service]
ExecStart=/data/consul/current/bin/consul agent -bind={ip} -config-dir /data/consul/etc/consul.json
User=root
[Install]
WantedBy=multi-user.target

sudo systemctl enable consul.service
sudo systemctl start consul.service
Copy the code

Visit http://localhost:8500 to open Consul admin interface, interface is still very good drop! Eye candy

Consul cluster

Consul cluster is a classic server-Agent architecture and supports multi-server mode, making it truly highly available.

If you’re using Microservices, try consul as a registry, you’ll be pleasantly surprised!

For ease of understanding, the demonstration uses 1server-2Agent.

The host ip
node01 10.10.10.5
node02 10.10.10.4
node03 10.10.10.6
# Install both on Node01, node02, and Consul 03 respectivelysudo mkdir -p /data/consul/{current/{bin,etc},data} sudo wget https://releases.hashicorp.com/consul/1.10.1/consul_1.10.1_linux_amd64.zip - O/data/consul/consul_1. 10.1 _linux_amd64. Zip Sudo apt-get install unzip sudo unzip /data/consul/consul_1.10.1_linux_amd64.zip -d /data/consul/current/bin sudo vi /data/consul/current/etc/consul.json {"datacenter": "roc-datacenter"."data_dir": "/data/consul/data"."log_level": "INFO"."server": true."bootstrap_expect": 3."client_addr": "10.10.10.4"."ui": true."start_join": ["10.10.10.4:8301"."10.10.10.5:8301"."10.10.10.6:8301"]."enable_syslog": true
}
# # more reference: https://www.consul.io/docs/agent/options.html#configuration_files

sudo ln -s /data/consul/current/etc /data/consul/etc

sudo vi /etc/systemd/system/consul.service
[Unit]
Description=consul service
[Service]
ExecStart=/data/consul/current/bin/consul agent -config-dir /data/consul/etc/consul.json
User=root
[Install]
WantedBy=multi-user.target

sudo systemctl enable consul.service
sudo systemctl start consul.service
Copy the code

Disable the firewall, or open ports 8300, 8301, and 8500 on the Intranet. If the network is disconnected, the child node cannot join the primary node, which may occur

failed to sync remote state: No cluster leader
Copy the code

A leader cannot be elected. In fact, nodes cannot communicate with each other. If the communication is normal, all nodes automatically elect a leader upon startup.

Common commands

sudo systemctl start consul.service
sudo systemctl stop consul.service
sudo systemctl restart consul.service

# # more reference: https://www.consul.io/docs/commands/index.html
Copy the code

If this blog has been helpful to you, please remember to leave a comment + like + bookmark.

I am Chen, on the road of technology we forge ahead together!