Last active
December 5, 2022 09:05
-
-
Save jonaskahn/63a0a75c1abd354199fd12ef04bacafe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo apt install -y unzip zip | |
export CONSUL_VERSION=1.13.4 | |
printf "Download & install consul ${CONSUL_VERSION}\n" | |
export CONSUL_URL="https://releases.hashicorp.com/consul" | |
curl --silent --remote-name \ | |
${CONSUL_URL}/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip | |
unzip consul_${CONSUL_VERSION}_linux_amd64.zip | |
sudo chown root:root consul | |
sudo mv consul /usr/bin/ | |
consul --version | |
printf "Setup consul . . .\n" | |
consul -autocomplete-install | |
complete -C /usr/bin/consul consul | |
sudo useradd --system --home /etc/consul.d --shell /bin/false consul | |
sudo mkdir --parents /opt/consul/certs | |
sudo chown --recursive consul:consul /opt/consul | |
sudo mkdir --parents /etc/consul.d | |
sudo touch /etc/consul.d/consul.hcl | |
sudo touch /etc/consul.d/server.hcl | |
sudo chown --recursive consul:consul /etc/consul.d | |
sudo chmod 640 /etc/consul.d/*.hcl | |
sudo rm -rf /etc/systemd/system/consul.service | |
sudo touch /etc/systemd/system/consul.service | |
echo "[Unit] | |
Description=\"HashiCorp Consul - A service mesh solution\" | |
Documentation=https://www.consul.io/ | |
Requires=network-online.target | |
After=network-online.target | |
ConditionFileNotEmpty=/etc/consul.d/consul.hcl | |
[Service] | |
EnvironmentFile=-/etc/consul.d/consul.env | |
User=consul | |
Group=consul | |
ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/ | |
ExecReload=/bin/kill --signal HUP $MAINPID | |
KillMode=process | |
KillSignal=SIGTERM | |
Restart=on-failure | |
LimitNOFILE=65536 | |
[Install] | |
WantedBy=multi-user.target | |
" | sudo tee -a /etc/systemd/system/consul.service | |
sudo systemctl enable consul | |
printf "Consul installed. Start configuration to continue\n" | |
printf "\nLatest NOMAD version >> $(curl -s https://checkpoint-api.hashicorp.com/v1/check/nomad | jq -r '.current_version') << \n" | |
export NOMAD_VERSION=1.4.3 | |
printf "Download & install nomad ${NOMAD_VERSION} . . .\n" | |
curl --silent --remote-name https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip | |
unzip nomad_${NOMAD_VERSION}_linux_amd64.zip | |
sudo chown root:root nomad | |
sudo mv nomad /usr/local/bin/ | |
nomad version | |
nomad -autocomplete-install | |
complete -C /usr/local/bin/nomad nomad | |
sudo mkdir --parents /opt/nomad | |
sudo useradd --system --home /etc/nomad.d --shell /bin/false nomad | |
sudo rm -rf /etc/systemd/system/nomad.service | |
echo " | |
[Unit] | |
Description=Nomad | |
Documentation=https://www.nomadproject.io/docs/ | |
Wants=network-online.target | |
After=network-online.target | |
#Wants=consul.service | |
#After=consul.service | |
[Service] | |
User=nomad | |
Group=nomad | |
ExecReload=/bin/kill -HUP $MAINPID | |
ExecStart=/usr/local/bin/nomad agent -config /etc/nomad.d | |
KillMode=process | |
KillSignal=SIGINT | |
LimitNOFILE=65536 | |
LimitNPROC=infinity | |
Restart=on-failure | |
RestartSec=2 | |
TasksMax=infinity | |
OOMScoreAdjust=-1000 | |
[Install] | |
WantedBy=multi-user.target | |
" | sudo tee -a /etc/systemd/system/nomad.service | |
sudo mkdir --parents /etc/nomad.d | |
sudo chmod 700 /etc/nomad.d | |
sudo touch /etc/nomad.d/nomad.hcl && \ | |
sudo touch /etc/nomad.d/server.hcl && \ | |
sudo touch /etc/nomad.d/client.hcl && \ | |
sudo touch /etc/nomad.d/consul.hcl | |
sudo systemctl enable nomad | |
sudo chown --recursive nomad:nomad /etc/nomad.d | |
sudo chown --recursive nomad:nomad /opt/nomad | |
sudo usermod -aG docker nomad | |
sudo rm -rf consul_${CONSUL_VERSION}_linux_amd64.zip | |
sudo rm -rf nomad_${NOMAD_VERSION}_linux_amd64.zip | |
printf "Nomad installed. Start configuration to continue\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bash -c "$(curl -fsSL https://gist.github.com/tuyendev/63a0a75c1abd354199fd12ef04bacafe/raw/9ebe1bbfec65bddbc1edf286bcd03e9836039d2b/consul-nomad-install.sh)"