amazon-web-services - AWS Web 服务器拒绝连接

provider "aws" {
  region = "us-east-1"
}

provider "random" {}

resource "random_pet" "name" {}

resource "aws_instance" "web" {
  ami           = "ami-0022f774911c1d690"
  instance_type = "t2.micro"
  user_data     = file("init-script.sh")
  vpc_security_group_ids = [aws_security_group.web-sg.id]

  tags = {
    Name = random_pet.name.id
  }
}

resource "aws_security_group" "web-sg" {
  name = "${random_pet.name.id}-sg"
  ingress {
    from_port = 80
    to_port = 80
    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"]
  }
}

我正在使用 Terraform 来部署 PHP Web 服务器。如图所示,定义了入口和出口规则,我应该能够连接。我究竟做错了什么?

另外,我正在关注本教程:

https://learn.hashicorp.com/tutorials/terraform/resource?in=terraform/configuration-language

回答1

我自己克隆并运行了本教程,它也不适用于我。尝试连接会给我一个超时错误。

第一次观察 - 它很老而且不是一个很好的教程。它采样的 AMI 甚至不再存在,我改用最新的 AMZN Default Linux 2 AMI。

第二个观察 - 在教程中没有创建或使用 key 对,这使得故障排除变得困难,因为您无法连接和查看日志。

第三个观察 - 与我的第一个相关, chkconfig 在 init-script 中使用,如果您使用较新的 AMI(centos、redhat 或 amzn linux 映像),它们都可能使用 systemctl 代替。

结论:本教程确实需要更新,我不建议使用它,因为它几乎无法使用并且非常过时。

相似文章

随机推荐

最新文章