0

我正在使用 Terraform 和 Google Compute 建立一个项目。在这个项目中,我启动了多个虚拟机,然后通过 SSH 直接配置它们。有时,我无法使用常用帐户通过 SSH 连接到单个或多个 VM。大约 5 分钟后问题神奇地消失了,即使我什么都不做。在这段时间之后,一切都会再次正常工作。但是,我可以在停机期间使用 Web 界面通过 SSH 连接到实例。

我无法可靠地重现此问题。它有时会神奇地发生在随机数量的虚拟机上大约 5 分钟。

我对此非常迷茫,并且非常感谢任何关于我可以在哪里找到解决方案的指针。

以下是问题的简短摘要:

  • 无法使用预定义用户通过 SSH 连接到 GCP VM
  • 仅有时会发生(问题无法可靠地重现)
  • 仅持续几分钟(约 5 分钟)
  • 在此期间,我可以通过 GCP 网络界面 SSH 进入虚拟机

这是我用来启动实例的 Terraform 代码:

模块.google:

variable "project"{}
variable "credentials"{}
variable "count"{default = 1}
variable "name_machine"{}
variable "zone"{}

provider "google" {
    credentials = "${var.credentials}"
    project     = "${var.project}"
}

resource "google_compute_instance" "vm" {

    count = "${var.count}"
    zone = "${var.zone}"
    name = "${var.name_machine}${count.index}"
    machine_type = "n1-standard-1"

    boot_disk {
        initialize_params {
            image = "ubuntu-os-cloud/ubuntu-1604-lts"
        }
    }

    network_interface {
        network = "default"
        access_config {
        }
    }
}

编辑我用来通过 SSH 连接到实例的代码。

resource "null_resource" "node"{

    provisioner "remote-exec" {
        inline="${data.template_file.start_up_script.rendered}"
    }

    connection {
        user = "${var.ssh_user}"
        host = "${var.ip_address}"
        type = "ssh"
        private_key="${var.ssh_private_key}"
    }
}

编辑 2地形输出

null_resource.node (remote-exec): Connecting to remote host via SSH...
null_resource.node (remote-exec):   Host: xx.xx.xx.xx
null_resource.node (remote-exec):   User: Nopx
null_resource.node (remote-exec):   Password: false
null_resource.node (remote-exec):   Private key: true
null_resource.node (remote-exec):   SSH Agent: false
null_resource.node:   Still creating... (10s elapsed)
null_resource.node (remote-exec): Connecting to remote host via SSH...
null_resource.node (remote-exec):   Host: xx.xx.xx.xx
null_resource.node (remote-exec):   User: Nopx
null_resource.node (remote-exec):   Password: false
null_resource.node (remote-exec):   Private key: true
null_resource.node (remote-exec):   SSH Agent: false
null_resource.node (remote-exec): Connecting to remote host via SSH...
null_resource.node (remote-exec):   Host: xx.xx.xx.xx
null_resource.node (remote-exec):   User: Nopx
null_resource.node (remote-exec):   Password: false
null_resource.node (remote-exec):   Private key: true
null_resource.node (remote-exec):   SSH Agent: false
null_resource.node:   Still creating... (20s elapsed)
null_resource.node (remote-exec): Connecting to remote host via SSH...
null_resource.node (remote-exec):   Host: xx.xx.xx.xx
null_resource.node (remote-exec):   User: Nopx
null_resource.node (remote-exec):   Password: false
null_resource.node (remote-exec):   Private key: true
null_resource.node (remote-exec):   SSH Agent: false
...
4

0 回答 0