Nomad

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索

NomadHashiCorp推出的資源管理軟體。

架構

Nomad分成Server與Client架構:

  • Server負責協調與分配工作。
  • Client負責實際執行工作。

Server建議至少三台機器,Client建議至少兩台機器。

安裝

Nomad server與Nomad client的安裝都相同(透過設定扮演不同的角色),這邊是安裝0.10.2版,記得到官方網站上確認最新版的號碼後,修改對應的設定:

cd /tmp; wget https://releases.hashicorp.com/nomad/0.10.2/nomad_0.10.2_linux_amd64.zip; unzip nomad_0.10.2_linux_amd64.zip; sudo install -m 0755 nomad /usr/local/bin/; wget https://raw.githubusercontent.com/hashicorp/nomad/master/dist/systemd/nomad.service; sudo install nomad.service /lib/systemd/system/; sudo service daemon-reload; sudo systemctl enable nomad; sudo mkdir /srv/nomad

Nomad client建議再安裝Docker

設定

Nomad server的部份,依照官方的建議放到/etc/nomad.d/server.hcl

datacenter = "us-east-1a"
data_dir = "/srv/nomad"
enable_syslog = true
log_level = "INFO"
region = "us-east-1"
server {
    enabled = true
    bootstrap_expect = 3
    server_join {
        retry_join = ["10.1.1.10:4648", "10.1.1.11:4648", "10.1.1.12:4648"]
    }
}

Nomad client的部份,依照官方的建議放到/etc/nomad.d/client.hcl

datacenter = "us-east-1a"
data_dir = "/srv/nomad"
enable_syslog = true
log_level = "INFO"
region = "us-east-1"
client {
    enabled = true
    servers = ["10.1.1.10:4648", "10.1.1.11:4648", "10.1.1.12:4648"]

    chroot_env {
        "/bin" = "/bin"
        "/etc" = "/etc"
        "/lib32" = "/lib32"
        "/lib64" = "/lib64"
        "/lib" = "/lib"
        "/run/resolveconf" = "/run/resolveconf"
        "/run/systemd/resolve" = "/run/systemd/resolve"
        "/sbin" = "/sbin"
        "/usr" = "/usr"
    }
}
ports {
    http = 5656
}

設定完成後(無論是server或是client)都可以啟用:

sudo service nomad restart
sudo service nomad status

檔案

一份example.nomad檔案:

job "example" {
  datacenters = ["us-east-1a", "us-east-1b", "us-east-1c"]
  type = "batch"
  group "example" {
    count = 10
    task "example" {
      driver = "exec"
      config {
        command = "/usr/bin/curl"
        args = ["https://wiki.gslin.org/robots.txt"]
      }
    }
  }
}

常用指令

目前測試的情況下,所有的指令都接受NOMAD_ADDR環境變數。如果沒有設定環境的話,需要在命令列加上-address=http://a.b.c.d:4646參數:

export NOMAD_ADDR=http://nomad-server:4646

操作類性指令:

nomad alloc status <id>
nomad alloc logs <id>
nomad server members
nomad node status
nomad job run example.nomad
nomad job status
nomad job stop example

外部連結