Created
November 25, 2017 03:28
-
-
Save fitz123/1cb9589a8cdbfc64e0cbdcf29a7ec75f to your computer and use it in GitHub Desktop.
install consul server
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
#!/usr/bin/env bash | |
set -e | |
echo "Installing dependencies..." | |
if [ -x "$(command -v apt-get)" ]; then | |
sudo su -s /bin/bash -c 'sleep 30 && apt-get update && apt-get install unzip' root | |
else | |
sudo yum update -y | |
sudo yum install -y unzip wget | |
fi | |
echo "Fetching Consul..." | |
CONSUL=1.0.0 | |
cp consul.service /tmp/ | |
cd /tmp | |
wget https://releases.hashicorp.com/consul/${CONSUL}/consul_${CONSUL}_linux_amd64.zip -O consul.zip --quiet | |
#wget https://raw.githubusercontent.com/hashicorp/consul/master/terraform/shared/scripts/rhel_consul.service -O consul.service --quiet | |
#wget https://gist.githubusercontent.com/Manc/a5f444a8eb89dfbcf530/raw/172dff0b216d1cd93443fe8b5fac0a8548669e9c/consul.service -O consul.service --quiet | |
wget https://gist.githubusercontent.com/fitz123/cb8355572f31d4144d90d5a3bd5fb3f0/raw/878beda60c28fe0180a82724700921c15292556a/consul.service -O consul.service --quiet | |
wget https://gist.githubusercontent.com/fitz123/e0f2a68d14b4349e1f71314674bfacd9/raw/f9edf7ea2e6187968819896285b7492e119de9e3/server -O server.hcl --quiet | |
echo "Installing Consul..." | |
unzip consul.zip >/dev/null | |
chmod +x consul | |
sudo mv consul /usr/local/bin/consul | |
sudo mkdir -p /opt/consul/data | |
sudo chown consul:consul -R /opt/consul | |
sudo chmod 0744 /opt/consul | |
sudo mkdir -p /run/consul | |
sudo chown consul:consul -R /run/consul | |
sudo chmod 0755 /run/consul | |
# Read from the file we created | |
#SERVER_COUNT=$(cat /tmp/consul-server-count | tr -d '\n') | |
#CONSUL_JOIN=$(cat /tmp/consul-server-addr | tr -d '\n') | |
SERVER_COUNT=${SERVER_COUNT:-1} | |
CONSUL_JOIN=${CONSUL_JOIN:-127.0.0.1} | |
# Write the flags to a temporary file | |
cat >/tmp/consul_flags << EOF | |
CONSUL_FLAGS="-server -bootstrap-expect=${SERVER_COUNT} -join=${CONSUL_JOIN} -data-dir=/opt/consul/data" | |
EOF | |
echo "Installing Systemd service..." | |
sudo mkdir -p /etc/sysconfig | |
sudo mkdir -p /etc/consul.d | |
sudo chown consul:consul /tmp/{consul.service,server.hcl} | |
sudo mv /tmp/server.hcl /etc/consul.d/server.hcl | |
sudo mv /tmp/consul.service /etc/systemd/system/consul.service | |
sudo chmod 0644 /etc/systemd/system/consul.service | |
sudo mv /tmp/consul_flags /etc/sysconfig/consul | |
sudo chown consul:consul /etc/sysconfig/consul | |
sudo chmod 0644 /etc/sysconfig/consul |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment