【发布时间】:2020-01-06 02:07:07
【问题描述】:
我正在尝试使用 terraform 启动 VPC 和单个实例,然后通过 ssh 连接,但我无法连接。我知道我这里没有任何密钥,但我试图通过网络终端简单地连接它仍然显示
设置实例连接时出现问题连接 已关闭,因为服务器响应时间过长。这个 通常是由网络问题引起的,例如参差不齐的无线 信号,或者网速慢。请检查您的网络连接 然后重试或联系您的系统管理员。
是否有人能够查看我的代码并了解我做错了什么?
provider "aws" {
region = "us-east-2"
}
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = "test"
}
}
resource "aws_internet_gateway" "gateway" {
vpc_id = "${aws_vpc.vpc.id}"
tags = {
Name = "test"
}
}
resource "aws_subnet" "subnet" {
vpc_id = "${aws_vpc.vpc.id}"
cidr_block = "${aws_vpc.vpc.cidr_block}"
availability_zone = "us-east-2a"
map_public_ip_on_launch = true
tags = {
Name = "test"
}
}
resource "aws_route_table" "table" {
vpc_id = "${aws_vpc.vpc.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gateway.id}"
}
tags = {
Name = "test"
}
}
resource "aws_route_table_association" "public" {
subnet_id = "${aws_subnet.subnet.id}"
route_table_id = "${aws_route_table.table.id}"
}
resource "aws_instance" "node" {
#ami = "ami-0d5d9d301c853a04a" # Ubuntu 18.04
ami = "ami-0d03add87774b12c5" # Ubuntu 16.04
instance_type = "t2.micro"
subnet_id = "${aws_subnet.subnet.id}"
}
UPDATE1:我添加了之前创建的key_name = "mykey"。我无法 ping 公共 ip,在尝试使用密钥 ssh 时,我得到以下信息:
$ ssh -v -i ~/.ssh/mykey ubuntu@1.2.3.4
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to 1.2.3.4 [1.2.3.4] port 22.
mykey 和 1.2.3.4 已更改为发布位置。
UPDATE2:查看安全组,我没有看到任何突出的东西。用于此的 ACL 具有以下内容:
Rule # Type Protocol Port Range Source Allow / Deny
100 ALL Traffic ALL ALL 0.0.0.0/0 ALLOW
* ALL Traffic ALL ALL 0.0.0.0/0 DENY
这是个问题吗?似乎没有人看到 terraform 代码有问题,所以如果有人可以确认这不是代码问题,那么我认为这可以关闭并转移到另一个板上,因为这不是代码问题,对吗?
【问题讨论】:
-
先ping实例的公网ip,再查看创建的sg规则。很可能端口 22 在给定部署中的 sg 级别或 acl 级别被阻止。检查那些。
-
Ping 公网 IP 没有返回任何内容。
-
你检查过sgs和acl吗?
-
对不起。是的 - 我之前检查过 sg 并没有看到任何明显的东西,尽管我可能遗漏了一些东西。 sg 默认在所有端口上打开所有入站流量。我以前没有看过 ACL。这可能是一个问题。我会更新的。
-
这听起来像是一个愚蠢的问题,但互联网网关是否已启动?他们确实需要一段时间来配置,我不确定 Terraform 是否异步执行。还要仔细检查路由表。
标签: amazon-web-services networking ssh terraform