2017-05-15 18:56:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-25 18:54:56 +00:00
|
|
|
set -e
|
|
|
|
|
2017-05-15 18:56:41 +00:00
|
|
|
CONFIGDIR=/ops/shared/config
|
2017-06-25 18:54:56 +00:00
|
|
|
|
2017-05-15 18:56:41 +00:00
|
|
|
CONSULCONFIGDIR=/etc/consul.d
|
|
|
|
VAULTCONFIGDIR=/etc/vault.d
|
|
|
|
NOMADCONFIGDIR=/etc/nomad.d
|
2017-06-24 23:25:46 +00:00
|
|
|
HADOOP_VERSION=hadoop-2.7.3
|
|
|
|
HADOOPCONFIGDIR=/usr/local/$HADOOP_VERSION/etc/hadoop
|
2017-05-15 18:56:41 +00:00
|
|
|
HOME_DIR=ubuntu
|
|
|
|
|
2017-06-25 17:09:54 +00:00
|
|
|
sleep 15
|
|
|
|
|
2017-05-15 18:56:41 +00:00
|
|
|
IP_ADDRESS=$(curl http://instance-data/latest/meta-data/local-ipv4)
|
2017-06-25 17:09:54 +00:00
|
|
|
DOCKER_BRIDGE_IP_ADDRESS=(`ifconfig docker0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`)
|
2017-05-15 18:56:41 +00:00
|
|
|
SERVER_COUNT=$1
|
|
|
|
REGION=$2
|
|
|
|
CLUSTER_TAG_VALUE=$3
|
|
|
|
|
|
|
|
# Consul
|
|
|
|
sed -i "s/IP_ADDRESS/$IP_ADDRESS/g" $CONFIGDIR/consul.json
|
|
|
|
sed -i "s/SERVER_COUNT/$SERVER_COUNT/g" $CONFIGDIR/consul.json
|
|
|
|
sed -i "s/REGION/$REGION/g" $CONFIGDIR/consul.json
|
|
|
|
sed -i "s/CLUSTER_TAG_VALUE/$CLUSTER_TAG_VALUE/g" $CONFIGDIR/consul.json
|
|
|
|
sudo cp $CONFIGDIR/consul.json $CONSULCONFIGDIR
|
|
|
|
sudo cp $CONFIGDIR/consul_upstart.conf /etc/init/consul.conf
|
|
|
|
|
|
|
|
sudo service consul start
|
|
|
|
sleep 20
|
|
|
|
export CONSUL_HTTP_ADDR=$IP_ADDRESS:8500
|
|
|
|
export CONSUL_RPC_ADDR=$IP_ADDRESS:8400
|
|
|
|
|
|
|
|
# Vault
|
|
|
|
sed -i "s/IP_ADDRESS/$IP_ADDRESS/g" $CONFIGDIR/vault.hcl
|
|
|
|
sudo cp $CONFIGDIR/vault.hcl $VAULTCONFIGDIR
|
|
|
|
sudo cp $CONFIGDIR/vault_upstart.conf /etc/init/vault.conf
|
|
|
|
|
|
|
|
sudo service vault start
|
|
|
|
|
|
|
|
# Nomad
|
|
|
|
sed -i "s/IP_ADDRESS/$IP_ADDRESS/g" $CONFIGDIR/nomad.hcl
|
|
|
|
sed -i "s/SERVER_COUNT/$SERVER_COUNT/g" $CONFIGDIR/nomad.hcl
|
|
|
|
sudo cp $CONFIGDIR/nomad.hcl $NOMADCONFIGDIR
|
|
|
|
sudo cp $CONFIGDIR/nomad_upstart.conf /etc/init/nomad.conf
|
|
|
|
|
|
|
|
sudo service nomad start
|
|
|
|
sleep 10
|
|
|
|
export NOMAD_ADDR=http://$IP_ADDRESS:4646
|
|
|
|
|
2017-06-25 17:09:54 +00:00
|
|
|
# Add hostname to /etc/hosts
|
|
|
|
|
|
|
|
echo "127.0.0.1 $(hostname)" | sudo tee --append /etc/hosts
|
|
|
|
|
|
|
|
# Add Docker bridge network IP to /etc/resolv.conf (at the top)
|
|
|
|
|
|
|
|
echo "nameserver $DOCKER_BRIDGE_IP_ADDRESS" | sudo tee /etc/resolv.conf.new
|
|
|
|
cat /etc/resolv.conf | sudo tee --append /etc/resolv.conf.new
|
|
|
|
sudo mv /etc/resolv.conf.new /etc/resolv.conf
|
|
|
|
|
2017-06-24 23:25:46 +00:00
|
|
|
# Hadoop
|
|
|
|
sudo cp $CONFIGDIR/core-site.xml $HADOOPCONFIGDIR
|
|
|
|
|
2017-06-25 18:54:56 +00:00
|
|
|
# Move examples directory to $HOME
|
|
|
|
sudo mv /ops/examples /home/$HOME_DIR
|
|
|
|
sudo chown -R $HOME_DIR:$HOME_DIR /home/$HOME_DIR/examples
|
|
|
|
sudo chmod -R 775 /home/$HOME_DIR/examples
|
|
|
|
|
2017-06-24 23:25:46 +00:00
|
|
|
# Set env vars for tool CLIs
|
2017-05-15 18:56:41 +00:00
|
|
|
echo "export CONSUL_RPC_ADDR=$IP_ADDRESS:8400" | sudo tee --append /home/$HOME_DIR/.bashrc
|
|
|
|
echo "export CONSUL_HTTP_ADDR=$IP_ADDRESS:8500" | sudo tee --append /home/$HOME_DIR/.bashrc
|
|
|
|
echo "export VAULT_ADDR=http://$IP_ADDRESS:8200" | sudo tee --append /home/$HOME_DIR/.bashrc
|
|
|
|
echo "export NOMAD_ADDR=http://$IP_ADDRESS:4646" | sudo tee --append /home/$HOME_DIR/.bashrc
|
|
|
|
echo "export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre" | sudo tee --append /home/$HOME_DIR/.bashrc
|
|
|
|
|
2017-06-25 18:54:56 +00:00
|
|
|
# Update PATH
|
2017-06-24 23:25:46 +00:00
|
|
|
echo "export PATH=$PATH:/usr/local/bin/spark/bin:/usr/local/$HADOOP_VERSION/bin" | sudo tee --append /home/$HOME_DIR/.bashrc
|