通过领事集群实现容错 [英] Achieve Fault Tolerance with Consul Cluster

查看:104
本文介绍了通过领事集群实现容错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用本地主机中的不同端口创建了consul服务器集群.

I have created consul server cluster using different ports in localhost.

我为此使用了以下命令.

I used below commands for that.

服务器1:

consul agent -server -bootstrap-expect=3 -data-dir=consul-data -ui -bind=127.0.0.1 -dns-port=8601 -http-port=8501 -serf-lan-port=8303 -serf-wan-port=8304 -server-port=8305 -node=node1

服务器2:

consul agent -server -bootstrap-expect=3 -data-dir=consul-data2 -ui -bind=127.0.0.1 -dns-port=8602 -http-port=8502 -serf-lan-port=8306 -serf-wan-port=8307 -server-port=8308 -node=node2 -join=127.0.0.1:8303

服务器3:

consul agent -server -bootstrap-expect=3 -data-dir=consul-data1 -ui -bind=127.0.0.1 -node=node3 -join=127.0.0.1:8303

然后我使用Spring Boot创建了两个名为service_Aservice_B的微服务.

Then I created 2 microservices using spring boot, called service_A and service_B.

Service_B调用service_A来获取一些数据.

Service_B calls service_A to get some data.

这两个服务都已在上述服务器之一中注册.

Both services get registered with one of the above servers.

application.properties中:

spring.cloud.consul.port=8501  #For service_A
spring.cloud.consul.port=8502  #For service_B

这很好,因为Service_B可以毫无问题地发现Service_A.

This works fine as Service_B discovers Service_A without any problem.

现在,当我杀死注册了service_A的领事服务器时,由于Service_B找不到Service_A,系统无法给出结果.

Now When I kill the consul server which service_A got registered, system fails to give results since Service_B cannot find Service_A.

我应该如何使该系统容错,这意味着即使领事服务器发生故障,在该服务器上注册的服务也会自动在群集中可用的另一台服务器上注册.

How should I make this system fault tolerant, Which means even though the consul server fails, services who registered with that server automatically get registered with another server which is available in the cluster.

我还需要知道领事如何在服务注册和发现中实现高可用性和容错能力.希望您能收到问题.

Further I need to know how consul achieves High availability and fault tolerance in service registration and discovery. Hope you get the Question.

推荐答案

显然,您可以在本地计算机上部署领事群集,但是您不能期望在同一台本地计算机上具有任何弹性机制或容错能力.这是因为您的spring服务(service_A& service_B)已配置为标识在给定领事服务器端口中bootstrap.yml(默认值为8500)下运行的领事服务器.

Apparently, you can deploy a consul cluster in your local machine but you cannot expect any resilience mechanism or fault tolerance in that same local machine. It's because your spring services (service_A & service_B) has been configured to identify the consul server which runs in the given consul server port under bootstrap.yml (default 8500).

 spring:
   cloud:
    consul:
     config:
      watch:
       enabled: true
     port: 8500
     discovery:
      instanceId: ${spring.application.name}:${random.value}

因此,每个服务都将发现在8500端口下运行的领事服务器(您可以根据需要进行更改).如果在同一台本地计算机上运行consul群集,则无法为需要标识的每个群集节点分配相同的端口号(8500).为了在相同的IP地址下运行,它会有所不同.为此,您需要将每个领事节点部署在具有相同端口号8500的不同IP地址下.

So each services will discover the consul servers that runs under 8500 port (you can change it as you wish). If you are running your consul cluster in your same local machine you cannot assign the same port number (8500) to each cluster nodes that need to be identified. It will be differed in order to run under same ip address. To achieve this you will need to deploy each consul nodes under different ip addresses with the same port number 8500.

8301是用于处理LAN中八卦的农奴LAN端口.甚至每个节点上的此端口也可以相同,以维持集群的相互连接.

最简单的方法是在AWS VPC中使用私有子网.

The easiest way to achieve this is that to use a private subnet in a AWS VPC.

然后,您可以为每个子网节点分配单独的配置,并为每个服务器节点分配相同的端口号,以便您的services_A&带有 @EnableDiscoveryClient 批注的service_B.

And then you can assign separate configurations for each subnet nodes with the same port number for each server nodes so that it can be identified by your services_A & service_B with @EnableDiscoveryClient annotation.

这篇关于通过领事集群实现容错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆