Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the commands of Consul

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to understand Consul commands". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to understand Consul's commands".

Agent

The process that runs for a long time in the background in a Consul cluster is the agent. The agent is started through consul agent. The agent can run in client or server mode. Because each node in the cluster must have an agent, it is easier to call a node a client or server. All agents can have DNS or HTTP interfaces that are responsible for health check and service synchronization.

Client

The client is the agent that forwards all RPC requests to the server. The client is relatively stateless. The only daemon that the client runs is the gossip pool that participates in LAN. This activity has the least resource overhead and consumes only a small amount of network bandwidth.

Server

The server is an agent with an extended set of responsibilities, which includes participating in Raft arbitration, maintaining cluster status, responding to RPC requests, exchanging WAN gossip with other data centers, and forwarding queries to cluster leader or remote data centers.

Datacenter

The data center is a private, low-latency, high-bandwidth network environment. Of course, this does not include traffic across the public network, but for our purposes, multiple availability zones within a single EC2 area will be treated as part of a single data center.

Consensus

Consensus agreement is the agreement of cluster electing leader consistency protocol and transaction order. Because these transactions apply to finite state machines, our definition of consistency means the consistency of replication state machines. Consensus is described in more detail on Wikipedia, and later articles will talk about the implementation of Consul.

Gossip

Consul is built on top of Serf, and Serf provides a complete Gossip protocol that can be used for multiple purposes. Serf provides functions such as member management, fault detection and event broadcasting. I will focus on the Gossip protocol later. Gossip involves random node-to-node UDP communication.

LAN Gossip

Refers to the LAN Gossip pool, which contains nodes located on the same LAN or data center.

WAN Gossip

Refers to the WAN Gossip pool that contains only the server. These Consul servers are mainly located in different data centers and generally communicate through Internet or WAN.

RPC

Remote procedure call. A request / response mode that allows the client to make a request to the server.

Serf

Serf, like Consul, is also an open source project from Hashicorp, which implements the decentralized gossip protocol, in which gossip defines a message transmission process similar to virus infection. Some well-known open source projects, such as Docker and Consul here, the core components of network management and service discovery are based on serf, but the serf behind them seems to be little known, on the one hand, its complex theory and imperfect documents are prohibitive; on the other hand, the natural weak data consistency of gossip protocol also restricts the use of serf. If you want to learn more, you can see here:

Https://www.infoq.cn/article/principle-and-impleme-of-de-centering-system-in-serf

Https://www.serf.io/intro/index.html

To create a data center, you need to create a server-side cluster. The recommended way to create a server is to use the-bootstrap-expect option. This option is the expected number of Consul server nodes created and boots automatically when so many servers are available. To avoid inconsistencies and brain cracks (multiple servers treat it as a cluster of leader), you must specify the same value for-bootstrap-expect, or none at all. Only the server with the specified value attempts to boot the cluster.

Suppose you are starting a cluster of three service nodes. Node A, node B, and node C can be started by providing the identity of-bootstrap-expect 3, respectively. After the node starts, you can see a warning message in the service output.

[WARN] raft: EnableSingleNode disabled, and no known peers. Aborting election.

The warning indicates that the node expects two peers, but it is not known yet. The next article will show you how to start a three-point Consul cluster, and you will use this command.

Follow up the start command of the previous article

Docker run\-d\-p 8500 virtual 8500\-p 8600:8600/udp\-- name=badger\ consul agent-server-ui-node=server-bootstrap-expect=1

Previously, when creating the Consul node, I specified the value of bootstrap-expect to be 1. This is a single-node Consul cluster. Because it is an experimental course, it is possible to set up a single node. It can also be used as a service, but not in a production environment. Sh

Port

A server-side Consul node needs up to six different ports to work properly, and some ports need to use TCP,UDP or both protocols.

Before running Consul, you should make sure that the following binding ports are accessible.

Use default port DNS: DNS service (TCP or UDP) 8600HTTP: HTTP interface (TCP only) 8500HTTPS: HTTPs interface recommended port, default shutdown (8501) * gRPC:gRPC interface recommended port, default shutdown (8502) * LAN Serf: lan port (TCP and UDP) 8301Wan Serf:Serf WAN port (TCP and UDP) 8302 server: server RPC address (TCP only) 8300Sidecar Proxy Min: the lowest port number included Sidecar service registration for automatic allocation. 21000Sidecar Proxy Max: contains the largest port number for automatically assigned sidecar service registration. 21255

Port usage

DNS API is used to parse DNS queries.

The HTTP API client requests the server through HTTP API

HTTPS API (optional) is off by default, but port 8501 is used by multiple tools by default.

GRPC API (optional) currently, gRPC is only used to expose xDS API to Envoy agents. It is off by default, but port 8502 is used by various tools by default. The default is 8502 in-dev mode.

Serf LAN is used to handle the gossip protocol in LAN. All agents need it.

Serf WAN servers WAN servers use it to propagate to other servers over the WAN. Starting with Consul 0.8, WAN connection flooding requires the Serf WAN port (TCP / UDP) to listen on the WAN and LAN interfaces.

RPC servers are used to process requests from other agents (agent).

At this point, I believe you have a deeper understanding of "how to understand Consul commands". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report