gpt4 book ai didi

amazon-web-services - 使用 Packer.io 创建基本 AWS AMI 时遇到问题。 SSH 超时

转载 作者:行者123 更新时间:2023-12-03 00:54:57 37 4
gpt4 key购买 nike

我正在尝试按照 these 说明使用 Packer.io 构建基本 AWS 镜像。但这对我不起作用。

这是我的模板文件:

{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami": "ami-146e2a7c",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-example {{timestamp}}",

# The following 2 lines don't appear in the tutorial.
# But I had to add them because it said this source AMI
# must be launched inside a VPC.
"vpc_id": "vpc-98765432",
"subnet_id": "subnet-12345678"
}]
}

您会注意到,我必须在底部添加两行(针对 VPC 和子网),从而偏离说明。这是因为我不断收到以下错误:

==> amazon-ebs: Error launching source instance: The specified instance type 
can only be used in a VPC. A subnet ID or network interface
ID is required to carry out the request.
(VPCResourceNotSpecified)

该 VPC 和子网是我必须手动创建的临时网络。但我为什么要这么做呢?为什么打包程序不创建这些然后删除它们,就像我看到它创建临时安全组和 key 对一样?

此外,即使在我添加这两行之后,它也无法创建 AMI,因为它出现 SSH 超时。为什么?我可以轻松通过 SSH 手动连接到此 VPC 中的其他实例。临时加壳实例具有 InstanceState=RunningStatusChecks=2/2 和允许来自世界各地的 SSH 的 SecurityGroup。

请参阅下面的加壳命令的调试输出:

$ packer build -debug -var 'aws_access_key=MY_ACCESS_KEY' -var 'aws_secret_key=MY_SECRET_KEY' packer_config_basic.json
Debug mode enabled. Builds will not be parallelized.
amazon-ebs output will be in this color.

==> amazon-ebs: Inspecting the source AMI...
==> amazon-ebs: Pausing after run of step 'StepSourceAMIInfo'. Press enter to continue.
==> amazon-ebs: Creating temporary keypair: packer 99999999-8888-7777-6666-555555555555
amazon-ebs: Saving key for debug purposes: ec2_amazon-ebs.pem
==> amazon-ebs: Pausing after run of step 'StepKeyPair'. Press enter to continue.
==> amazon-ebs: Creating temporary security group for this instance...
==> amazon-ebs: Authorizing SSH access on the temporary security group...
==> amazon-ebs: Pausing after run of step 'StepSecurityGroup'. Press enter to continue.
==> amazon-ebs: Launching a source AWS instance...
amazon-ebs: Instance ID: i-12345678
==> amazon-ebs: Waiting for instance (i-12345678) to become ready...
amazon-ebs: Private IP: 10.0.2.204
==> amazon-ebs: Pausing after run of step 'StepRunSourceInstance'. Press enter to continue.
==> amazon-ebs: Waiting for SSH to become available...
==> amazon-ebs: Timeout waiting for SSH.
==> amazon-ebs: Pausing before cleanup of step 'StepRunSourceInstance'. Press enter to continue.
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Pausing before cleanup of step 'StepSecurityGroup'. Press enter to continue.
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Pausing before cleanup of step 'StepKeyPair'. Press enter to continue.
==> amazon-ebs: Deleting temporary keypair...
==> amazon-ebs: Pausing before cleanup of step 'StepSourceAMIInfo'. Press enter to continue.
Build 'amazon-ebs' errored: Timeout waiting for SSH.

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.

最佳答案

  1. 您正在使用 t2.micro 实例类型,该类型只能在 VPC 环境中运行(请参阅 T2 Instances )。

  2. 由于您位于VPC中,默认情况下所有流量都位于防火墙后面,因此您需要设置安全组以允许您的 IP访问该实例上的 SSH 端口。

更简单的方法是使用 m3.medium 实例类型,有点贵,但它运行速度更快,并且您不需要在以下位置设置VPC/安全组全部。

关于amazon-web-services - 使用 Packer.io 创建基本 AWS AMI 时遇到问题。 SSH 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28775855/

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