hbase/contrib/ec2/bin/launch-hbase-zookeeper

95 lines
2.9 KiB
Plaintext
Raw Normal View History

#!/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
[ -z "$type" ] && type=$SLAVE_INSTANCE_TYPE
arch=$ZOO_ARCH
[ -z "$arch" ] && arch=$SLAVE_ARCH
# Finding HBase image
[ -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}'`
# Start Zookeeper instances
echo "Starting ZooKeeper quorum ensemble."
peers=""
peer_addrs=""
i=0
while [ $i -lt $NO_INSTANCES ] ; do
echo "Starting an AMI with ID $ZOO_AMI_IMAGE (arch $arch) in group $CLUSTER_ZOOKEEPER"
inst=`ec2-run-instances $TOOL_OPTS $ZOO_AMI_IMAGE -n 1 -g $CLUSTER_ZOOKEEPER -k root -t $type | grep INSTANCE | awk '{print $2}'`
if [ "$ENABLE_ELASTIC_IPS" = "true" ] ; then
addr=`ec2-allocate-address $TOOL_OPTS | awk '{print $2}'`
ec2-associate-address $TOOL_OPTS $addr -i $inst
fi
echo -n "Waiting for instance $inst to start: "
while true; do
printf "."
priv=`ec2-describe-instances $TOOL_OPTS $inst | grep running | awk '{print $5}'`
if [ ! -z $priv ]; then
echo " Started ZooKeeper instance $inst as $priv"
break
fi
sleep 1
done
host=`ec2-describe-instances $TOOL_OPTS $inst | grep INSTANCE | awk '{print $4}'`
peers="$peers $host"
peer_addrs="$peer_addrs $addr"
i=$(($i + 1))
done
quorum=`echo $peers | sed -e 's/ /,/g'`
echo $quorum > $ZOOKEEPER_QUORUM_PATH
echo $peer_addrs > $ZOOKEEPER_ADDR_PATH
echo "ZooKeeper quorum is $quorum"
# Start Zookeeper quorum
sleep 10
echo "Initializing the ZooKeeper quorum ensemble"
for host in $peers ; do
echo " $host"
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
done