From 476da38f1f71eb39c65c67c9dd33371e7e525124 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Tue, 27 Jan 2009 18:20:09 +0000 Subject: [PATCH] HBASE-1147 Modify the scripts to use Zookeeper git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@738184 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + bin/hbase | 68 +++++++++++++++++++++++------------------- bin/hbase-zookeeper.sh | 42 ++++++++++++++++++++++++++ bin/start-hbase.sh | 2 ++ bin/stop-hbase.sh | 2 ++ bin/zookeeper.sh | 63 ++++++++++++++++++++++++++++++++++++++ conf/hbase-env.sh | 3 ++ conf/zoo.cfg | 12 ++++++++ 8 files changed, 162 insertions(+), 31 deletions(-) create mode 100755 bin/hbase-zookeeper.sh create mode 100755 bin/zookeeper.sh create mode 100644 conf/zoo.cfg diff --git a/CHANGES.txt b/CHANGES.txt index 878cff015b9..b5199e0ba20 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,7 @@ HBase Change Log Release 0.20.0 - Unreleased INCOMPATIBLE CHANGES + HBASE-1147 Modify the scripts to use Zookeeper BUG FIXES HBASE-1140 "ant clean test" fails (Nitay Joffe via Stack) diff --git a/bin/hbase b/bin/hbase index 6ca95999745..ac756bbee7e 100755 --- a/bin/hbase +++ b/bin/hbase @@ -60,6 +60,7 @@ if [ $# = 0 ]; then echo " regionserver run an HBase HRegionServer node" echo " rest run an HBase REST server" echo " thrift run an HBase Thrift server" + echo " zookeeper run a Zookeeper server" echo " migrate upgrade an hbase.rootdir" echo " or" echo " CLASSNAME run the class named CLASSNAME" @@ -181,36 +182,41 @@ fi # restore ordinary behaviour unset IFS -# figure out which class to run -if [ "$COMMAND" = "shell" ] ; then - CLASS="org.jruby.Main ${HBASE_HOME}/bin/hirb.rb" -elif [ "$COMMAND" = "master" ] ; then - CLASS='org.apache.hadoop.hbase.master.HMaster' -elif [ "$COMMAND" = "regionserver" ] ; then - CLASS='org.apache.hadoop.hbase.regionserver.HRegionServer' -elif [ "$COMMAND" = "rest" ] ; then - CLASS='org.apache.hadoop.hbase.rest.Dispatcher' -elif [ "$COMMAND" = "thrift" ] ; then - CLASS='org.apache.hadoop.hbase.thrift.ThriftServer' -elif [ "$COMMAND" = "migrate" ] ; then - CLASS='org.apache.hadoop.hbase.util.Migrate' +# We kill the ZK instance using a hard coded port, to be changed +if [ "$COMMAND" = "zookeeper" ] && [ "$@" = "start" ] ; then + exec "$JAVA" $JAVA_HEAP_MAX -classpath "$CLASSPATH" org.apache.zookeeper.server.quorum.QuorumPeerMain conf/zoo.cfg else - CLASS=$COMMAND + # figure out which class to run + if [ "$COMMAND" = "shell" ] ; then + CLASS="org.jruby.Main ${HBASE_HOME}/bin/hirb.rb" + elif [ "$COMMAND" = "master" ] ; then + CLASS='org.apache.hadoop.hbase.master.HMaster' + elif [ "$COMMAND" = "regionserver" ] ; then + CLASS='org.apache.hadoop.hbase.regionserver.HRegionServer' + elif [ "$COMMAND" = "rest" ] ; then + CLASS='org.apache.hadoop.hbase.rest.Dispatcher' + elif [ "$COMMAND" = "thrift" ] ; then + CLASS='org.apache.hadoop.hbase.thrift.ThriftServer' + elif [ "$COMMAND" = "migrate" ] ; then + CLASS='org.apache.hadoop.hbase.util.Migrate' + else + CLASS=$COMMAND + fi + + # Have JVM dump heap if we run out of memory. Files will be 'launch directory' + # and are named like the following: java_pid21612.hprof. Apparently it doesn't + # 'cost' to have this flag enabled. Its a 1.6 flag only. See: + # http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better + HBASE_OPTS="$HBASE_OPTS -XX:+HeapDumpOnOutOfMemoryError" + HBASE_OPTS="$HBASE_OPTS -Dhbase.log.dir=$HBASE_LOG_DIR" + HBASE_OPTS="$HBASE_OPTS -Dhbase.log.file=$HBASE_LOGFILE" + HBASE_OPTS="$HBASE_OPTS -Dhbase.home.dir=$HBASE_HOME" + HBASE_OPTS="$HBASE_OPTS -Dhbase.id.str=$HBASE_IDENT_STRING" + HBASE_OPTS="$HBASE_OPTS -Dhbase.root.logger=${HBASE_ROOT_LOGGER:-INFO,console}" + if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then + HBASE_OPTS="$HBASE_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" + fi + + # run it + exec "$JAVA" $JAVA_HEAP_MAX $HBASE_OPTS -classpath "$CLASSPATH" $CLASS "$@" fi - -# Have JVM dump heap if we run out of memory. Files will be 'launch directory' -# and are named like the following: java_pid21612.hprof. Apparently it doesn't -# 'cost' to have this flag enabled. Its a 1.6 flag only. See: -# http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better -HBASE_OPTS="$HBASE_OPTS -XX:+HeapDumpOnOutOfMemoryError" -HBASE_OPTS="$HBASE_OPTS -Dhbase.log.dir=$HBASE_LOG_DIR" -HBASE_OPTS="$HBASE_OPTS -Dhbase.log.file=$HBASE_LOGFILE" -HBASE_OPTS="$HBASE_OPTS -Dhbase.home.dir=$HBASE_HOME" -HBASE_OPTS="$HBASE_OPTS -Dhbase.id.str=$HBASE_IDENT_STRING" -HBASE_OPTS="$HBASE_OPTS -Dhbase.root.logger=${HBASE_ROOT_LOGGER:-INFO,console}" -if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then - HBASE_OPTS="$HBASE_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" -fi - -# run it -exec "$JAVA" $JAVA_HEAP_MAX $HBASE_OPTS -classpath "$CLASSPATH" $CLASS "$@" diff --git a/bin/hbase-zookeeper.sh b/bin/hbase-zookeeper.sh new file mode 100755 index 00000000000..859faabc745 --- /dev/null +++ b/bin/hbase-zookeeper.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +#/** +# * Copyright 2009 The Apache Software Foundation +# * +# * 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. +# */ +# +# Run a hbase command on all slave hosts. +# Modelled after $HADOOP_HOME/bin/hadoop-daemons.sh + +usage="Usage: hbase-daemons.sh [--config ] \ + [start|stop] command args..." + +# if no args specified, show usage +if [ $# -le 1 ]; then + echo $usage + exit 1 +fi + +bin=`dirname "$0"` +bin=`cd "$bin"; pwd` + +. $bin/hbase-config.sh + +exec "$bin/zookeeper.sh" --config "${HBASE_CONF_DIR}" \ + cd "${HBASE_HOME}" \; \ + "$bin/hbase-daemon.sh" --config "${HBASE_CONF_DIR}" "$@" diff --git a/bin/start-hbase.sh b/bin/start-hbase.sh index 8fcc88c39fa..324fa643c2d 100755 --- a/bin/start-hbase.sh +++ b/bin/start-hbase.sh @@ -38,6 +38,8 @@ if [ $errCode -ne 0 ] then exit $errCode fi +"$bin"/hbase-zookeeper.sh --config "${HBASE_CONF_DIR}" \ + start zookeeper "$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" start master "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" \ --hosts "${HBASE_REGIONSERVERS}" start regionserver diff --git a/bin/stop-hbase.sh b/bin/stop-hbase.sh index fd861afc339..071ae55257f 100755 --- a/bin/stop-hbase.sh +++ b/bin/stop-hbase.sh @@ -30,3 +30,5 @@ bin=`cd "$bin"; pwd` . "$bin"/hbase-config.sh "$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" stop master +"$bin"/hbase-zookeeper.sh --config "${HBASE_CONF_DIR}" \ + stop zookeeper diff --git a/bin/zookeeper.sh b/bin/zookeeper.sh new file mode 100755 index 00000000000..85c15e8af20 --- /dev/null +++ b/bin/zookeeper.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# +#/** +# * Copyright 2009 The Apache Software Foundation +# * +# * 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. +# */ +# +# Run a shell command on all regionserver hosts. +# +# Environment Variables +# +# HADOOP_CONF_DIR Alternate conf dir. Default is ${HADOOP_HOME}/conf. +# HBASE_CONF_DIR Alternate hbase conf dir. Default is ${HBASE_HOME}/conf. +# HADOOP_SLAVE_SLEEP Seconds to sleep between spawning remote commands. +# HADOOP_SSH_OPTS Options passed to ssh when running remote commands. +# +# Modelled after $HADOOP_HOME/bin/slaves.sh. + +usage="Usage: zookeeper [--config ] command..." + +# if no args specified, show usage +if [ $# -le 0 ]; then + echo $usage + exit 1 +fi + +bin=`dirname "$0"` +bin=`cd "$bin"; pwd` + +. "$bin"/hbase-config.sh + +if [ -f "${HBASE_CONF_DIR}/hbase-env.sh" ]; then + . "${HBASE_CONF_DIR}/hbase-env.sh" +fi + +if [ "$HBASE_MANAGES_ZK" = "" ]; then + HBASE_MANAGES_ZK=true +fi + +if [ "$HBASE_MANAGES_ZK" = "true" ]; then + ssh $HBASE_SSH_OPTS 127.0.0.1 $"${@// /\\ }" \ + 2>&1 | sed "s/^/$zookeeper: /" & + if [ "$HBASE_SLAVE_SLEEP" != "" ]; then + sleep $HBASE_SLAVE_SLEEP + fi +fi + +wait diff --git a/conf/hbase-env.sh b/conf/hbase-env.sh index 9db8f9b1011..64fa4c541de 100644 --- a/conf/hbase-env.sh +++ b/conf/hbase-env.sh @@ -55,3 +55,6 @@ # can be useful in large clusters, where, e.g., slave rsyncs can # otherwise arrive faster than the master can service them. # export HBASE_SLAVE_SLEEP=0.1 + +# Tell HBase whether it should manage it's own instance of Zookeeper or not. +# export HBASE_MANAGES_ZK=true diff --git a/conf/zoo.cfg b/conf/zoo.cfg new file mode 100644 index 00000000000..418ec039814 --- /dev/null +++ b/conf/zoo.cfg @@ -0,0 +1,12 @@ +# The number of milliseconds of each tick +tickTime=2000 +# The number of ticks that the initial +# synchronization phase can take +initLimit=10 +# The number of ticks that can pass between +# sending a request and getting an acknowledgement +syncLimit=5 +# the directory where the snapshot is stored. +dataDir=/tmp/zookeeper +# the port at which the clients will connect +clientPort=2181