Nomad
原文链接: Nomad
Nomad 名词解释
Nomad 类似 kubernets mesos 集群管理 部署工具
Sentinel 会不断地检查你的主服务器和从服务器是否运作正常
Install
解压安装包,将Nomad文件放在/usr/local/bin下.
curl -O https://releases.hashicorp.com/nomad/0.8.4/nomad_0.8.4_linux_amd64.zip
unzip -o nomad_0.7.0_linux_amd64.zip -d /usr/local/bin/
cd /usr/local/bin
chmod +x nomad
ansible-galaxy install brianshumate.nomad
安装地址: /root/.ansible/roles/brianshumate.nomad
ANSIBLE_ROLES_PATH=.. ansible-playbook -i tests/inventory tests/test.yml --syntax-check
inventory
vi hosts[nomad_instances] l19 nomad_node_role=both l18 nomad_node_role=both l17 nomad_node_role=server l16 nomad_node_role=client l15 nomad_node_role=client l14 nomad_node_role=client [all:vars] nomad_bind_address="0.0.0.0"
site.yml
```yml
File: site.yml - Example nomad site playbook
name: Installing Nomad
hosts: nomad_instances
become: yes
become_user: root
roles:{ role: brianshumate.nomad }
tasks:
- name: Start nomad
service: name=nomad state=started enabled=yes
```
constraint
https://www.nomadproject.io/docs/job-specification/constraint.html
清理 nomad 数据
deleteNomad() {
job="$1"
echo "deleting $job..."
stringarray=($job)
jobID=${stringarray[0]}
echo $jobID
nomad stop -purge $jobID
}
nomad status > ./stat.txt
input="./stat.txt"
while IFS= read -r var
do
deleteNomad "$var";
done < "$input"
rm -r ./stat.txt
java application
# task for Java Application
#
# Download this file:
# curl -sSL https://gist.githubusercontent.com/ryanpadilha/5854213edbad8a9698c72c8a6dc66e24/raw/ -o nomad-operation-for-java-app.hcl
#
# Operation for job execution:
#
# validate job - $ nomad validate nomad-operation-for-java-app.hcl
# plan job - $ nomad plan nomad-operation-for-java-app.hcl
# execution plan - $ nomad run -check-index 55 nomad-operation-for-java-app.hcl
# execution status - $ nomad status vulcano-health-check-monitor
# verify error exec - $ nomad alloc-status -verbose 5f33b395-d370-7ebb-851c-287811143041
#
job "vulcano-health-check-monitor" {
datacenters = ["dc1"] # "us-west-1", "us-east-1"
type = "service"
group "java" {
count = 1
task "java-application" {
driver = "java"
user = "nomad"
config {
jar_path = "${NOMAD_META_AWS_PATH}/lib/vulcano-health-check-monitor-${NOMAD_META_APP_VERSION}.jar"
jvm_options = ["-Xms64m", "-Xmx256m",
"-Dspring.config.location=${NOMAD_META_AWS_CONFIG}/application-prd-health-monitor.properties"]
}
# TODO verify register this on Consul by service element
# service { }
# artifact used to ship the jar to run
# download from http, https, git, hg, s3 - automatic unarchived
artifact {
source = "https://s3-sa-east-1.amazonaws.com/nomad-artifact/vulcano-health-check-monitor-0.0.1-dev.tar.gz"
destination = "/var/wplex/apps"
options {
aws_access_key_id = "AKIAI2ZEQ7JXLSS3UW7Q"
aws_access_key_secret = "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"
# aws_access_token = "<token>"
}
}
meta {
AWS_PATH = "/var/wplex/apps/vulcano-health-check-monitor"
AWS_CONFIG = "/var/wplex/apps/config"
APP_VERSION = "0.0.1"
}
}
}
# constraints defined after task is placed on a node
constraint {
attribute = "${attr.kernel.name}"
value = "linux"
}
constraint {
attribute = "${attr.cpu.arch}"
value = "amd64"
}
#constraint {
# attribute = "${attr.platform.aws.instance-type}"
# value = "m4.xlarge"
#}
constraint {
attribute = "${attr.driver.java.version}"
operator = ">="
value = "1.8.0"
}
}