CentOS8 Nomad安装(2)

1 环境

操作系统版本:centos8
系统工具:yum
默认启用端口:4646、4647、4648

2 下载 安装

wget https://releases.hashicorp.com/nomad/0.6.1/nomad_0.6.1_linux_amd64.zip

--2022-04-18 10:08:10--  https://releases.hashicorp.com/nomad/0.6.1/nomad_0.6.1_linux_amd64.zip
Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.109.183, 2a04:4e42:11::439
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.109.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10577708 (10M) [application/zip]
Saving to: ‘nomad_0.6.1_linux_amd64.zip’

nomad_0.6.1_linux_amd64.zip                         100%[==================================================================================================================>]  10.09M  6.18MB/s    in 1.6s

2022-04-18 10:08:12 (6.18 MB/s) - ‘nomad_0.6.1_linux_amd64.zip’ saved [10577708/10577708]



#解压
unzip nomad_0.6.1_linux_amd64.zip -d /usr/bin

Archive:  nomad_0.6.1_linux_amd64.zip
  inflating: /usr/bin/nomad

3 创建启动文件

vim /lib/systemd/system/nomad.service

[Unit]
Description=nomad
[Service]
ExecStart=/usr/bin/nomad agent -config /etc/nomad
killSignal=SIGTERM


:wq

4 开始

#开发者模式
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.1

==> Nomad agent started! Log data will stream in below:
	…………

server和client都为true,表示同时开启了server和client。

新开一个终端,查看状态

nomad node-status
ID        DC   Name        Class   Drain  Status
288cf1d8  dc1  controller  <none>  false  ready
ID,它是随机生成的UUID

DC,数据中心

Name,节点名称

Class 节点类别

Drain 漏斗模式

Status 当前状态
nomad server-members

Name               Address    Port  Status  Leader  Protocol  Build  Datacenter  Region
controller.global  127.0.0.1  4648  alive   true    2         0.6.1  dc1         global

停止
CTRL + C

5 Nomad Job

Job是Nomad主要交互的内容

示例Job

cd /etc/nomad/

nomad init
#输出,这是一个示例的nomad job配置文件。
Example job file written to example.nomad

运行这个job

[root@controller nomad]# nomad run example.nomad
==> Monitoring evaluation "f2915eb4"
    Evaluation triggered by job "example"
    Evaluation within deployment: "3d4565e9"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "f2915eb4" finished with status "complete" but failed to place all allocations:
    Task Group "cache" (failed to place 1 allocation):
      * Constraint "missing drivers" filtered 1 nodes
    Evaluation "3a4f267c" waiting for additional capacity to place remainder

报错,原因是未开启Docker

systemctl start docker
[root@controller ~]# nomad run example.nomad
==> Monitoring evaluation "46df41a2"
    Evaluation triggered by job "example"
    Evaluation within deployment: "637faa61"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "46df41a2" finished with status "complete"

查看job状态

[root@controller nomad]# nomad status example
ID            = example
Name          = example
Submit Date   = 04/22/22 11:57:22 CST
Type          = service
Priority      = 50
Datacenters   = dc1
Status        = running
Periodic      = false
Parameterized = false

Summary
Task Group  Queued  Starting  Running  Failed  Complete  Lost
cache       0       0         1        0       0         0

Latest Deployment
ID          = 637faa61
Status      = successful
Description = Deployment completed successfully

Deployed
Task Group  Desired  Placed  Healthy  Unhealthy
cache       1        1       1        0

Allocations
ID        Node ID   Task Group  Version  Desired  Status   Created At
d4595003  288cf1d8  cache       2        run      running  04/22/22 11:59:18 CST


检查job的分配情况。

[root@controller ~]# nomad alloc-status d4595003
ID                  = d4595003
Eval ID             = f218342a
Name                = example.cache[0]
Node ID             = 288cf1d8
Job ID              = example
Job Version         = 2
Client Status       = running
Client Description  = <none>
Desired Status      = run
Desired Description = <none>
Created At          = 04/22/22 11:59:18 CST
Deployment ID       = 637faa61
Deployment Health   = healthy

Task "redis" is "running"
Task Resources
CPU        Memory           Disk     IOPS  Addresses
4/500 MHz  924 KiB/256 MiB  300 MiB  0     db: 127.0.0.1:22788

Task Events:
Started At     = 04/22/22 03:59:47 UTC
Finished At    = N/A
Total Restarts = 0
Last Restart   = N/A

Recent Events:
Time                   Type        Description
04/22/22 11:59:47 CST  Started     Task started by client
04/22/22 11:59:18 CST  Driver      Downloading image redis:3.2
04/22/22 11:59:18 CST  Task Setup  Building Task Directory
04/22/22 11:59:18 CST  Received    Task received by client

Logs打印

[root@controller ~]# nomad logs dab3f690 redis

修改job

vim example.nomad

...
count = 3
...

:wq

nomad plan example.nomad


# nomad run -check-index 7 example.nomad

停止job

[root@controller ~]# nomad stop example
==> Monitoring evaluation "a3883687"
    Evaluation triggered by job "example"
    Evaluation within deployment: "264c07db"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "a3883687" finished with status "complete"

建立Nomad集群

测试环境:

192.168.143.203(server)
192.168.143.194(server)
192.168.143.192(client)

配置

分别配置一次

mkdir /etc/nomad/
cd /etc/nomad/

vim nomad_test.hcl
-----
datacenter = "dc1"
data_dir = "/root/nomad/data"

server {
  enabled = true
  bootstrap_expect = 3
}

client {
  enabled = true
  servers = ["192.168.143.203:4647"]  #此处写本机ip
}

新开终端,加入集群

[root@controller ~]# nomad server-join "192.168.143.192:4648"
Joined 1 servers successfully

查看成员

root@controller ~]# nomad server-members
Name               Address       Port  Status  Leader  Protocol  Build  Datacenter  Region
compute.global     10.10.20.192  4648  alive   false   2         0.6.1  dc1         global
controller.global  127.0.0.1     4648  alive   false   2         0.6.1  dc1         global
stone.global       10.10.20.194  4648  alive   false   2         0.6.1  dc1         global

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会长胖的斜杠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值