gpt4 book ai didi

linux - Docker - 如何编写自定义负载均衡器?

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:46 25 4
gpt4 key购买 nike

为了进一步了解 Docker,我想尝试编写一个自定义负载均衡器。我正在考虑使用默认网桥驱动程序创建一个 docker 网络,并将负载均衡器应用程序放入该网络的代理容器中。我将运行一个或多个具有多个副本的服务,代理将使用循环法将流量路由到每个容器。

我想代理应该知道同一网络中存在的所有其他实例以及它们提供的服务,以便进行负载平衡。这些是我的想法:

  • 对于网络中运行的每个容器,向代理发送请求以通知其可用性状态。我发现这是可行的,但需要自定义所有容器(以定期发送请求)。
  • 使代理向主机查询网络状态:我注意到命令 docker network inspect 提供了有关网络配置以及网络内运行的容器的详细信息,因此我想我可以发送也将此信息发送给代理。

我的问题是:首选哪种方法?第二种方法是否可行?如果是,是否有任何我应该查看的指南或文档?我对操作系统和网络知之甚少,因此非常感谢任何将这些东西放在一起的帮助。

最佳答案

您还必须查看术语Service Discovery/Service Registry 以及如何将它们与您的负载均衡器一起使用。

发件人:Service Discovery and Load Balancing

Service Discovery

When we're handling a microservice architecture, it's very possible that we have multiple services across multiple servers or even multiple data servers. While the end user might not care much about the location of any of these services, our application is highly concerned with the connection details for each service. This problem is addressed with Service Discovery.

1. What is Service Discovery?

As we mentioned, when services become spread out they become difficult to manage. It's tough to keep track of where each service is and what information details are needed to connect to each service. Service Discovery is exactly what it sounds like, the process of discovering all of our exposed services and how to connect with them.

This process of keeping track of multiple services is solved with the use of a Service Registry. Each service registers with the Service Registry upon creation, and the Service Registry is responsible for handling and maintaining the information required to connect to each service.

...

Since it's possible for microservices to go down from time to time, it's important to think of how that situation gets handled within the Service Registry. Generally a Service Registry is paired with a load balancer layer (mentioned in the previous section) that will seamlessly fail over upon discovering that the instance no longer exists. So if a service instance was to go down, the Service Registry would not be able to return the required information and the load balancer would kick in to handle it while also caching the service registry lookups.

关于linux - Docker - 如何编写自定义负载均衡器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55624785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com