Amazon web services 运行状况检查失败,代码为:[502]-云信息

Amazon web services 运行状况检查失败,代码为:[502]-云信息,amazon-web-services,amazon-ec2,amazon-cloudformation,amazon-ecs,aws-application-load-balancer,Amazon Web Services,Amazon Ec2,Amazon Cloudformation,Amazon Ecs,Aws Application Load Balancer,您好,我正在使用cloudforamtion创建ecs群集、服务和任务。在任务中,我只是简单地拉wordpress图像并将其连接到rds数据库。这里的问题是目标组中的实例进入draining状态,然后变得不健康。Wordpress出现在alb的dns中,但当您刷新它时,有时会出现错误502坏网关。我只是附加模板的错误可能存在最有可能我给了端口错误。我与数据库的连接很好(我已经检查了它,就像我在实例中使用ssh一样,然后使用了mysql-umysqldb-pmysql123a-h rds.endp

您好,我正在使用cloudforamtion创建ecs群集、服务和任务。在任务中,我只是简单地拉wordpress图像并将其连接到rds数据库。这里的问题是目标组中的实例进入
draining
状态,然后变得不健康。Wordpress出现在alb的dns中,但当您刷新它时,有时会出现错误
502坏网关
。我只是附加模板的错误可能存在最有可能我给了端口错误。我与数据库的连接很好(我已经检查了它,就像我在实例中使用ssh一样,然后使用了
mysql-umysqldb-pmysql123a-h rds.endpoint
命令)。targetgroup中的目标出现错误
运行状况检查失败,代码为:[502]

任务:

alb:

集群与服务

---
AWSTemplateFormatVersion: 2010-09-09

Parameters:

  KeyName:
    Type: AWS::EC2::KeyPair::KeyName
    Default: webserver

  DesiredCapacity:
    Type: Number
    Default: 2

  MinSize:
    Type: Number
    Default: 1

  MaxSize:
    Type: Number
    Default: 4  

  InstanceProfile:
    Type: String

  DefaultTargetGroup:
    Type: String
  
  Task:
    Type: String

  Albsg:
    Type: String

  VpcID:
    Type: String

  SubnetA:
    Type: String
      
  SubnetB:
    Type: String
  
  webserver:
    Type: String


Resources:

  MyCluster:
      Type: AWS::ECS::Cluster
      Properties: {}

  Myservice:
      Type: AWS::ECS::Service
      Properties: 
          Cluster: !Ref MyCluster        
          DeploymentController:   
              Type: ECS
          DesiredCount: 2
          LaunchType: EC2
          LoadBalancers: 
              - ContainerName: wordpress
                ContainerPort: 80
                TargetGroupArn: !Ref DefaultTargetGroup
          #Role: !Ref InstanceProfile
          SchedulingStrategy: REPLICA
          ServiceName: wordpress
          TaskDefinition: !Ref Task

  ec2instance:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash -xe

          yum update -y && yum install -y aws-cfn-bootstrap 

          echo ECS_CLUSTER=${MyCluster} >> /etc/ecs/ecs.config
          echo ECS_BACKEND_HOST= >> /etc/ecs/ecs.config           

          /opt/aws/bin/cfn-signal -e $? \
                --stack ${AWS::StackName} \
                --resource myASG \
                --region ${AWS::Region}

      BlockDeviceMappings:
        - DeviceName: /dev/xvda
          Ebs:
            DeleteOnTermination: "true"
            VolumeSize: 30
            VolumeType: gp2
      ImageId: ami-06e05a843071324d1 
      InstanceType: t2.small
      IamInstanceProfile: !Ref InstanceProfile
      KeyName: !Ref KeyName
      SecurityGroups:
          - Ref: webserver

  myASG:
    Type: AWS::AutoScaling::AutoScalingGroup
    CreationPolicy:
      ResourceSignal:
        Timeout: PT5M
        Count: !Ref DesiredCapacity
    Properties:
      #AutoScalingGroupName: myASG
      MinSize: !Ref MinSize
      MaxSize: !Ref MaxSize
      DesiredCapacity: !Ref DesiredCapacity
      HealthCheckGracePeriod: 300
      LaunchConfigurationName:
        Ref: ec2instance
      VPCZoneIdentifier:
        - !Ref SubnetA
        - !Ref SubnetB
      TargetGroupARNs:
        - !Ref DefaultTargetGroup
很可能我把端口给错了

在您的
中,键入:AWS::ECS::TaskDefinition
您已经为wordpress定义了端口80

但您的目标群体正在使用端口8080:

       Properties:
            Name: alb-tg
            VpcId: !Ref VpcID
            Port: 8080 # <--- should be 80
            Protocol: HTTP
很可能我把端口给错了

在您的
中,键入:AWS::ECS::TaskDefinition
您已经为wordpress定义了端口80

但您的目标群体正在使用端口8080:

       Properties:
            Name: alb-tg
            VpcId: !Ref VpcID
            Port: 8080 # <--- should be 80
            Protocol: HTTP

如果我想在prod和qa环境中部署相同的堆栈,我应该做哪些更改?我现在拥有的堆栈在名称上有冲突。@aws noob Hi。不确定。您必须提供一些新错误消息的示例。这似乎是一个新问题,你也可以考虑提出新的问题。如果我对当前问题的回答有帮助,我们将不胜感激。Marcin现在显示健康检查失败,代码如下:[302]:|@aws noob 302是重定向代码。可能你的健康检查结果是302而不是200。您可以使用修改预期的代码。如果要在prod和qa环境中部署相同的堆栈,我应该做哪些更改?我现在拥有的堆栈在名称上有冲突。@aws noob Hi。不确定。您必须提供一些新错误消息的示例。这似乎是一个新问题,你也可以考虑提出新的问题。如果我对当前问题的回答有帮助,我们将不胜感激。Marcin现在显示健康检查失败,代码如下:[302]:|@aws noob 302是重定向代码。可能你的健康检查结果是302而不是200。您可以使用修改预期的代码。
       Properties:
            Name: alb-tg
            VpcId: !Ref VpcID
            Port: 8080 # <--- should be 80
            Protocol: HTTP
    DefaultTargetGroup:
        Type: AWS::ElasticLoadBalancingV2::TargetGroup
        DependsOn: Alb
        Properties:
            Name: alb-tg
            VpcId: !Ref VpcID
            Port: 80
            Protocol: HTTP
            Matcher: 
              HttpCode: 302