Nomad
Nomad是HashiCorp推出的資源管理軟件。
架構
Nomad分成Server與Client架構:
- Server負責協調與分配工作。
- Client負責實際執行工作。
正式環境下Server建議至少三台機器,Client建議至少兩台機器。
安裝
Nomad server與Nomad client的安裝都相同(透過設定扮演不同的角色),這邊是安裝官方的apt repository:
curl https://apt.releases.hashicorp.com/gpg | sudo apt-key add -; sudo apt-add-repository "deb https://apt.releases.hashicorp.com $(lsb_release -cs) main"; sudo apt update && sudo apt install -y nomad
Nomad client建議再安裝Docker。
設定
測試環境
單機同時跑server與client:
#
bind_addr = "0.0.0.0"
data_dir = "/opt/nomad/data"
client {
enabled = true
network_interface = "{{ Interfaces | limit 1 }}"
}
server {
bootstrap_expect = 1
enabled = true
}
正式環境
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
外部連結
- 官方網站 (英文)