如何访问使用CDK创建的负载平衡器中的EC2插座

发布于 2025-02-07 13:45:17 字数 1974 浏览 4 评论 0原文

我正在创建一个ASG,它将具有经典的负载平衡器。所需数量的实例为5,我正在使用用户数据启动ASG创建,但是即使经过多次实验,负载平衡器显示出不健康的主机,我还是将VPC的子网类型更改为公共场所,但ELB保留的健康宿主数量0。 以下是代码段,

 Vpc vpc=new Vpc(this,"MyVPC");
        AutoScalingGroup asg = AutoScalingGroup.Builder.create(this,"AutoScalingGroup").vpcSubnets(SubnetSelection.builder()
                        .subnetType(SubnetType.PUBLIC)
                        .build()).vpc(vpc).instanceType(InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO))
                .machineImage(new AmazonLinuxImage()).minCapacity(1).desiredCapacity(5).maxCapacity(10).build();
        asg.addUserData("#!/bin/bash\n" +
                "# Use this for your user data (script from top to bottom)\n" +
                "# install httpd (Linux 2 version)\n" +
                "yum update -y\n" +
                "yum install -y httpd\n" +
                "systemctl start httpd\n" +
                "systemctl enable httpd\n" +
                "echo \"<h1>Hello World from $(hostname -f)</h1>\" > /var/www/html/index.html");
        LoadBalancer loadbalancer=LoadBalancer.Builder.create(this,"ElasticLoadBalancer").vpc(vpc).internetFacing(Boolean.TRUE).healthCheck(software.amazon.awscdk.services.elasticloadbalancing.HealthCheck.builder().port(80).build())
                .build();
        loadbalancer.addTarget(asg);
        ListenerPort listenerPort = loadbalancer.addListener(LoadBalancerListener.builder().externalPort(80).build());

默认情况下,通过ASG创建的实例也无法在网络上访问ASG(即使更改安全组或将其全部放在公共子网中,也无法从实例Connect中访问它们。 以下是EC2的列表和ELB的指标 这显示了EC2实例列表 fresent, elb的指标,动机是从存在的代码中在这里

I am creating an ASG which will have a classical load balancer . The desired number of instances is 5 , I am starting the asg creation using a userdata but even after experimenting multiple times the load balancer shows unhealthy hosts,i changed the subnet type of the vpc as public but the number of healthy host for the elb remains 0 .
Below is the code segment

 Vpc vpc=new Vpc(this,"MyVPC");
        AutoScalingGroup asg = AutoScalingGroup.Builder.create(this,"AutoScalingGroup").vpcSubnets(SubnetSelection.builder()
                        .subnetType(SubnetType.PUBLIC)
                        .build()).vpc(vpc).instanceType(InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO))
                .machineImage(new AmazonLinuxImage()).minCapacity(1).desiredCapacity(5).maxCapacity(10).build();
        asg.addUserData("#!/bin/bash\n" +
                "# Use this for your user data (script from top to bottom)\n" +
                "# install httpd (Linux 2 version)\n" +
                "yum update -y\n" +
                "yum install -y httpd\n" +
                "systemctl start httpd\n" +
                "systemctl enable httpd\n" +
                "echo \"<h1>Hello World from $(hostname -f)</h1>\" > /var/www/html/index.html");
        LoadBalancer loadbalancer=LoadBalancer.Builder.create(this,"ElasticLoadBalancer").vpc(vpc).internetFacing(Boolean.TRUE).healthCheck(software.amazon.awscdk.services.elasticloadbalancing.HealthCheck.builder().port(80).build())
                .build();
        loadbalancer.addTarget(asg);
        ListenerPort listenerPort = loadbalancer.addListener(LoadBalancerListener.builder().externalPort(80).build());

Also the instances those are created by default via ASG cannot be accessed on the web(by hitting their public IP) even after changing the security groups or making them all in a public subnet they are not accessible from instance connect.
Below is the list of ec2 present and the metrics for the elb
This shows the list of EC2 instances present ,the metrics of elb,motivation has been taken from the code present here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2025-02-14 13:45:18

从实例连接

无法访问

实例连接不可访问的所有情况下默认情况下都无法正常工作。它必须正确设置并配置<<<<<< /A>与特定的安全组一起工作。

not accessible from instance connect

Instance connect does not work in all instances by default. It must be properly setup and configured to work, with specific security groups.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文