昨天,我在AWS成立了我的第一个自动标度小组。我编写了一个云init/userdata脚本来安装我的应用程序,并且对它进行了40次测试,没有任何错误。就在我回家之前,它突然停止了工作,新的开始永远不会变得健康,并最终被终止,一旦他们的宽限期结束。
今天早上我进来,发现这个问题还在继续。我将SSH放入一个实例中,查看了云init-output.log文件,发现了以下内容:
Err:1 http://ap-southeast-2.ec2.archive.ubuntu.com/ubuntu xenial InRelease
Could not connect to ap-southeast-2.ec2.archive.ubuntu.com:80 (54.253.131.141), connection timed out [IP: 54.253.131.141 80]
Err:2 http://ap-southeast-2.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease
Unable to connect to ap-southeast-2.ec2.archive.ubuntu.com:http: [IP: 54.253.131.141 80]
Err:3 http://ap-southeast-2.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease
Unable to connect to ap-southeast-2.ec2.archive.ubuntu.com:http: [IP: 54.253.131.141 80]
Err:4 http://security.ubuntu.com/ubuntu xenial-security InRelease
Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8001::21 80]
Reading package lists...
W: Failed to fetch http://ap-southeast-2.ec2.archive.ubuntu.com/ubuntu/dists/xenial/InRelease Could not connect to ap-southeast-2.ec2.archive.ubuntu.com:80 (54.253.131.141), connection timed out [IP: 54.253.131.141 80]
W: Failed to fetch http://ap-southeast-2.ec2.archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Unable to connect to ap-southeast-2.ec2.archive.ubuntu.com:http: [IP: 54.253.131.141 80]
W: Failed to fetch http://ap-southeast-2.ec2.archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease Unable to connect to ap-southeast-2.ec2.archive.ubuntu.com:http: [IP: 54.253.131.141 80]
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8001::21 80]
W: Some index files failed to download. They have been ignored, or old ones used instead.这是由脚本顶部的sudo apt-get update命令引起的。在此之后,我的sudo apt-get -y install命令中的多个包无法安装,从而使我的应用程序无法工作。
奇怪的是,如果我通过SSH运行sudo apt-get update,它不会出现任何错误,只有在云init脚本中它才不能工作。我的预感是,在脚本执行时,实例可能还没有连接到网络?如果是这样的话,我如何处理这个问题呢?
编辑:我不能再复制这个问题了。为了防止问题再次发生,我将其添加到脚本的顶部:
until ping -c1 ap-southeast-2.ec2.archive.ubuntu.com &>/dev/null; do echo "waiting for networking to initialise"; done但是“等待网络初始化”的消息并不存在于云init-output.log中,因此这段代码似乎没有做任何事情,这个问题可能是暂时的。如果有人知道是什么原因造成了这一问题,以及如何更可靠地减轻这一问题,请告诉我。
发布于 2017-07-20 23:54:56
我弄明白问题出在哪里了,我觉得有点傻。事实证明,实例需要公共IP才能访问VPC之外的服务器。我想我以为会有某种NAT允许服务器在没有公共IP的情况下拨号,但我现在看到了,如果我想这样做的话,我必须用NAT网关来设置它。
这个问题很难解决的原因是为了在SSH中查看日志,我为实例分配了一个Elastic,这导致了脚本的成功。
https://serverfault.com/questions/863378
复制相似问题