首页 > 解决方案 > Nomad : raw_exec 安装 nginx

问题描述

我想运行 raw_exec 来安装一个 nginx ,这可能吗?或者如何仅由 raw_exec 完成。因为此代码不会启动/运行。

job "raw-exec" {
  datacenters = ["dc1"]
  type        = "service"

  group "exec" {
    count = 1

    update {
       max_parallel      = 1
       min_healthy_time  = "10s"
       healthy_deadline  = "5m"
       progress_deadline = "10m"
       auto_revert       = true
     }

    task "raw-exec-test" {
      driver = "raw_exec"

      config {
        command = "/bin/apt"
        args = ["-y", "install", "nginx.service"]
      }

      resources {
        cpu    = 100
        memory = 125
      }

    }
  }
}

标签: nginxdriverubuntu-18.04nomad

解决方案


如果没有工作状态,就很难解决问题所在。 nomad job status raw-exec会显示你的工作状态。它还将显示作业创建的分配。您可以检查 Nomad 由nomad alloc status YOUR-ALLOC-ID.

我已经运行了以下 Nomad 作业规范,它在我的 MacBook 上运行良好。我在一个终端窗口中运行 nomad using nomad agent -dev,然后在另一个终端窗口中创建文件 test.job 并运行它并在 MacBook 上nomad job run test.job安装软件。htop

job "raw-exec" {
  datacenters = ["dc1"]
  type        = "batch"

  group "exec" {
    count = 1

    task "raw-exec-test" {
      driver = "raw_exec"

      config {
        command = "brew"
        args = ["install", "htop"]
      }

      resources {
        cpu    = 100
        memory = 125
      }
    }
  }
}

请注意,我已将工作type从服务更改为批处理。批处理作业设计为运行一次,而服务应始终启动并运行。我想你希望你的apt install -y nginx命令只运行一次。您可以在此处阅读有关工作类型的更多信息


推荐阅读