如何访问使用CDK创建的负载平衡器中的EC2插座
我正在创建一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实例连接不可访问的所有情况下默认情况下都无法正常工作。它必须正确设置并配置<<<<<< /A>与特定的安全组一起工作。
Instance connect does not work in all instances by default. It must be properly setup and configured to work, with specific security groups.