os
yum update -y
yum install -y wget
consul
wget https://releases.hashicorp.com/consul/1.0.6/consul_1.0.6_linux_amd64.zip?_ga=2.168732835.300079002.1523367737-891652806.1523367737
unzip
mv consul /usr/bin
adduser consul
mkdir -p /etc/consul.d/{bootstrap,server,client}
mkdir /var/consul
chown consul:consul /var/consul
bootstrapping
vi /etc/consul.d/bootstrap/config.json
chown consul /etc/consul.d/bootstrap/config.json
{
"bootstrap": true,
"server": true,
"datacenter": "troy",
"data_dir": "/var/consul",
"encrypt" : "TudpzIpJzDOJn9PANmIv5g==",
"log_level": "INFO",
"enable_syslog": true
}
server
vi /etc/consul.d/server/config.json
{
"bootstrap": false,
"server": true,
"datacenter": "troy",
"data_dir": "/var/consul",
"encrypt" : "TudpzIpJzDOJn9PANmIv5g==",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["192.168.96.43", "192.168.96.45", "192.168.96.50"]
}
client
vi /etc/consul.d/client/config.json
{
"client_addr" : "0.0.0.0",
"datacenter": "troy",
"data_dir": "/var/consul",
"ui_dir": "/home/consul/dist",
"encrypt" : "TudpzIpJzDOJn9PANmIv5g==",
"log_level": "INFO",
"enable_syslog": true,
"start_join": ["192.168.96.43", "192.168.96.45", "192.168.96.50"]
}
chown -R consul /etc/consul.d/
STARTUP SCRIPT
vi /etc/systemd/system/consul.service
[Unit]
Description=consul agent
Requires=network-online.target
After=network-online.target
[Service]
EnvironmentFile=-/etc/sysconfig/consul
Environment=GOMAXPROCS=2
Restart=on-failure
ExecStart=/usr/bin/consul agent $OPTIONS -config-file=/etc/consul.d/server/config.json -config-file=/etc/consul.d/client/config.json
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
User=consul
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable consul
systemctl start consul
nomad
wget https://releases.hashicorp.com/nomad/0.7.1/nomad_0.7.1_linux_amd64.zip?_ga=2.195871532.1808499245.1523282073-1935389508.1522933228
unzip
mv nomad /usr/bin/
adduser nomad
mkdir -p /etc/nomad.d/
mkdir /var/nomad
chown nomad:nomad /var/nomad
servers
vi /etc/nomad.d/server.hcl
data_dir = "/var/nomad"
server {
enabled = true
bootstrap_expect = 3
}
clients
vi /etc/nomad.d/client.hcl
datacenter = "troy"
data_dir = "/var/nomad"
client {
enabled = true
}
chown -R nomad /etc/nomad.d/
nomad startup
nomad agent -config=/etc/nomad.d/server.hcl -config=/etc/nomad.d/client.hcl
STARTUP SCRIPT
vi /etc/systemd/system/nomad.service
[Unit]
Description=nomad agent
Documentation=https://nomadproject.io/docs/
[Service]
ExecStart=/usr/bin/nomad agent -config=/etc/nomad.d/server.hcl -config=/etc/nomad.d/client.hcl
ExecReload=/bin/kill -HUP $MAINPID
LimitNOFILE=65536
User=nomad
[Install]
WantedBy=multi-user.target
make sure to add nomad user to docker group
systemctl daemon-reload
systemctl enable nomad
systemctl start nomad
sudo gpasswd -a nomad docker
some rest commands
https://pastebin.com/fe2CaRtF
convert hcl to json with -> nomad run -output my-job.nomad
curl -X POST --data @http-test.json http://nomad01:4646/v1/jobs
curl -X DELETE http://nomad01:4646/v1/job/http-test?purge=true
Consul Tests
curl http://nomad01:8500/v1/catalog/services
curl http://nomad01:8500/v1/catalog/service/http-test-check
[{"ID":"717680e0-ea81-34d9-4bec-8a678bb90ffe","Node":"nomad03.socialgist.local","Address":"192.168.96.43","Datacenter":"troy","TaggedAddresses":{"lan":"192.168.96.43","wan":"192.168.96.43"},"NodeMeta":{"consul-network-segment":""},"ServiceID":"_nomad-task-emnckmej6njnpkfo4fdvyrz6xqiordtu","ServiceName":"http-test-check","ServiceTags":["global","http"],"ServiceAddress":"192.168.96.43","ServicePort":30953,"ServiceEnableTagOverride":false,"CreateIndex":10289,"ModifyIndex":10289}]
curl http://nomad01:8500/v1/health/checks/http-test-check
[{"Node":"nomad03.socialgist.local","CheckID":"5e13c02725794668f869ba5199c0eb34bc7b6a6e","Name":"alive","Status":"passing","Notes":"","Output":"HTTP GET http://192.168.96.43:30953/: 200 OK Output: \u003chtml\u003e\u003chead\u003e\u003ctitle\u003eHTTP Hello World\u003c/title\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003eHello from cfd175092f2f\u003c/h1\u003e\u003c/body\u003e\u003c/html\n","ServiceID":"_nomad-task-emnckmej6njnpkfo4fdvyrz6xqiordtu","ServiceName":"http-test-check","ServiceTags":["global","http"],"Definition":{},"CreateIndex":10290,"ModifyIndex":10292}]