nomad 集群搭建
比较简单的集群搭建
一个server 三个client (单机) 参考代码 https://github.com/rongfengliang/nomad-cluster-demo
server 配置
# Increase log verbosity
log_level = "DEBUG"
# Setup data dir 实际配置参考自己的配置路径,必须是绝对路径
data_dir = "/Users/dalong/mylearning/nomad-cluster/server/node1/data"
# Enable the server
server {
enabled = true
# Self-elect, should be 3 or 5 for production
bootstrap_expect = 1
}
客户端配置
三个
- client1
# Increase log verbosity
log_level = "DEBUG"
# Setup data dir
data_dir = "/Users/dalong/mylearning/nomad-cluster/client/client1"
# Give the agent a unique name. Defaults to hostname
name = "client1"
# Enable the client
client {
enabled = true
# For demo assume we are talking to server1. For production,
# this should be like "nomad.service.consul:4647" and a system
# like Consul used for service discovery.
servers = ["127.0.0.1:4647"]
}
# Modify our port to avoid a collision with server1
ports {
http = 5656
}
- client2
# Increase log verbosity
log_level = "DEBUG"
# Setup data dir
data_dir = "/Users/dalong/mylearning/nomad-cluster/client/client2"
# Give the agent a unique name. Defaults to hostname
name = "client2"
# Enable the client
client {
enabled = true
# For demo assume we are talking to server1. For production,
# this should be like "nomad.service.consul:4647" and a system
# like Consul used for service discovery.
servers = ["127.0.0.1:4647"]
}
# Modify our port to avoid a collision with server1
ports {
http = 5657
}
- client3
# Increase log verbosity
log_level = "DEBUG"
# Setup data dir
data_dir = "/Users/dalong/mylearning/nomad-cluster/client/client3"
# Give the agent a unique name. Defaults to hostname
name = "client3"
# Enable the client
client {
enabled = true
# For demo assume we are talking to server1. For production,
# this should be like "nomad.service.consul:4647" and a system
# like Consul used for service discovery.
servers = ["127.0.0.1:4647"]
}
# Modify our port to avoid a collision with server1
ports {
http = 5658
}
启动server && client
- 启动consul
测试,使用单
consul agent --dev
- server
nomad agent -config server.hcl
- client(1、2、3)
按照实际,进入目录进行启动
nomad agent -config client(1、2、3).hcl
参考界面
- consul
-
nomad server
-
client
运行job
- 生成参考代码
nomad init
- 修改运行个数为5
实际代码可以参考github
group "cache" {
count = 5
- 运行
nomad run example.nomad
- 参考界面
consul dns 测试
说明
实际环境中我们使用集群环境,同时结合coredns 可以实现一些比较强大的功能。
参考资料
https://www.nomadproject.io/intro/getting-started/cluster.html
https://github.com/rongfengliang/nomad-cluster-demo