Skip to content

Instantly share code, notes, and snippets.

@wedtm
Created July 15, 2015 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wedtm/25b5040586257602150d to your computer and use it in GitHub Desktop.
Save wedtm/25b5040586257602150d to your computer and use it in GitHub Desktop.
Simple Mesos Cluster
#! /usr/bin/env bash
HOST_IP_1="10.0.10.10"
HOST_IP_2="10.0.20.10"
HOST_IP_3="10.0.30.10"
###### DO NOT TOUCH BELOW HERE ########
SCRIPT=`basename "$0"`
if [ $# -eq 0 ]; then
# Attempt automatic identification of host by comparing the host's IP's to the expected list above.
ips=( $(ifconfig | awk '/inet/ {print $2}') )
for ip in "${ips[@]}"; do
if [ $HOST_IP_1 == $ip ]; then
MY_ID=1
echo "Automatically determined this host as HOSTID:$MY_ID ($HOST_IP_1), configuring as such."
elif [ $HOST_IP_2 == $ip ]; then
MY_ID=2
echo "Automatically determined this host as HOSTID:$MY_ID ($HOST_IP_2), configuring as such."
elif [ $HOST_IP_3 == $ip ]; then
MY_ID=3
echo "Automatically determined this host as HOSTID:$MY_ID ($HOST_IP_3), configuring as such."
fi
done
if [ -z $MY_ID ]; then
echo "NOTE: We attempted automatic provisioning and failed. This means that you do not have an ip on this machine that matches one of the requested configs."
echo "If you continue, things will probably break."
echo ""
echo "If you wish to continue anyways, please provide a single number as an argument indicating which server is being bootstrapped."
echo "Example Usage:"
echo " -> './$SCRIPT 1' would provision $HOST_IP_1."
exit 1
fi
fi
if [ -z $MY_ID ]; then
MY_ID=$1
fi
prebuild="HOST_IP_${MY_ID}"
SELECTED="${!prebuild}"
echo "SELECTED: "
echo $SELECTED
# START ZOOKEEPER
docker run -d \
--net="host" \
-e SERVER_ID=$MY_ID \
-e ADDITIONAL_ZOOKEEPER_1=server.1=${HOST_IP_1}:2888:3888 \
-e ADDITIONAL_ZOOKEEPER_2=server.2=${HOST_IP_2}:2888:3888 \
-e ADDITIONAL_ZOOKEEPER_3=server.3=${HOST_IP_3}:2888:3888 \
--name zookeeper-$MY_ID \
garland/zookeeper
if [ $? -ne 0 ]; then
echo "Zookeeper could not start successfully."
exit 1
fi
# START MESOS
docker run --net="host" \
-p 5050:5050 \
-e "MESOS_HOSTNAME=`hostname`" \
-e "MESOS_IP=${SELECTED}" \
-e "MESOS_ZK=zk://${HOST_IP_1}:2181,${HOST_IP_2}:2181/mesos,${HOST_IP_3}:2181/mesos" \
-e "MESOS_PORT=5050" \
-e "MESOS_LOG_DIR=/var/log/mesos" \
-e "MESOS_QUORUM=1" \
-e "MESOS_REGISTRY=in_memory" \
-e "MESOS_WORK_DIR=/var/lib/mesos" \
-e "LIBPROCESS_IP=${SELECTED}" \
-d \
--name mesos-master \
garland/mesosphere-docker-mesos-master
if [ $? -ne 0 ]; then
echo "Mesos could not start successfully."
exit 1
fi
# START MARATHON
docker run \
-d \
-p 8080:8080 \
--name marathon \
garland/mesosphere-docker-marathon --master zk://${HOST_IP_1}:2181,${HOST_IP_2}:2181/mesos,${HOST_IP_3}:2181/mesos --zk zk://${HOST_IP_1}:2181,${HOST_IP_2}:2181/marathon,${HOST_IP_3}:2181/marathon
if [ $? -ne 0 ]; then
echo "Marathon could not start successfully."
exit 1
fi
echo "Mesos Master Bootstrapped!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment