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
外部连结
- 官方网站 (英文)