繁体   English   中英

Packer 出现问题:amazon-ebs: Timeout waiting for SSH

[英]Having problems with Packer: amazon-ebs: Timeout waiting for SSH

我是 Packer 的新手,我正在尝试使用 VPC 的专用网络创建映像,但我不断遇到错误*amazon-ebs: Timeout waiting for SSH.*

使用的 Packer 版本是1.3.4 ,私有子网可以通过公共子网和路由表访问 NAT 网关。 但是由于问题无法到达实例,所以我也尝试过使用其他参数,例如: ssh_interfaceprivate_dnsassociate_public_ip_address的值。 但即使是改变我也得到同样的错误。

我正在使用的模板有下一个内容

"builders": [
{
  "type": "amazon-ebs",
  "access_key": "{{user `aws_access_key`}}",
  "secret_key": "{{user `aws_secret_key`}}",
  "region": "{{user `region`}}",
  "source_ami": "{{user `source_ami`}}",
  "instance_type": "{{user `instance_type`}}",
  "iam_instance_profile": "{{user `role`}}",
  "ssh_username": "{{user `ssh_username`}}",
  "ssh_timeout": "15m",
  "vpc_id": "{{user `vpc_id`}}",
  "subnet_id": "{{user `subnet_id`}}",
  "associate_public_ip_address": true,
  "ami_name": "{{user `name`}}.{{isotime \"2006-01-02T150405Z\"}}",
  "ami_description": "based on {{user `source_ami`}}",
  "tags": {
    "Name": "{{user `name`}}"
  }]

在模板中我没有定义安全组,但在 Packer 的日志中我看到它能够创建一个临时安全组,那么对端口 22 的访问也应该可用

==> amazon-ebs: Pausing after run of step 'StepKeyPair'. Press enter to continue. 
==> amazon-ebs: Creating temporary security group for this instance: packer_5
c6b3667-c41f-92bc-aa89-efc5f3a2d8a8
==> amazon-ebs: Authorizing access to port 22 from 0.0.0.0/0 in the temporary security group...
==> amazon-ebs: Pausing after run of step 'StepSecurityGroup'. Press enter to continue. 
==> amazon-ebs: Pausing after run of step 'StepCleanupVolumes'. Press enter to continue. 
==> amazon-ebs: Launching a source AWS instance...

但问题仍然存在。 模板中是否缺少某些内容? 或者我应该做些什么来生成AMI?

您无法通过 NAT 网关访问 ec2。 AWS 中的 NAT 网关用于提供从 VPC 而非 VPC 的 Internet 访问。

您有多种选择:

  1. Make packer 在具有公共 ip 的公共子网中启动 ec2。 在 VPC 和路由表中正确配置了 IGW
  2. 在 AWS 中部署一个安全堡垒主机,并使用它从带有打包程序的工作站跳转到 ec2。 您需要使用自定义通信器在 packer.json 中配置一些内容。 这里的文档https://www.packer.io/docs/templates/communicator.html#ssh

问候

我面临着同样的问题。 我发现的问题是我的所有实例都在默认 VPC 中启动。 即使我已经设置了 SG 和路由表以允许来自0.0.0.0/0 的入口 ssh 流量。 即使从控制台访问仍然不舒服。 所以必须使用适当的互联网网关、安全组和路由表创建自定义 VPC,我的最终构建器是这样的。

  "builders": [{
        "type": "amazon-ebs",
        "access_key": "{{user `aws_access_key`}}",
        "secret_key": "{{user `aws_secret_key`}}",
        "region": "us-******",
        "source_ami": "ami-*********",
        "instance_type": "t2.micro",
        "ssh_username": "ubuntu",
        "ami_name": "packer-example {{timestamp}}",
        "vpc_id": "{VPC id i had created}",
        "subnet_id": "{Subnet i had created}",
        "security_group_id": "sg with proper ingress port 22 rule enabled from 0.0.0.0"

  }],

希望能解决您的问题并原谅我的词汇量:)

还有一种可能是打包程序无法找到登录堡垒主机的密钥并等待其他方法登录。

使用 export PACKER_LOG=1 收集的日志如下。

==> amazon-ebs: Waiting for SSH to become available...
2020/07/30 12:19:22 packer: 2020/07/30 12:19:22 [DEBUG] TCP connection to SSH ip/port failed: Error connecting to bastion: ssh: handshake failed: ssh: unable to authenticate, attempted methods [publickey none], no supported methods remain
2020/07/30 12:19:27 packer: 2020/07/30 12:19:27 [DEBUG] TCP connection to SSH ip/port failed: Error connecting to bastion: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2020/07/30 12:19:32 packer: 2020/07/30 12:19:32 [DEBUG] TCP connection to SSH ip/port failed: Error connecting to bastion: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2020/07/30 12:19:37 packer: 2020/07/30 12:19:37 [DEBUG] TCP connection to SSH ip/port failed: Error connecting to bastion: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2020/07/30 12:19:43 packer: 2020/07/30 12:19:43 [DEBUG] TCP connection to SSH ip/port failed: Error connecting to bastion: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2020/07/30 12:19:48 packer: 2020/07/30 12:19:48 [DEBUG] TCP connection to SSH ip/port failed: Error connecting to bastion: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

此外,验证ssh-add -l不应列出密钥,然后我们知道加壳程序无法找到登录密钥。

在这种情况下,我们只需要使用ssh-add <path to your ssh keys> ,它应该可以解决问题。

我遇到了同样的问题,导致它的原因是使用加密的 AMI,而我明确指出“错误”。

  "builders": [
    {
      "launch_block_device_mappings": [
        {
          "device_name": "/dev/sda1",
          "volume_type": "gp2",
          "encrypted": true      <-- I was setting it to 'false' while only 'true' works
        }
      ],
      ...
    }
  ],

我有一个安全组(防火墙)设置,阻止了来自移动网络的连接。 当我从受信任的(允许的)网络连接时,它运行良好。

请注意以下步骤:

2022/07/31 05:58:15 packer-builder-amazon-ebs plugin: Using specified security groups: [sg-0123456789abcd sg-0123456789abce]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM