Winserver's Consul Deployment Beijing _ Racing collection repair practice with. NET Core client use

Source: Internet
Author: User
Tags response code value store

With the emergence of micro-services, the management of services is extremely important. All know that microservices are "split", the bloated single-block application, split into a number of lightweight services, each service can be in a short period of time to reconstruct, iterate, delivery. With the increase in the number of micro-services, due to quantitative quality, resulting in a new problem one of which is the management of services. With the growth of micro-services in the business, it is possible that the technology leader can not clearly remember the deployment of services, the health of services can not always pay attention to, so the role of service governance system is essential.

Beijing _ Racing Collection Repair


Address one: "hubawl.com" Fox PA Source Forum
Address two: "Bbscherry.com"

Consul

Consul is a simple, easy-to-use, scalable and strong service governance system.

The main core features are:

Service discovery

Health Check

Key-Value Storage

Multi-Data center

The consul agent accesses the Registry's service node each time, if the response code of "20X" is considered healthy.

A key-value store can be thought of as a simple k/v database, so you can use this to store configuration information.

Service discovery

Service Discovery Sub-service registration and service lookup.

Service Registration

Add (remove) the Service node information (address + port) to the registry, which records the node information and status of the service

Service Finder

The node information that is queried by other services or systems through the registry to the specified available service.

How services are discovered

The way of service discovery is divided into autonomous and proxy type.

Autonomous type

Each service actively adds (deletes) its own node information to the registry. The implementation is through the unified encapsulation or the library, by the service each node undertakes the service discovery function, compared with the proxy type to share the access pressure by the respective node.

640?wx_fmt=png

Proxy type

Service discovery is done by a system (load balancing System) or service (API Gateway). Because a system or service is complete, as the enrollment service increases the performance bottleneck, you need to do this cluster.

640?wx_fmt=png

Consul mode

There are two modes of consul, client and server, and there is a consul agent in all modes.

Client mode

The client mode is a lightweight consul agent that only has functions such as registration services, health checks, and forwarding queries.

Server mode

Compared with client mode, the server mode has more data storage, leader elections, and so on, besides the function of client mode.

The official recommendation server mode should be guaranteed 3-5, and should be odd, for what, because less than 3 can not guarantee high availability, more than 5 will give the consistency of database synchronization pressure, and the client number control is not fastidious.

640?wx_fmt=png

Cluster deployment

On Server A, open cmd,

Consul Agent-server-bootstrap-expect=1-bind=192.168.20.80-client=192.168.20.80-join=192.168.20.80-datacenter= Dc1-data-dir=data-ui-node=consul-80
On Server B, open cmd,

Consul agent-server-bind=192.168.20.81-client=192.168.20.81-join=192.168.20.80-data-dir=data-node=consul-81

640?wx_fmt=png

Brief analysis of Directives

-server

Consul is started in server mode and is not populated by default in client mode

-bootstrap-expect=1

Number of cluster nodes, data synchronization occurs when the number of cluster nodes reaches the number of claims

-bind=192.168.20.80

Current Consul Service binding address

-client=192.168.20.80

HTTP interface binding address, client call required

-join=192.168.20.80

Join target cluster when starting service

-node=consul-81

Service Node Name

-ui

Start Web Management background

Client Practice

Installing consul

640?wx_fmt=png

Encapsulation extension

Only part of the core code, the specific can view the demo source.

Inject consulclient

640?wx_fmt=png

Register the current service to consul

640?wx_fmt=png

Add Health Check Interface

With the above package can be in the same library, avoid each Web service to write a

640?wx_fmt=png

Calls to the consul package in Startup.cs

Configureservices

640?wx_fmt=png

Configure

640?wx_fmt=png

k/v extension

Only put, get, delete are implemented, and the rest can be added on demand

640?wx_fmt=png

Deployment Startup

Modify Appsettings.json, fill in the target Consul address and the service address

640?wx_fmt=png

After startup, the effect can be displayed if the service is healthy.

640?wx_fmt=png

Winserver's Consul Deployment Beijing _ Racing collection repair practice with. NET Core client use

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.