在 Nomad (0.6) 中部署 Redis 作业时,我无法在 Consul 中使其正常运行。
我在容器中启动 Consul 并在 localhost 上提供端口 8500。
$ docker container run --name consul -d -p 8500:8500 consul
当我运行 nomad 时,它正确连接到 Consul,正如我们在日志中看到的那样。
$ nomad agent -dev
No configuration files loaded
==> Starting Nomad agent...
==> Nomad agent configuration:
Client: true
Log Level: DEBUG
Region: global (DC: dc1)
Server: true
Version: 0.6.0
==> Nomad agent started! Log data will stream in below:
...
2017/08/18 15:45:28.373766 [DEBUG] client.consul: bootstrap contacting following Consul DCs: ["dc1"]
2017/08/18 15:45:28.377703 [INFO] client.consul: discovered following Servers: 127.0.0.1:4647
2017/08/18 15:45:28.378851 [INFO] client: node registration complete
2017/08/18 15:45:28.378895 [DEBUG] client: periodically checking for node changes at duration 5s
2017/08/18 15:45:28.379232 [DEBUG] consul.sync: registered 1 services, 1 checks; deregistered 0 services, 0 checks
...
然后我使用以下配置文件运行 redis 作业
job "nomad-redis" {
datacenters = ["dc1"]
type = "service"
group "cache" {
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
port_map {
db = 6379
}
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
network {
mbits = 10
port "db" {}
}
}
service {
name = "redis"
port = "db"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
}
}
Redis 服务已添加到 consul 中,但它看起来很关键。似乎无法进行健康检查。据我了解,检查是在任务中完成的。有什么我想念的吗?