AWS ec2 SSH无法访问连接超时

AWS ec2 SSH无法访问连接超时

我遇到了无法使用 SSH 连接和访问我的 EC2 的问题,并且显示连接超时。创建 EC2 后,我可以连接和访问。3 分钟后,我无法连接和访问它。请告诉我如何解决这个问题?

[    7.540187] cloud-init[1047]: Cloud-init v. 17.1 running 'init' at Wed, 20 Dec 2017 08:53:52 +0000. Up 7.27 seconds.
[    7.548824] cloud-init[1047]: ci-info: ++++++++++++++++++++++++++++++++++++++Net device info++++++++++++++++++++++++++++++++++++++
[    7.560826] cloud-init[1047]: ci-info: +--------+------+-----------------------------+---------------+-------+-------------------+
[    7.572244] cloud-init[1047]: ci-info: | Device |  Up  |           Address           |      Mask     | Scope |     Hw-Address    |
[    7.580877] cloud-init[1047]: ci-info: +--------+------+-----------------------------+---------------+-------+-------------------+
[    7.592982] cloud-init[1047]: ci-info: |  eth0  | True |        172.31.20.209        | 255.255.240.0 |   .   | 06:0c:2a:5e:5b:be |
[    7.604832] cloud-init[1047]: ci-info: |  eth0  | True | fe80::40c:2aff:fe5e:5bbe/64 |       .       |  link | 06:0c:2a:5e:5b:be |
[    7.616448] cloud-init[1047]: ci-info: |   lo   | True |          127.0.0.1          |   255.0.0.0   |   .   |         .         |[[0;32m  OK  [0m] Started Initial cloud-init job (metadata service crawler).
[    7.625744] cloud-init[1047]: ci-info: |   lo   | True |           ::1/128           |       .       |  host |         .         |
[[0;32m  OK  [0m] Reached target Cloud-config availability.
[[0;32m  OK  [0m
[    7.636537] cloud-init[1047]: ci-info: +--------+------+-----------------------------+---------------+-------+-------------------+] Reached target Network is Online.
         Starting iSCSI initiator daemon (iscsid)...
[[0;32m  OK  [0m] Reached target System Initialization.
[    7.648807] cloud-init[1047]: ci-info: +++++++++++++++++++++++++++++Route IPv4 info+++++++++++++++++++++++++++++
[[0;32m  OK  [0m] Listening on UUID daemon activation socket.
[    7.657063] cloud-init
[[0;32m  OK  [0m] Listening on ACPID Listen Socket.
[1047]: ci-info: +-------+-------------+-------------+---------------+-----------+-------+
[[0;32m  OK  [0m] Started Timer to automatically refresh installed snaps.
[    7.672702] cloud-init[1047]: [[0;32m  OK  [0m] Started Daily Cleanup of Temporary Directories.
         Starting Socket activation for snappy daemon.ci-info: | Route | Destination |   Gateway   |    Genmask    | Interface | Flags |
[    7.684164] cloud-init[1047]: ci-info: +-------+-------------+-------------+---------------+-----------+-------+

[[0;32m  OK  [0m] Started Daily apt download activities.
[[0;32m  OK  [0m] Started Daily apt upgrade and clean activities.
[[0;32m  OK  [0m] Reached target Timers.[    7.696431] cloud-init[1047]: ci-info: |   0   |   0.0.0.0   | 172.31.16.1 |    0.0.0.0    |    eth0   |   UG  |
[    7.700455] cloud-init[1047]: ci-info: |   1   | 172.31.16.0 |   0.0.0.0   | 255.255.240.0 |    eth0   |   U   |

         Starting LXD - unix socket.
[[0;32m  OK  [0m] Listening on D-Bus System Message Bus Socket.
[    7.705061] cloud-init[1047]: ci-info: +-------+-------------+-------------+---------------+-----------+-------+
[[0;32m  OK  [0m] Started ACPI Events Check.
[[0;32m  OK  [0m] Reached target Paths.
[[0;32m  OK  [0m] Listening on Socket activation for snappy daemon.
[[0;32m  OK  [0m] Listening on LXD - unix socket.
[[0;32m  OK  [0m] Started iSCSI initiator daemon (iscsid).
         Starting Login to default iSCSI targets...
[[0;32m  OK  [0m] Reached target Sockets.
[[0;32m  OK  [0m] Reached target Basic System.
         Starting LSB: MD monitoring daemon...
         Starting LXD - container startup/shutdown...
[[0;32m  OK  [0m] Started ACPI event daemon.
         Starting Snappy daemon...
[[0;32m  OK  [0m] Started Unattended Upgrades Shutdown.
         Starting /etc/rc.local Compatibility...
         Starting LSB: Record successful boot for GRUB...
[[0;32m  OK  [0m] Started Regular background program processing daemon.
         Starting A high performance web server and a reverse proxy server...
[[0;32m  OK  [0m] Started D-Bus System Message Bus.
         Starting Apply the settings specified in cloud-config...
[[0;32m  OK  [0m] Started FUSE filesystem for LXC.
[[0;32m  OK  [0m] Started Deferred execution scheduler.
         Starting System Logging Service...
         Starting Login Service...
         Starting Accounts Service...
         Starting OpenBSD Secure Shell server...
[[0;32m  OK  [0m] Started LXD - container startup/shutdown.
[[0;32m  OK  [0m] Started /etc/rc.local Compatibility.
[[0;32m  OK  [0m] Started Login to default iSCSI targets.
[[0;32m  OK  [0m] Started LSB: MD monitoring daemon.
[[0;32m  OK  [0m] Started OpenBSD Secure Shell server.
[[0;32m  OK  [0m] Started Snappy daemon.
[[0;32m  OK  [0m] Started LSB: Record successful boot for GRUB.
[[0;32m  OK  [0m] Started A high performance web server and a reverse proxy server.
[[0;32m  OK  [0m] Started Login Service.
         Starting Authenticate and Authorize Users to Run Privileged Tasks...
[[0;32m  OK  [0m] Reached target Remote File Systems (Pre).
[[0;32m  OK  [0m] Reached target Remote File Systems.
         Starting LSB: Set the CPU Frequency Scaling governor to "ondemand"...
         Starting LSB: automatic crash report generation...
         Starting Permit User Sessions...
         Starting LSB: daemon to balance interrupts for SMP systems...
[[0;32m  OK  [0m] Started Permit User Sessions.
[[0;32m  OK  [0m] Started Authenticate and Authorize Users to Run Privileged Tasks.
[[0;32m  OK  [0m] Started Accounts Service.
         Starting Hold until boot process finishes up...
         Starting Terminate Plymouth Boot Screen...
[[0;32m  OK  [0m] Started LSB: Set the CPU Frequency Scaling governor to "ondemand".
[[0;32m  OK  [0m] Started LSB: automatic crash report generation.
[[0;32m  OK  [0m] Started Hold until boot process finishes up.
[[0;32m  OK  [0m] Started Terminate Plymouth Boot Screen.
[[0;32m  OK  [0m] Started Getty on tty1.
[[0;32m  OK  [0m] Started Serial Getty on ttyS0.
[[0;32m  OK  [0m] Reached target Login Prompts.
         Starting Set console scheme...
[[0;32m  OK  [0m] Started LSB: daemon to balance interrupts for SMP systems.
[[0;32m  OK  [0m] Started Set console scheme.
[    8.617050] cloud-init[1147]: Cloud-init v. 17.1 running 'modules:config' at Wed, 20 Dec 2017 08:53:53 +0000. Up 8.52 seconds.
[[0;32m  OK  [0m] Started Apply the settings specified in cloud-config.

答案1

从我看到和经历的情况来看,私钥未被接受或访问写入错误。尝试使用以下指南设置连接。

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

答案2

最好的办法是等待 20 分钟,然后再试一次,并仔细检查控制台输出。您很可能发现了一个 cloud-init 错误,该错误在初始启动后应用了配置更改或软件包升级序列,并导致一段时间的中断。有时,当发生这种情况时,已发布的 AMI 配置会尝试在启动时更新操作系统或“寻求”远程指令以完成其初始配置。如果是这种情况,您需要等待这些过程完成,直到完成并且 SSH 再次可用。

要明确测试这种情况的方法:启动一个新图像,尽可能登录,保持开放并查看该会话是否被服务器终止。三分钟后尝试单独登录;如果第一个会话没有被终止,请使用该会话来排除故障。如果曾是杀死,尝试等待大约 30 分钟(假设它是一个 t2.micro 实例)然后重试。

还要确认您的网络 ACL 确实正确地传递了流量,以及您的实例正在使用的安全组。您的实例几乎肯定会在初始化时尝试连接互联网,这意味着任何无法访问 DNS(传出 UDP 流量)的情况都会延迟初始化过程,并使启动后配置缓慢,因为每个程序步骤都要等待超时才能继续下一步。

如果 30 分钟后你的实例仍然不可用,那么停止然后重新启动映像可能会有所帮助(cloud-init我相信不会在重启时运行,因为它已经初始化)。

否则,你需要

  1. 启动你知道正在运行的图像位于同一可用区
  2. 确认你可以达到
  3. 然后停止它,
  4. 关闭或停止不工作的那个
  5. 并分离其体积;
  6. 然后,您可以将非工作卷中的卷作为额外磁盘附加到工作实例上,
  7. 重新启动工作实例,
  8. 登录工作实例,
  9. 然后从故障实例安装磁盘并手动检查其日志和配置。

相关内容