当前位置:网站首页>Consul cluster deployment
Consul cluster deployment
2022-07-25 02:06:00 【freesharer】
Consul brief introduction
Consul yes HashiCorp Open source software launched by the company , be based on GO Language writing , Provide service registration and discovery 、 To configure 、 High availability solutions and other capabilities of multiple data centers , The distributed consistency aspect adopts raft Algorithm implementation , And it's easy to Spring Cloud Isomicroservice framework integration , It's very simple to use , Simple 、 Easy to use 、 Pluggable and other features .
In short ,Consul It is the control plane of the service grid ,Consul Provides a complete service grid solution .

Consul The running nodes are connected , It's called the data center , A data center will have 3 To 5 Servers and many clients .Consul The cluster architecture is as follows :
Consul Cluster deployment
Here we use 3Server + 1Client Cluster architecture of ,3 platform Server On a separate virtual machine ,1 platform Client Then run directly on the host of the deployment service .
| The name of the node | node IP | Agent type | OS edition |
|---|---|---|---|
| consul-01 | 192.168.94.10 | server | Ubuntu 22.04 LTS |
| consul-02 | 192.168.94.11 | server | Ubuntu 22.04 LTS |
| consul-03 | 192.168.94.12 | server | Ubuntu 22.04 LTS |
| consul-client | 192.168.94.13 | client | Ubuntu 22.04 LTS |
1、 install Consul
Configure host name , Order sample :( The following operations are configured on all nodes )
hostnamectl set-hostname consul-01
hostnamectl set-hostname consul-02
hostnamectl set-hostname consul-03
hostnamectl set-hostname consul-client
export VER="1.12.3"
wget https://releases.hashicorp.com/consul/${VER}/consul_${VER}_linux_amd64.zip
Unpack the installation
apt install -y unzip
unzip consul_${VER}_linux_amd64.zip -d /usr/local/bin/
View version
consul version
establish consul Users and groups
sudo groupadd --system consul
sudo useradd -s /sbin/nologin --system -g consul consul
establish consul The installation directory
mkdir -p /data/consul/{
config,data,logs}
chown -R consul:consul /data/consul
chmod -R 775 /data/consul
Set up DNS Or edit /etc/hosts File to configure the hostname of all servers , Replace example.com For your actual domain name .
cat >/etc/hosts<<EOF 192.168.94.10 consul-01.example.com consul-01 192.168.94.11 consul-02.example.com consul-02 192.168.94.12 consul-03.example.com consul-03 192.168.94.13 consul-client.example.com consul-client EOF
2、Server Node configuration
Generate Consul secret
consul keygen
by server Node creation json The configuration file , Other node configurations are modified IP Address and node name
consul-01 node
cat >/data/consul/config/consul.json<<EOF
{
"advertise_addr": "192.168.94.10",
"bind_addr": "192.168.94.10",
"bootstrap_expect": 3,
"client_addr": "0.0.0.0",
"datacenter": "DC1",
"node_name": "consul-01",
"data_dir": "/data/consul/data",
"domain": "consul",
"enable_script_checks": true,
"dns_config": {
"enable_truncate": true,
"only_passing": true
},
"enable_syslog": true,
"encrypt": "F0VSq05Die32sMUimbZ2LAzUIc5Ry4jCL2ouwz/Gu8Q=",
"leave_on_terminate": true,
"log_level": "INFO",
"rejoin_after_leave": true,
"retry_join": [
"consul-01",
"consul-02",
"consul-03"
],
"server": true,
"start_join": [
"consul-01",
"consul-02",
"consul-03"
],
"ui": true
}
EOF
Configuration parameter description :
datacenter: This flag controls the data center where the agent runs . If not provided , The default isdc1.Consul First class support for multiple data centers , But it depends on the correct configuration . Nodes in the same data center should be located in a single location LAN On .data_dir: This flag provides a data directory for the agent to store state .node_name: Node name , Usually the host name .server: Specify whether to be server node .bootstrap_expect: In a datacenter We hope to provide server Number of nodes , When this value is provided ,consul Wait until the designated sever The number will guide the whole cluster , The mark cannot be used with bootstrap public .bind_addr: This address is used for communication within the cluster , All nodes in the cluster must be reachable , The default is 0.0.0.0.client_addr:Consul Will bind the address of the client interface , Include HTTP and DNS The server . By default , This is a 127.0.0.1, Only loopback connections are allowed . stay Consul 1.0 And later , This can be set to a space delimited address list to bind to .log_json: This flag enables the agent to JSON Format output log . The default is false.log_level: stay Consul The log level displayed after the agent starts . The default isinfo. The available log levels aretrace、debug、info、warnanderr.retry_join: Specify the IP list , If you fail , Will automatically retry , Know until you successfully join .start_join: The address to join the cluster at startupui_config: This object allows you to set multiple subkeys , Used to control the UI Displays or functions available in .rejoin_after_leave: Allow rejoining the cluster
consul-02 node
cat >/data/consul/config/consul.json<<EOF
{
"advertise_addr": "192.168.94.11",
"bind_addr": "192.168.94.11",
"bootstrap_expect": 3,
"client_addr": "0.0.0.0",
"datacenter": "DC1",
"node_name": "consul-02",
"data_dir": "/data/consul/data",
"domain": "consul",
"enable_script_checks": true,
"dns_config": {
"enable_truncate": true,
"only_passing": true
},
"enable_syslog": true,
"encrypt": "F0VSq05Die32sMUimbZ2LAzUIc5Ry4jCL2ouwz/Gu8Q=",
"leave_on_terminate": true,
"log_level": "INFO",
"rejoin_after_leave": true,
"retry_join": [
"consul-01",
"consul-02",
"consul-03"
],
"server": true,
"start_join": [
"consul-01",
"consul-02",
"consul-03"
],
"ui": true
}
EOF
consul-03 node
cat >/data/consul/config/consul.json<<EOF
{
"advertise_addr": "192.168.94.12",
"bind_addr": "192.168.94.12",
"bootstrap_expect": 3,
"client_addr": "0.0.0.0",
"datacenter": "DC1",
"node_name": "consul-03",
"data_dir": "/data/consul/data",
"domain": "consul",
"enable_script_checks": true,
"dns_config": {
"enable_truncate": true,
"only_passing": true
},
"enable_syslog": true,
"encrypt": "F0VSq05Die32sMUimbZ2LAzUIc5Ry4jCL2ouwz/Gu8Q=",
"leave_on_terminate": true,
"log_level": "INFO",
"rejoin_after_leave": true,
"retry_join": [
"consul-01",
"consul-02",
"consul-03"
],
"server": true,
"start_join": [
"consul-01",
"consul-02",
"consul-03"
],
"ui": true
}
EOF
3、Client Node configuration
client yes consul client , The client does not save data , The client forwards the received request to Server End .Server Data consistency is achieved through LAN or WAN communication between . Every Server or Client It's all one consul agent.
establish consul-client Node profile
cat >/data/consul/config/consul.json<<EOF
{
"advertise_addr": "192.168.94.13",
"bind_addr": "192.168.94.13",
"client_addr": "0.0.0.0",
"datacenter": "DC1",
"node_name": "consul-client",
"data_dir": "/data/consul/data",
"domain": "consul",
"enable_script_checks": true,
"dns_config": {
"enable_truncate": true,
"only_passing": true
},
"enable_syslog": true,
"encrypt": "F0VSq05Die32sMUimbZ2LAzUIc5Ry4jCL2ouwz/Gu8Q=",
"leave_on_terminate": true,
"log_level": "INFO",
"rejoin_after_leave": true,
"retry_join": [
"consul-01",
"consul-02",
"consul-03"
],
"server": false,
"start_join": [
"consul-01",
"consul-02",
"consul-03"
],
"ui": true
}
EOF
4、systemd Startup file
All nodes created systemd Service document /etc/systemd/system/consul.service, All nodes have the same content , The configuration is as follows :
cat >/etc/systemd/system/consul.service<<EOF [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 -config-dir=/data/consul/config/consul.json ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT TimeoutStopSec=5 Restart=on-failure SyslogIdentifier=consul [Install] WantedBy=multi-user.target EOF
All nodes start consul service
systemctl enable --now consul.service
see consul Service running status
[email protected]:~# systemctl status consul
● consul.service - Consul Service Discovery Agent
Loaded: loaded (/etc/systemd/system/consul.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-07-19 11:17:02 CST; 3s ago
Docs: https://www.consul.io/
Main PID: 46248 (consul)
Tasks: 8 (limit: 4537)
Memory: 23.3M
CPU: 249ms
CGroup: /system.slice/consul.service
└─46248 /usr/local/bin/consul agent -config-dir=/data/consul/config/consul.json
Jul 19 11:17:03 consul-01 consul[46248]: agent: Joining cluster
Jul 19 11:17:03 consul-01 consul[46248]: agent: (LAN) joining: lan_addresses=[consul-01, consul-02, consul-03]
Jul 19 11:17:03 consul-01 consul[46248]: agent: (LAN) joined: number_of_nodes=3
Jul 19 11:17:03 consul-01 consul[46248]: agent: Join cluster completed. Synced with initial agents: cluster=LAN num_agents=3
Jul 19 11:17:03 consul-01 consul[46248]: agent: (LAN) joined: number_of_nodes=3
Jul 19 11:17:03 consul-01 consul[46248]: agent: Join completed. Initial agents synced with: agent_count=3
Jul 19 11:17:03 consul-01 consul[46248]: agent: started state syncer
Jul 19 11:17:03 consul-01 consul[46248]: agent: Consul agent running!
Jul 19 11:17:03 consul-01 consul[46248]: 2022-07-19T11:17:03.431+0800 [INFO] agent: Synced node info
Jul 19 11:17:03 consul-01 consul[46248]: agent: Synced node info
5、 see Consul State of the cluster
3 platform Server and 1 platform Client Upper Consul After the services are started, they will be based on consul.json The configuration in automatically forms a cluster , also Server Will pass Raft The agreement Server Choose... From the nodes leader node .
You can use the following command to view the status of cluster nodes on any machine :
[email protected]:~# consul members
Node Address Status Type Build Protocol DC Partition Segment
consul-01 192.168.94.10:8301 alive server 1.12.3 2 dc1 default <all>
consul-02 192.168.94.11:8301 alive server 1.12.3 2 dc1 default <all>
consul-03 192.168.94.12:8301 alive server 1.12.3 2 dc1 default <all>
consul-client 192.168.94.13:8301 alive client 1.12.3 2 dc1 default <default>
see server Node member status information :
[email protected]:~# consul operator raft list-peers
Node ID Address State Voter RaftProtocol
consul-02 edefb129-e0fd-804d-bbfb-76e259077d03 192.168.94.11:8300 leader true 3
consul-01 50f9830f-45cd-683c-2382-77e1cf6d6e48 192.168.94.10:8300 follower true 3
consul-03 5dae09d2-7079-4611-1ab5-7728d0966cbe 192.168.94.12:8300 follower true 3
visit Consul UI:http://192.168.94.10:8500/ui

Reference resources :
边栏推荐
- Management mode of agricultural science data center based on life cycle theory
- [hero planet July training leetcode problem solving daily] 20th BST
- Easy to master SSO single sign on, see this article
- Plug ins QRcode and ityped
- DotNetCore. Cap notes
- Take C language from 0 to 1 - program structure and use examples
- Download files and web pages with WGet
- Ecosystem long-term observation data product system
- Application status of typical marine environmental observation data products and Its Enlightenment to China
- Server performance monitoring
猜你喜欢

How to judge which star you look like?

The most complete summary of MySQL data types in history - (first)

What do growth enterprises need most to build a data-driven organization?

Jsonp solves cross domain plug-ins (JS, TS)

Research 280+ documents! The team of Tsinghua Huang Gao, the winner of CVPR best paper, proposed the first dynamic network overview to comprehensively review the development of dynamic networks!
![[programmer interview classic] 01.09 string rotation](/img/d2/7ea9351c31af01665d86f8c6bc3468.png)
[programmer interview classic] 01.09 string rotation

Take the first place in the International Olympic Games in mathematics, physics and chemistry, and win all the gold medals. Netizen: the Chinese team is too good

July 8, 2022

MySQL advanced (13) command line export import database

Boutique solution | Haitai cloud password application service solution to create secure and compliant Cloud Applications
随机推荐
Gerrit statistics script
Ecosystem long-term observation data product system
Plug ins QRcode and ityped
【Power Shell】Invoke-Expression ,Invoke-Expression -Command $activateCommand; Error or power shell failed to activate the virtual environment
When executing SQL query statements in MySQL database, the underlying implementation principle (ultra detailed)
The most complete summary of MySQL data types in history - (first)
Several application scenarios of NAT
High performance memory recovery technology for decrypting ark -- HPP GC
G024-db-gs-ins-01 openeuler deployment opengauss (single instance)
Win10 configuring CUDA and cudnn
Data governance notes
Anacona has too many environments?? How to view your current environment in jupyter
Unable to display spline in UE4 (unreal engine4) terrain editing tool
Visual studio code installation package download slow & Installation & environment configuration & new one-stop explanation
In the post deep learning era, where is the recommendation system going?
Computing network, AI first, shengteng AI helps operators' Digital Transformation -- work together to win-win Computing Era
About the relationship between parent process and child process (UAC bypass idea)
PostgreSQL views tables, table indexes, views, table structures, and parameter settings
[recognize cloud Nativity] Chapter 4 cloud network section 4.9.4.3 - smart network card usage scenario - network acceleration implementation
Start to build a three node Eureka cluster