【问题标题】:Having problems with Packer: amazon-ebs: Timeout waiting for SSHPacker 出现问题:amazon-ebs: Timeout waiting for SSH
【发布时间】:2019-07-13 07:56:52
【问题描述】:

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

正在使用的 Packer 版本是 1.3.4,并且私有子网可以通过公共子网和路由表访问 NAT 网关。 Butas 问题可能无法到达实例,然后我也尝试过使用其他参数,例如:ssh_interface,其值为private_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?

【问题讨论】:

  • jww 感谢您的提示,我将转移问题。我在这里做了这个问题,因为它是基础设施即代码,并且这里有 Terraform 和 Packer 的主题。我还猜想可以使用公共网络中的堡垒来解决这个问题,该堡垒可以通过路由表访问私有网络中的实例。那么谢谢。

标签: amazon-ec2 ssh packer


【解决方案1】:

您无法通过 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

问候

【讨论】:

  • 谢谢,我想第一个选项可以让我快速解决问题,但我将阅读第二个选项以避免将来出现问题。
【解决方案2】:

我遇到了同样的问题。我发现的问题是我的所有实例都在默认 VPC 中启动。即使我设置了 SG 和路由表以允许来自 0.0.0.0/0 的入口 ssh 流量。即使从控制台也无法访问。 因此必须创建具有适当互联网网关、安全组和路由表的自定义 VPC,而我的最终 builders 是这样的。

  "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"

  }],

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

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,导致我遇到的问题是使用了加密的 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
            }
          ],
          ...
        }
      ],
    

    【讨论】:

    • 也为我工作。
    【解决方案4】:

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

    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 &lt;path to your ssh keys&gt; 添加 ssh 密钥,它应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-01
      • 2022-10-14
      • 2019-01-06
      • 2019-07-30
      • 2021-11-08
      • 1970-01-01
      • 2013-10-29
      • 1970-01-01
      相关资源
      最近更新 更多