首页 文章

未检查GCP目标组实例

提问于
浏览
0

我正在尝试在GCP上创建TCP / UDP负载均衡器以允许我的服务上的HA,但我注意到,当我创建目标组时,该组中的所有实例都被标记为不 Health 并且未被Google检查(我已经看过机器日志来检查它) . 防火墙是开放的,因为它是用于测试目的,所以我确信这不是问题 .

我已经使用具有类似检查配置的后端创建了一个HTTP / S负载均衡器,并且同一台机器被标记为 Health ,所以这不是该机器的问题(即使现在日志显示谷歌如何真正检查该实例) .

两个检查都是HTTP到端口80,所以我无法看到问题的位置以及两种负载 balancer 器检查器之间的区别 .

此外,我已检查禁用运行状况检查,但实例仍标记为运行状况不佳,并且流量未发送到任何实例,因此负载均衡器无效 .

是否需要任何其他配置来检查实例?

谢谢和问候!!

1 回答

  • 1

    创建TCP负载均衡器

    当您使用任何Google Cloud负载均衡器时,无需将VM的外部端口暴露给互联网,只有您的负载均衡器需要能够访问它 .

    steps to create a TCP load balancer are described here . 我发现使用 gcloud 并运行命令很方便,但您也可以使用Cloud Console UI来获得相同的结果 .

    我尝试了以下步骤,它适用于我(您可以轻松地修改它以使其与UDP一起使用 - 记住您仍然需要HTTP运行状况检查,即使使用UDP负载 balancer ):

    # Create 2 new instances
    gcloud compute instances create vm1 --zone us-central1-f
    gcloud compute instances create vm2 --zone us-central1-f
    
    # Make sure you have some service running on port 80 on these VMs after creation.
    
    # Create an address resource to act as the frontend VIP.
    gcloud compute addresses create net-lb-ip-1 --region us-central1
    
    # Create a HTTP health check (by default uses port 80).
    $ gcloud compute http-health-checks create hc-1
    
    # Create a target pool associated with the health check you just created.
    gcloud compute target-pools create tp-1 --region us-central1 --http-health-check hc-1
    
    # Add the instances to the target pool
    gcloud compute target-pools add-instances tp-1 --instances vm1,vm2 --instances-zone us-central1-f
    
    # Create a forwarding rule associated with the frontend VIP address we created earlier
    # which will forward the traffic to the target pool.
    $ gcloud compute forwarding-rules create fr-1 --region us-central1 --ports 80 --address net-lb-ip-1 --target-pool tp-1
    
    # Describe the forwarding rule
    gcloud compute forwarding-rules describe fr-1 --region us-central1
    
    IPAddress: 1.2.3.4
    IPProtocol: TCP
    creationTimestamp: '2017-07-19T10:11:12.345-07:00'
    description: ''
    id: '1234567890'
    kind: compute#forwardingRule
    loadBalancingScheme: EXTERNAL
    name: fr-1
    portRange: 80-80
    region: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/us-central1
    selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/us-central1/forwardingRules/fr-1
    target: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/us-central1/targetPools/tp-1
    
    # Check the health status of the target pool and verify that the
    # target pool considers the backend instances to be healthy
    $ gcloud compute target-pools get-health tp-1
    ---
    healthStatus:
    - healthState: HEALTHY
      instance: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/us-central1-f/instances/vm1
      ipAddress: 1.2.3.4
    kind: compute#targetPoolInstanceHealth
    ---
    healthStatus:
    - healthState: HEALTHY
      instance: https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/zones/us-central1-f/instances/vm2
      ipAddress: 1.2.3.4
    kind: compute#targetPoolInstanceHealth
    

    非代理TCP / UDP负载均衡器需要HTTP运行状况检查

    如果您使用的是UDP负载均衡器(在Google CLoud中被视为网络负载均衡),您需要启动一个基本的HTTP服务器,除了正在侦听UDP端口的服务之外,它还可以响应HTTP运行状况检查进来的交通 .

    这同样适用于基于非代理的TCP负载均衡器(在Google Cloud中也被视为网络负载均衡) .

    这是documented here .

    运行状况检查运行状况检查可确保计算引擎仅将新连接转发给已启动并准备接收它们的实例 . 计算引擎以指定的频率向每个实例发送运行状况检查请求;一旦实例超过其允许的 Health 检查失败次数,它就不再被视为接收新流量的合格实例 . 将不会主动终止现有连接,这允许实例正常关闭并关闭TCP连接 . 运行状况检查将继续查询运行状况不佳的实例,并在满足指定数量的成功检查后将实例返回到池中 . 网络负载 balancer 依赖于传统的HTTP运行状况检查来确定实例运行状况 . 即使您的服务不使用HTTP,您也需要至少在运行状况检查系统可以查询的每个实例上运行基本Web服务器 .

相关问题