gpt4 book ai didi

amazon-web-services - 应用程序负载均衡器 - 运行状况检查失败,代码为 : [301]

转载 作者:行者123 更新时间:2023-12-03 07:27:23 28 4
gpt4 key购买 nike

您好,我正在使用 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"

我的实例处于耗尽状态并且运行状况不佳,请参阅此屏幕截图: enter image description here

最佳答案

301 表示访问目标健康检查路径上的 ECS 主机正在执行重定向(因此是 301)。要修复此问题,请将运行状况检查中的路径更新为不会重定向的路径,或者更新运行状况检查状态代码以包含 301。这可以作为单个状态代码 (301) 或范围 (200-399) 来完成。

关于amazon-web-services - 应用程序负载均衡器 - 运行状况检查失败,代码为 : [301],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63288969/

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