我创建了一个 AWS EC2 实例以在其上设置 prometheus,我创建了一个新的 ssh 密钥对并使用 terraform 配置了该实例,我使用实例类型为“t3.large”和一个 120GB 的 SSD 磁盘,操作系统是 Ubuntu 18.04,并且我可以正常 ssh 到实例。到现在为止一切都还好。
使用 docker 安装 Prometheus 和 Grafana 一段时间后,我回到实例,发现无法登录!我收到以下问题:
ssh: connect to host [ip] port 22: Connection timed out
我确定这不是互联网连接问题,因为我可以通过 ssh 连接到其他实例。使用ip地址或DNS时问题相同,端口22也是开放的。
这是我使用的 terraform 脚本,但我认为它与此无关:
provider "aws" {
profile = "default"
region = "eu-west-1"
}
resource "aws_key_pair" "ubuntu" {
key_name = "ubuntu"
public_key = file("ubuntu.pem.pub")
}
resource "aws_security_group" "ubuntu" {
name = "ubuntu-security-group"
description = "Allow HTTP, HTTPS and SSH traffic"
ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTPS"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTP"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTP"
from_port = 3000
to_port = 3000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTP"
from_port = 9090
to_port = 9090
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTP"
from_port = 9100
to_port = 9100
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "terraform"
}
}
resource "aws_instance" "ubuntu" {
key_name = aws_key_pair.ubuntu.key_name
ami = "ami-0dc8d444ee2a42d8a"
instance_type = "t3.large"
tags = {
Name = "ubuntu-prometheus"
}
vpc_security_group_ids = [
aws_security_group.ubuntu.id
]
connection {
type = "ssh"
user = "ubuntu"
private_key = file("key")
host = self.public_ip
}
ebs_block_device {
device_name = "/dev/sda1"
volume_type = "gp2"
volume_size = 120
}
}
resource "aws_eip" "ubuntu" {
vpc = true
instance = aws_instance.ubuntu.id
}