What is an 应用程序负载均衡器? - Elastic Load Balancing
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门


What is an 应用程序负载均衡器?

Elastic Load Balancing 支持三种类型的负载均衡器:Application Load Balancer、Network Load Balancer 和 Classic Load Balancer。本指南讨论 Application Load Balancer。有关 Network Load Balancer 的更多信息,请参阅Network Load Balancer 用户指南。有关 Classic Load Balancer 的更多信息,请参阅Classic Load Balancer 用户指南

应用程序负载均衡器 components

A load balancer 作为客户的单点联系人。负载均衡器在多个可用区中的多个目标 (例如 EC2 实例) 间分配应用程序的传入流量。这将提高应用程序的可用性。可以向您的负载均衡器添加一个或多个侦听器。

A listener 使用您配置的协议和端口检查客户端的连接请求。您为侦听器定义的规则确定负载均衡器如何将请求路由到其已注册目标。每条规则由优先级、一个或多个操作以及一个或多个条件组成。当规则的条件满足时,将执行其操作。您必须为每个侦听器定义默认规则,并且可以选择定义其他规则。

每个 target group 使用您指定的协议和端口号,将请求路由到一个或多个已注册目标(例如ec2实例)。您可以向多个目标组注册一个目标。您可以对每个目标组配置运行状况检查。在注册到目标组 (它是使用负载均衡器的侦听器规则指定的) 的所有目标上,执行运行状况检查。


                基本组成部分 应用程序负载均衡器


应用程序负载均衡器 overview

应用程序负载均衡器在应用程序层正常工作,该层是开放系统互连 (OSI) 模型的第 7 层。负载均衡器收到请求后,将按照优先级顺序评估侦听器规则以确定应用哪个规则,然后从目标组中选择规则操作目标。可以配置侦听器规则,以根据应用程序流量的内容,将请求路由至不同的目标组。每个目标组的路由都是单独进行的,即使某个目标已在多个目标组中注册。可以配置目标组级别使用的路由算法。默认路由算法为轮询路由算法;或者,可以指定最少未完成请求路由算法。

可以根据需求变化在负载均衡器中添加和删除目标,而不会中断应用程序的整体请求流。Elastic Load Balancing 根据传输到应用程序的流量随时间的变化对负载均衡器进行扩展。Elastic Load Balancing 能够自动扩展以处理绝大部分工作负载。


有关详细信息,请参阅 如何 Elastic Load Balancing 工作Elastic Load Balancing 用户指南.

Benefits of migrating from a 传统负载均衡器

使用 应用程序负载均衡器 而不是 传统负载均衡器 具有以下优势:

  • Support for path-based routing. You can configure rules for your listener that forward requests based on the URL in the request. This enables you to structure your application as smaller services, and route requests to the correct service based on the content of the URL.

  • Support for host-based routing. You can configure rules for your listener that forward requests based on the host field in the HTTP header. This enables you to route requests to multiple domains using a single load balancer.

  • Support for routing based on fields in the request, such as standard and custom HTTP headers and methods, query parameters, and source IP addresses.

  • Support for routing requests to multiple applications on a single EC2 instance. You can register each instance or IP address with the same target group using multiple ports.

  • Support for redirecting requests from one URL to another.

  • Support for returning a custom HTTP response.

  • Support for registering targets by IP address, including targets outside the VPC for the load balancer.

  • Support for registering Lambda functions as targets.

  • Support for the load balancer to authenticate users of your applications through their corporate or social identities before routing requests.

  • Support for containerized applications. Amazon Elastic Container Service (Amazon ECS) can select an unused port when scheduling a task and register the task with a target group using this port. This enables you to make efficient use of your clusters.

  • Support for monitoring the health of each service independently, as health checks are defined at the target group level and many CloudWatch metrics are reported at the target group level. Attaching a target group to an Auto Scaling group enables you to scale each service dynamically based on demand.

  • Access logs contain additional information and are stored in compressed format.

  • Improved load balancer performance.

有关每个负载均衡器类型支持的功能的详细信息,请参阅 比较 Elastic Load Balancing 产品.

How to get started


Elastic Load Balancing 可与以下服务一起使用来提高应用程序的可用性和可扩展性。

  • Amazon EC2 — Virtual servers that run your applications in the cloud. You can configure your load balancer to route traffic to your EC2 instances.

  • Amazon EC2 Auto Scaling — Ensures that you are running your desired number of instances, even if an instance fails, and enables you to automatically increase or decrease the number of instances as the demand on your instances changes. If you enable Auto Scaling with Elastic Load Balancing, instances that are launched by Auto Scaling are automatically registered with the load balancer, and instances that are terminated by Auto Scaling are automatically de-registered from the load balancer.

  • AWS Certificate Manager — When you create an HTTPS listener, you can specify certificates provided by ACM. The load balancer uses certificates to terminate connections and decrypt requests from clients. For more information, see SSL 证书.

  • Amazon CloudWatch — Enables you to monitor your load balancer and take action as needed. For more information, see CloudWatch 的 指标应用程序负载均衡器.

  • Amazon ECS — Enables you to run, stop, and manage Docker containers on a cluster of EC2 instances. You can configure your load balancer to route traffic to your containers. For more information, see Service load balancing in the Amazon Elastic Container Service Developer Guide.

  • AWS Global Accelerator — Improves the availability and performance of your application. Use an accelerator to distribute traffic across multiple load balancers in one or more AWS Regions. For more information, see the AWS Global Accelerator 开发人员指南.

  • Route 53 — Provides a reliable and cost-effective way to route visitors to websites by translating domain names (such as www.example.com) into the numeric IP addresses (such as that computers use to connect to each other. AWS assigns URLs to your resources, such as load balancers. However, you might want a URL that is easy for users to remember. For example, you can map your domain name to a load balancer.

  • AWS WAF — You can use AWS WAF with your 应用程序负载均衡器 to allow or block requests based on the rules in a web access control list (web ACL). For more information, see Application Load Balancer 和 AWS WAF.

要查看与负载均衡器集成的服务的信息,请在 AWS 管理控制台中选择负载均衡器,并选择 Integrated services (集成的服务) 选项卡。


利用负载均衡器,您可以按实际用量付费。有关更多信息,请参阅 Elastic Load Balancing 定价