应用程序负载均衡器 - 运行状况检查失败,代码如下:[301]
Application load balancer - Health checks failed with these codes: [301]
您好,我正在使用 cloudformation 创建 ecs 集群,我在配置任务和应用程序负载平衡器端口时遇到了问题,因为我的实例变得不健康。我可能给了错误的端口,请指出错误。我只在我认为错误的地方附上模板。
任务模板:
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ExRole:
Type: String
RDS:
Type: String
Dbname:
Type: String
dbpassword:
Type: String
containerName:
Type: String
taskFamily:
Type: String
Resources:
Task:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref taskFamily
Cpu: 1 vCPU
ExecutionRoleArn: !Ref ExRole
Memory: 1 GB
NetworkMode: bridge
RequiresCompatibilities:
- EC2
TaskRoleArn: !Ref ExRole
ContainerDefinitions:
- Essential: true
Image: wordpress:latest
Name: !Ref containerName
PortMappings:
- ContainerPort: 80
HostPort: 0
Protocol: tcp
Environment:
- Name: WORDPRESS_DB_HOST
Value: !Ref RDS
- Name: WORDPRESS_DB_USER
Value: !Ref Dbname
- Name: WORDPRESS_DB_PASSWORD
Value: !Ref dbpassword
- Name: WORDPRESS_DB_NAME
Value: !Ref Dbname
Outputs:
Task:
Description: Contains all the task specifications
Value: !Ref Task
Export:
Name: !Sub "${AWS::StackName}-Task"
应用程序负载均衡器:
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
SubnetA:
Type: String
SubnetB:
Type: String
VpcID:
Type: String
Env:
Type: String
Resources:
Albsg:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub "albsg-${Env}"
VpcId: !Ref VpcID
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
Description: For traffic from Internet
GroupDescription: Security Group for demo server
Alb:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Name: !Sub "Alb-${Env}"
Scheme: internet-facing
SecurityGroups:
- !Ref Albsg
Subnets:
- Ref: "SubnetA"
- Ref: "SubnetB"
Type: application
DefaultTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: Alb
Properties:
Name: !Sub "Albtg-${Env}"
VpcId: !Ref VpcID
Port: 80
Protocol: HTTP
Matcher:
HttpCode: 302
LoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref Alb
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref DefaultTargetGroup
Outputs:
Albsg:
Description: security group for application load balancer
Value: !Ref Albsg
Export:
Name: !Sub "${AWS::StackName}-Albsg"
Alb:
Description: application load balancer
Value: !Ref Alb
Export:
Name: !Sub "${AWS::StackName}-Alb"
DefaultTargetGroup:
Description: Default Target Group
Value: !Ref DefaultTargetGroup
Export:
Name: !Sub "${AWS::StackName}-DefaultTargetGroup"
我的实例处于耗尽状态并且运行状况不佳,请参见此屏幕截图:
301是在其目标健康检查路径上访问ECS主机正在执行重定向(因此是301)。要修复,请将健康检查中的路径更新为不会重定向的路径,或者更新健康检查状态代码以包含 301
。这可以作为单个状态代码 (301
) 或作为范围 (200-399
) 来完成。
您好,我正在使用 cloudformation 创建 ecs 集群,我在配置任务和应用程序负载平衡器端口时遇到了问题,因为我的实例变得不健康。我可能给了错误的端口,请指出错误。我只在我认为错误的地方附上模板。
任务模板:
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ExRole:
Type: String
RDS:
Type: String
Dbname:
Type: String
dbpassword:
Type: String
containerName:
Type: String
taskFamily:
Type: String
Resources:
Task:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref taskFamily
Cpu: 1 vCPU
ExecutionRoleArn: !Ref ExRole
Memory: 1 GB
NetworkMode: bridge
RequiresCompatibilities:
- EC2
TaskRoleArn: !Ref ExRole
ContainerDefinitions:
- Essential: true
Image: wordpress:latest
Name: !Ref containerName
PortMappings:
- ContainerPort: 80
HostPort: 0
Protocol: tcp
Environment:
- Name: WORDPRESS_DB_HOST
Value: !Ref RDS
- Name: WORDPRESS_DB_USER
Value: !Ref Dbname
- Name: WORDPRESS_DB_PASSWORD
Value: !Ref dbpassword
- Name: WORDPRESS_DB_NAME
Value: !Ref Dbname
Outputs:
Task:
Description: Contains all the task specifications
Value: !Ref Task
Export:
Name: !Sub "${AWS::StackName}-Task"
应用程序负载均衡器:
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
SubnetA:
Type: String
SubnetB:
Type: String
VpcID:
Type: String
Env:
Type: String
Resources:
Albsg:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Sub "albsg-${Env}"
VpcId: !Ref VpcID
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
Description: For traffic from Internet
GroupDescription: Security Group for demo server
Alb:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Name: !Sub "Alb-${Env}"
Scheme: internet-facing
SecurityGroups:
- !Ref Albsg
Subnets:
- Ref: "SubnetA"
- Ref: "SubnetB"
Type: application
DefaultTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: Alb
Properties:
Name: !Sub "Albtg-${Env}"
VpcId: !Ref VpcID
Port: 80
Protocol: HTTP
Matcher:
HttpCode: 302
LoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref Alb
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref DefaultTargetGroup
Outputs:
Albsg:
Description: security group for application load balancer
Value: !Ref Albsg
Export:
Name: !Sub "${AWS::StackName}-Albsg"
Alb:
Description: application load balancer
Value: !Ref Alb
Export:
Name: !Sub "${AWS::StackName}-Alb"
DefaultTargetGroup:
Description: Default Target Group
Value: !Ref DefaultTargetGroup
Export:
Name: !Sub "${AWS::StackName}-DefaultTargetGroup"
我的实例处于耗尽状态并且运行状况不佳,请参见此屏幕截图:
301是在其目标健康检查路径上访问ECS主机正在执行重定向(因此是301)。要修复,请将健康检查中的路径更新为不会重定向的路径,或者更新健康检查状态代码以包含 301
。这可以作为单个状态代码 (301
) 或作为范围 (200-399
) 来完成。