2009-11-14 09:11:53 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
# Launch the EC2 HBase Zookeepers.
|
|
|
|
|
|
|
|
if [ -z $1 ]; then
|
|
|
|
echo "Cluster name required!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z $2 ]; then
|
|
|
|
echo "Must specify the number of zookeeper quorum peers to start."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
CLUSTER=$1
|
|
|
|
NO_INSTANCES=$2
|
|
|
|
|
|
|
|
# Import variables
|
|
|
|
bin=`dirname "$0"`
|
|
|
|
bin=`cd "$bin"; pwd`
|
|
|
|
. "$bin"/hbase-ec2-env.sh
|
|
|
|
|
|
|
|
type=$ZOO_INSTANCE_TYPE
|
2009-11-26 03:00:02 -05:00
|
|
|
[ -z "$type" ] && type=$SLAVE_INSTANCE_TYPE
|
2009-11-14 09:11:53 -05:00
|
|
|
arch=$ZOO_ARCH
|
2009-11-26 03:00:02 -05:00
|
|
|
[ -z "$arch" ] && arch=$SLAVE_ARCH
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
# Finding HBase image
|
2010-03-15 20:19:09 -04:00
|
|
|
[ -z "$ZOO_AMI_IMAGE" ] && ZOO_AMI_IMAGE=`ec2-describe-images $TOOL_OPTS -a | grep $S3_BUCKET | grep hbase | grep $HBASE_VERSION-$arch | grep available | awk '{print $2}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
# Start Zookeeper instances
|
|
|
|
|
|
|
|
echo "Starting ZooKeeper quorum ensemble."
|
|
|
|
|
|
|
|
peers=""
|
2010-03-15 20:19:09 -04:00
|
|
|
peer_addrs=""
|
|
|
|
i=0
|
|
|
|
while [ $i -lt $NO_INSTANCES ] ; do
|
2009-11-14 09:11:53 -05:00
|
|
|
echo "Starting an AMI with ID $ZOO_AMI_IMAGE (arch $arch) in group $CLUSTER_ZOOKEEPER"
|
2010-03-15 20:19:09 -04:00
|
|
|
inst=`ec2-run-instances $ZOO_AMI_IMAGE $TOOL_OPTS -n 1 -g $CLUSTER_ZOOKEEPER -k root -t $type | grep INSTANCE | awk '{print $2}'`
|
|
|
|
addr=`ec2-allocate-address $TOOL_OPTS | awk '{print $2}'`
|
|
|
|
ec2-associate-address $TOOL_OPTS $addr -i $inst
|
|
|
|
echo -n "Waiting for instance $inst to start: "
|
2009-11-14 09:11:53 -05:00
|
|
|
while true; do
|
|
|
|
printf "."
|
2010-03-15 20:19:09 -04:00
|
|
|
priv=`ec2-describe-instances $TOOL_OPTS $inst | grep running | awk '{print $5}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
if [ ! -z $priv ]; then
|
2010-03-15 20:19:09 -04:00
|
|
|
echo " Started ZooKeeper instance $inst as $priv"
|
2009-11-14 09:11:53 -05:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
2010-03-15 20:19:09 -04:00
|
|
|
host=`ec2-describe-instances $TOOL_OPTS $inst | grep INSTANCE | awk '{print $4}'`
|
|
|
|
echo "Associated elastic IP $host ($addr) with instance $INSTANCE"
|
|
|
|
peers="$peers $host"
|
|
|
|
peer_addrs="$peer_addrs $addr"
|
|
|
|
i=$(($i + 1))
|
2009-11-14 09:11:53 -05:00
|
|
|
done
|
|
|
|
|
2010-03-15 20:19:09 -04:00
|
|
|
quorum=`echo $peers | sed -e 's/ /,/g'`
|
|
|
|
echo $quorum > $ZOOKEEPER_QUORUM_PATH
|
|
|
|
echo $peer_addrs > $ZOOKEEPER_ADDR_PATH
|
|
|
|
echo "ZooKeeper quorum is $quorum"
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
# Start Zookeeper quorum
|
|
|
|
|
2009-12-31 15:48:12 -05:00
|
|
|
sleep 10
|
2010-03-15 20:19:09 -04:00
|
|
|
echo "Initializing the ZooKeeper quorum ensemble"
|
2009-11-14 09:11:53 -05:00
|
|
|
|
2010-03-15 20:19:09 -04:00
|
|
|
for host in $peers ; do
|
2009-11-14 09:11:53 -05:00
|
|
|
echo " $host"
|
2010-03-15 20:48:06 -04:00
|
|
|
i=0
|
|
|
|
while [ $i -lt 3 ] ; do
|
|
|
|
scp $SSH_OPTS "$bin"/hbase-ec2-init-zookeeper-remote.sh "root@${host}:/var/tmp" && ssh $SSH_OPTS "root@${host}" "sh -c \"ZOOKEEPER_QUORUM=\"$ZOOKEEPER_QUORUM\" sh /var/tmp/hbase-ec2-init-zookeeper-remote.sh\"" && break
|
|
|
|
sleep 5
|
|
|
|
i=$(($i + 1))
|
|
|
|
done
|
2009-11-14 09:11:53 -05:00
|
|
|
done
|