consul entry

1.consul is go language development, it can be said that a tool, is to serve the finding that address a variety of services recorded

C / S architecture, you can run the service mode or client mode. Each data center must have at least one service node

2. do service discovery framework

  • zookeeper
  • eureka
  • etcd
  • consul

3.consul problem

consul is distributed, highly available, lateral spread. Some of the key characteristics of the consul offered:

  • service discovery: consul through DNS or HTTP interface enables service registration and service discovery becomes very easy, some external services, for example, can also register as saas provided.
  • health checking: Health detection can quickly alert the consul operations in the cluster. Integration and service discovery, service can be forwarded to the failure to prevent the above services.
  • key / value storage: a storage system for dynamically configured. It provides a simple HTTP interface that can operate anywhere.
  • multi-datacenter: no complex configuration, it can support any number of areas.

Image.png

We look at the data center 1, it can be seen consul cluster is composed of N SERVER, plus M CLIENT thereof. And whether it is a SERVER or CLIENT, is consul of nodes , all services can sign up to these sites, it is the shared service registration information through these nodes. In addition to these two, there are some small details, one by one briefly.

  • CLIENT

CLIENT represents consul in client mode, that is, the client mode. It is a model consul node In this mode, all registered to the current node's service will be forwarded to the SERVER, itself is not persistent information.

  • SERVER

SERVER represents the consul of server mode, indicating that the consul was a server, this mode features and CLIENT are the same, the only difference is that all the information it will persist locally, so it encounters an error information can be retained of.

  • SERVER-LEADER

SERVER LEADER below the middle of the word, this show SERVER is their boss, and it is not the same as other SERVER point is responsible for the information it needs to synchronize to other registered SERVER, but also responsible for monitoring the health of each node.

4.consul basic use

1) pull the mirror

The following shows the use of consul at docker deployed on a single machine. Ignore container port mapping host computer, each host normal production environment a consul, the port needs to be mapped to the host.

(If you do not use docker consul, you can follow these steps to download and install consul: # here to Linux system as an example:
$ wget https://releases.hashicorp.com/consul/1.4.2/consul_1.4.2_linux_amd64.zip

$ unzip consul_1.4.2_linux_amd64.zip
$ mv consul /usr/local/bin/)

docker pull consul

Client : Client, stateless, HTTP and DNS forwarding the request to the server cluster interfaces within the LAN.

server : server, save the configuration information, high availability clustering, in the LAN to communicate with local clients, the number of each data center server recommended communications with other data center is 3 or 5 over the WAN.

2) Enable docker

Start Node 1 (server mode)

docker run -d -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' --name=node1 consul agent -server -bind=172.17.0.2  -bootstrap-expect=3 -node=node1
//====================
-node:节点的名称 
-bind:绑定的一个地址,用于节点之间通信的地址,可以是内外网,必须是可以访问到的地址 
-server:这个就是表示这个节点是个SERVER 
-bootstrap-expect:这个就是表示期望提供的SERVER节点数目,数目一达到,它就会被激活,然后就是LEADER了

Start node 2-3 (server mode)

docker run -d -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' --name=node2 consul agent -server -bind=172.17.0.3  -join=172.17.0.2 -node-id=$(uuidgen | awk '{print tolower($0)}')  -node=node2

docker run -d -e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true}' --name=node3 consul agent -server -bind=172.17.0.4  -join=172.17.0.2 -node-id=$(uuidgen | awk '{print tolower($0)}')  -node=node3 -client=172.17.0.4

//=====================
-join:这个表示启动的时候,要加入到哪个集群内,这里就是说要加入到节点1的集群 
-node-id:这个貌似版本8才加入的,这里用这个来指定唯一的节点ID,可以查看这个issue 
-client:这个表示注册或者查询等一系列客户端对它操作的IP,如果不指定这个IP,默认是127.0.0.1。

Start node 4 (client mode)

docker run -d -e 'CONSUL_LOCAL_CONFIG={"leave_on_terminate": true}' --name=node4 consul agent -bind=172.17.0.5 -retry-join=172.17.0.2 -node-id=$(uuidgen | awk '{print tolower($0)}')  -node=node4

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/u013755520/article/details/91383556