Consul (turn https://blog.csdn.net/junaozun/article/details/90699384)

What 1.consul that?

Consul is HashiCorp company launched the open source tools for implementing service discovery and configuration of distributed systems. Consul is distributed, highly available, it may be laterally extensible. It has the following characteristics:
       -Service Discovery: Consul by DNS or HTTP interface enables the service registration and discovery service becomes very easy, some external services, such as registration may be provided saas.
       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.

2. Why use consul service discovery?

Because of a micro-service architecture, there are many services need to be managed, which means there will be a lot of grpc. If the correspondence is managed will be very complicated so we need to have a mechanism to manage discovery.

        

Services 1 ~ 4 current position their networks to service discovery module registration, service discovery on the way to record KV, K is usually the service name, V is the IP: PORT. Service discovery module timed to view these polls can not access the service (this is the health check). When the client calls the service 1 to 4, ran a service discovery module ask their network location, and then call their service. The client does not need to record the full service network location, the client and server completely decoupled!

Installation 3.consul of

  (1) into the consul's official website to find their own development platform corresponding installation package download https://www.consul.io/ downloads.html

           Or https://releases.hashicorp.com/consul/1.5.1/consul_1.5.1_linux_amd64.zip wget

  (2) After the download, decompress, to give an executable file Consul

  (. 3) to move the file to the global environment variables the

           $ Consul sudo mv / usr / local / bin /

  (4) verify that the installation was successful

           $ Consul

4.consul Description

(1) consul role
   client: the client, stateless, HTTP and DNS forwarding the request to the service interface to the LAN end cluster.
   server: the 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) the agent running consul
    consul is a typical C / S architecture, you can run the service mode or client mode. Each data center must have at least one serving node, serving 3-5) the best service node. Very does not recommend running only one service node, because there is a great risk of losing data in case of node failure.
(3) Run Agent
     After completing the Consul of installation, you must run the agent. agent can be run as a server or client mode. Each data center must have at least one server. There are three or five recommended server in a cluster. Deploy a single server, when the failure occurred will inevitably result in data loss. Other agent running in client mode. A client is a very lightweight process. For registration services, health checks and run forward queries to the server. agent must be running in the cluster on each host.

5. Start consul server and Client

   the PS: a total of three nodes, the two nodes as a server, as a client. Three node address are:

          106.14.125.167 (cloud. 1)

          129.28.80.79 (cloud 2)

          106.12.77.99 (Yun 3)

in server mode cosnul agent: node1

     first create the directory under consul.d node1 node's / etc directory and open a terminal type the following command:

Consul Agent Expect = -server -ui -bootstrap-2--data the dir = / tmp / Consul -node the dir--config = N1 = 106.14.125.167 /etc/consul.d -advertise -bind = -client = 0.0.0.0 0.0.0.0

parameters:
     -server: run agent defined in server mode
     -bootstrap-expect: the number of nodes in the server provided in a datacenter desired, when the value provided, Consul waits until the specified time will sever the guide number of the entire cluster, the mark can not be shared bootstrap
     -data-dir: providing a directory used to store the agent of the state, all of the agent is required to allow the directory, which must be stable, will continue to exist after the system restart
     -node: node names in the cluster in a cluster must be unique, the default is the host name of the node
     -bind :: IP address of the specified node, usually 0.0.0.0 or cloud server network address can not write Ali goes outside the network address. It's Consul listening address, it must have access to all other nodes in the cluster. Although the binding address is not absolutely necessary, but it is preferable to provide a.
     -ui: Start the web interface
     -config-dir :: profile directory, which all loaded with .json the end of the file will
     -rejoin: the consul ignore previous leave, after starting again still trying to join the cluster.
     -client: consul service listens address that provides HTTP, DNS, RPC and other services, the default is 127.0.0.1 so do not provide services, if you want to provide services into 0.0.0.0

node2: Run cosnul agent in a server mode

  node2 switched to the machine, open the terminal type the following command:

Agent -server -ui -bootstrap-Consul Expect = 2--data the dir = / tmp / Consul -node = N2 = 129.28.80.79 -advertise -bind = 0.0.0.0 0.0.0.0 -join -client = 106.14.125.167

node3: cosnul agent running in client mode

  is switched to the node3 machine, first create consul.d directory / etc directory, open a terminal type the following command:

Consul-Agent -data the dir = / tmp / Consul -node = N3 = -advertise -bind = 0.0.0.0 -client = 106.12.77.99 0.0.0.0 -join 106.14.125.167

6. View in a terminal cluster members

   to open a terminal window run consul members, you can see the cluster members Consul:

      

7. stop Agent
   you can use Ctrl-C and elegant close Agent. After the interruption Agent you can see he left the cluster and turn off.
   During withdrawal, Consul alert other members of the cluster, the node to leave. If you are forced to kill the process. Other members of the cluster should be able to detect this node fails. When a member leaves, his service and inspection will be removed from the directory. When a member fails, his health is simply marked as dangerous, but will not be removed from the directory. Consul will automatically attempt to re-connect node failures allowed him to recover from the network under certain conditions. Node leaves is no longer continue to contact.
   Furthermore, if an agent as a server, an elegant departure is very important, to avoid causing potential to reach a consensus protocol usability faults.
       Consul the Leave $

      

 8. Registration Service
----------------
Disclaimer: This article is CSDN blogger original article "suxuefeng123", and follow CC 4.0 BY-SA copyright agreements, please attach a reprint the original source link and this statement.
Original link: https: //blog.csdn.net/junaozun/article/details/90699384

Guess you like

Origin www.cnblogs.com/agang-php/p/12130805.html