. Netcore Consul implementing Service registration and Discovery-single node deployment

Source: Internet
Author: User

First, the basic introduction of consul

Consul is an open source tool launched by Hashicorp to implement service discovery and configuration for distributed systems. Compared with other distributed service registration and discovery schemes, such as Airbnb's Smartstack, Consul's solution is more "one-stop", with built-in service registration and discovery Framework, distributed consistency Protocol implementation, health check, Key/value storage, multi-data center solution, No longer need to rely on other tools (such as zookeeper, etc.), it is easier to use. Consul is implemented with Golang and therefore has natural portability (support for Linux, Windows, and Mac OS X); the installation package contains only one executable file for easy deployment and works seamlessly with lightweight containers such as Docker.

More about the consul, such as the advantages, here will not repeat, the Internet a search can be found everywhere. However, a comparison with other similar software must be posted:

?

Second, consul before the installation of understanding

The Consul agent has two modes of operation:Server and Client. The server and client here are only consul cluster-level distinctions, regardless of the application service built on cluster, consul agent nodes running in server mode are used to maintain the status of consul clusters, and each consul is officially recommended Cluster at least 3 or more of the agent,client nodes running in server mode are not limited.

Consul supports multi-data centers, and consul cluster in each data center selects a leader node in the agent node running in server mode, which is ensured by Consul protocol, The consul data information on the server node is strongly consistent. The Consul Agent node in client mode is relatively simple and stateless, only responsible for forwarding requests to the Server Agent node.

Here we demonstrate the installation of two scenarios: a single-node deployment, two cluster deployments, and easier to understand from simple to complex deployments.

Three, consul formal installation (single node)

1. Download Consul

Website address: https://www.consul.io/downloads.html, download the corresponding version can be

?

Confirm the good version, download to our Native Directory command:

> wget -P /opt/consul/  https://releases.hashicorp.com/consul/1.2.2/consul_1.2.2_linux_amd64.zip

2, Installation consul

#先解压Consul文件> unzip consul_1.2.2_linux_amd64.zip#将Consul文件拷贝到执行目录> mv consul /usr/local/bin/注:如果找不到unzip命令请安装,命令如:yum install -y unzip

3. Test whether the consul is installed successfully

> consul

If it means success:

?

4. Start and configure Consul service

consul agent -server -ui -bootstrap-expect=1 -data-dir=/tmp/consul  -node=consul-1 -client=0.0.0.0  -bind=172.16.1.174 -datacenter=dc1

If this indicates a successful start:

?

Enter Address to view service status: Current Consul normal operation

?

Further review of server conditions and role status

  View individual server scenarios > Consul Members View all current Consul role status:> consul operator raft List-peers  

?

5, through the configuration file to register the service ( You can also add a service registration from the Consul API interface, and he will automatically persist )

vi/etc/consul/services_config.json{"Services": [{"id":"Client_service_01","Name":"Mvcclientservice","Tags": ["Urlprefix-/mvcclientservice01"],"Address":"172.16.1.110","Port": 5000,"Checks": [{"Name":"Clientservice_check","http":"http://172.16.1.110:5000","Interval":"10s","Timeout": "5s"}]}, { "id": "client_service_02", "name": "Apiclientservice", "tags": [
                            
                              "URLPREFIX-/APICLIENTSERVICE02"], 
                             "address": "172.16.1.110", "port": " Checks": [{ "name ": " Clientservice_check ", " http ": " Http://172.16.1.110:5001/api/values ", " interval ": " 10s " , "Timeout": "5s"}]}]}            
                             

Re-run the command:

consul agent -server -ui -bootstrap-expect=1 -config-dir=/etc/consul -data-dir=/tmp/consul -node=consul-1 -client=0.0.0.0 -bind=172.16.1.174 -datacenter=dc1

Note: Be sure to ensure that the backend service is running properly: Port 5001

After successful operation, such as:

?

The above operations are done on the Consul server side, according to the official note: Consul server and Consul client to distinguish between, the backend services should be deployed on the Consul client, they handle their own things better.

The next article has been updated:. Netcore Consul implement service registration and discovery-cluster

. Netcore Consul implementing Service registration and Discovery-single node deployment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.