服务器型号M20S,在“provisioner”块上的AWS EC2实例上运行Hashicorp Vault服务器

用户在使用Terraform创建AWS EC2实例时遇到问题,尝试通过远程执行脚本安装并启动Vault服务器。尽管服务器似乎在后台运行,但Terraform的实例创建过程一直无法完成。尝试了使用`&`和`nohup`命令在后台启动服务器,但均未成功。寻求解决方案来确保在实例创建完成后,Vault服务器能正常后台运行。
摘要由CSDN通过智能技术生成

我正在创建一个AWS实例,并试图在创建时运行一个Vault服务器。我的问题是创建过程永远不会结束,因为服务器没有在后台运行。这是我的配置:

resource "aws_instance" "web" {

ami = "ami-466768ac"

instance_type = "t2.micro"

key_name = "my_key"

tags {

Name = "Vault"

}

provisioner "remote-exec" {

connection {

type = "ssh"

agent = false

user = "ec2-user"

private_key = "${file("/path/to/my_key")}"

}

inline = [

"curl -O https://releases.hashicorp.com/vault/0.10.4/vault_0.10.4_linux_amd64.zip",

"unzip vault_0.10.4_linux_amd64.zip",

"./vault server -dev -dev-listen-address=0.0.0.0:8200"

]

}

}

基本上,我是通过

curl

运行开发服务器。服务器实际上正在运行(我在终端日志中看到),但实例创建(由Terraform)从未完成:

aws_instance.web: Still creating... (40s elapsed)

aws_instance.web: Still creating... (50s elapsed)

aws_instance.web: Still creating... (1m0s elapsed)

aws_instance.web: Still creating... (1m10s elapsed)

aws_instance.web: Still creating... (1m20s elapsed)

aws_instance.web: Still creating... (1m30s elapsed)

...

我试着加上

&

在starting Vault server命令的末尾,为了不阻止shell,但在我执行此操作时,将创建实例,但实际上并没有启动Vault server。

如何在创建实例时以后台模式启动服务器?

编辑

我也试过

nohup

:

nohup ./vault server -dev -dev-listen-address=0.0.0.0:8200

但当terraform完成时服务器不会启动。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 AWS EC2 实例中使用 Terraform 部署 Nginx 的步骤: 1. 在 AWS 控制台中创建一个 IAM 用户,并为该用户授权 AWS 访问密钥和安全凭证。 2. 安装 Terraform,并配置 AWS 访问密钥和安全凭证: ``` $ terraform init $ export AWS_ACCESS_KEY_ID="your_access_key_here" $ export AWS_SECRET_ACCESS_KEY="your_secret_key_here" ``` 3. 创建一个 Terraform 项目,并在 main.tf 文件中定义以下资源: ``` provider "aws" { region = "us-west-2" } resource "aws_instance" "nginx" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" tags = { Name = "nginx-server" } provisioner "remote-exec" { inline = [ "sudo apt-get update", "sudo apt-get install -y nginx", ] } connection { type = "ssh" user = "ubuntu" private_key = file("~/.ssh/id_rsa") host = aws_instance.nginx.public_ip } lifecycle { create_before_destroy = true } # Allow HTTP traffic ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } # Allow SSH traffic ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } # Allow HTTPS traffic ingress { from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } # Allow ICMP traffic ingress { from_port = -1 to_port = -1 protocol = "icmp" cidr_blocks = ["0.0.0.0/0"] } } ``` 上述代码中定义了一个 AWS EC2 实例和一些安全组规则,以允许 HTTP、SSH、HTTPS 和 ICMP 流量通过。还在 provisioner 部分中安装了 Nginx。 4. 运行 Terraform 命令创建实例: ``` $ terraform apply ``` 5. 在浏览器中输入实例 IP 地址,应该可以看到 Nginx 的欢迎页面。 现在,您已经成功在 AWS EC2 实例中部署了 Nginx,而且使用 Terraform 进行自动化管理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值