nomad 集群搭建

Posted rongfengliang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
```code
# 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

以上是关于nomad 集群搭建的主要内容,如果未能解决你的问题,请参考以下文章

Nomad+Consul Service Mesh如何搭建本地开发环境

重塑 Prometheus 的 Nomad 指标

Traefik 的 Nomad 高可用性

如何在启用 tls 的情况下连接到 nomad/consul UI?

nomad拖拽和移动有啥区别

滑板nomad和prd那个好用