這篇文章給大家分享的是有關(guān)HBase如何啟動腳本的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
成都創(chuàng)新互聯(lián)公司是專業(yè)的蘇州網(wǎng)站建設(shè)公司,蘇州接單;提供網(wǎng)站制作、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行蘇州網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
常用腳本主要包括:
1、$HBASE_HOME/bin/start-hbase.sh
啟動整個(gè)集群
2、$HBASE_HOME/bin/stop-hbase.sh
停止整個(gè)集群
3、$HBASE_HOME/bin/hbase-daemons.sh
啟動或停止,所有的regionserver或zookeeper或backup-master
4、$HBASE_HOME/bin/hbase-daemon.sh
啟動或停止,單個(gè)master或regionserver或zookeeper
5、$HBASE_HOME/bin/hbase
最終啟動的實(shí)現(xiàn)由這個(gè)腳本執(zhí)行
一般通過start-hbase.sh來啟動HBase集群,腳本執(zhí)行流程如下:
#!/usr/bin/env bash # $? 最后運(yùn)行的命令的結(jié)束代碼 # $# 傳shell給腳本的參數(shù)個(gè)數(shù) # $0 shell腳本本身的名字 # $1 shell腳本的第一個(gè)參數(shù) # $2 shell腳本的第二個(gè)參數(shù) # $@ shell腳本的所有參數(shù)的列表 # Start hadoop hbase daemons. # Run this on master node. usage="Usage: start-hbase.sh" bin=`dirname "${BASH_SOURCE-$0}"` bin=`cd "$bin">/dev/null; pwd` # 1、裝載相關(guān)配置 . "$bin"/hbase-config.sh # start hbase daemons errCode=$? # 最后運(yùn)行的命令的結(jié)束代碼 if [ $errCode -ne 0 ] # then exit $errCode fi # 2、解析參數(shù)(0.96版本及以后才可以帶唯一參數(shù)autorestart,作用就是重啟) if [ "$1" = "autorestart" ] # 獲取start-hbase.sh的參數(shù),調(diào)用時(shí)未提供參數(shù) then commandToRun="autorestart" else commandToRun="start" fi # HBASE-6504 - only take the first line of the output in case verbose gc is on distMode=`$bin/hbase --config "$HBASE_CONF_DIR" org.apache.hadoop.hbase.util.HBaseConfTool hbase.cluster.distributed | head -n 1` # 判定hbase是否為分布式模式,hbase-site.xml中配置的 # 3、調(diào)用相應(yīng)的啟動腳本 if [ "$distMode" == 'false' ] then "$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" $commandToRun master $@ else "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" $commandToRun zookeeper "$bin"/hbase-daemon.sh --config "${HBASE_CONF_DIR}" $commandToRun master "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" --hosts "${HBASE_REGIONSERVERS}" $commandToRun regionserver "$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" --hosts "${HBASE_BACKUP_MASTERS}" $commandToRun master-backup fi
hbase-config.sh的作用:
裝載相關(guān)配置,如HBASE_HOME目錄、conf目錄(HBASE_CONF_DIR)、regionserver機(jī)器列表(HBASE_REGIONSERVERS)、JAVA_HOME目錄以及HBASE_BACKUP_MASTERS機(jī)器列表它會調(diào)用$HBASE_HOME/conf/hbase-env.sh。
if [ -z "$HBASE_ENV_INIT" ] && [ -f "${HBASE_CONF_DIR}/hbase-env.sh" ]; then . "${HBASE_CONF_DIR}/hbase-env.sh" export HBASE_ENV_INIT="true" fi
hbase-env.sh的作用:
主要是配置JVM及其GC參數(shù),還可以配置log目錄及參數(shù),配置是否需要hbase管理ZK,配置進(jìn)程id目錄等。
# export JAVA_HOME=/usr/sca_app/java/jdk1.7.0 # Where log files are stored. $HBASE_HOME/logs by default. # export HBASE_LOG_DIR=${HBASE_HOME}/logs # Tell HBase whether it should manage it's own instance of Zookeeper or not. # export HBASE_MANAGES_ZK=true
hbase-daemons.sh的作用:
根據(jù)需要啟動的進(jìn)程。
# Run a hbase command on all slave hosts. # Modelled after $HADOOP_HOME/bin/hadoop-daemons.sh usage="Usage: hbase-daemons.sh [--config <hbase-confdir>] \ [--hosts regionserversfile] [start|stop] command args..." # if no args specified, show usage if [ $# -le 1 ]; then echo $usage exit 1 fi bin=`dirname "${BASH_SOURCE-$0}"` bin=`cd "$bin">/dev/null; pwd` . $bin/hbase-config.sh remote_cmd="cd ${HBASE_HOME}; $bin/hbase-daemon.sh --config ${HBASE_CONF_DIR} $@" args="--hosts ${HBASE_REGIONSERVERS} --config ${HBASE_CONF_DIR} $remote_cmd" command=$2 case $command in (zookeeper) exec "$bin/zookeepers.sh" $args ;; (master-backup) exec "$bin/master-backup.sh" $args ;; (*) exec "$bin/regionservers.sh" $args ;; esac
zookeepers.sh的作用:
如果hbase-env.sh中的HBASE_MANAGES_ZK" = "true",那么通過ZKServerTool這個(gè)類解析xml配置文件,獲取ZK節(jié)點(diǎn)列表(即hbase.zookeeper.quorum的配置值),然后通過SSH向這些節(jié)點(diǎn)發(fā)送遠(yuǎn)程命令:
cd ${HBASE_HOME}; $bin/hbase-daemon.sh --config ${HBASE_CONF_DIR} start/stop zookeeper if [ "$HBASE_MANAGES_ZK" = "true" ]; then hosts=`"$bin"/hbase org.apache.hadoop.hbase.zookeeper.ZKServerTool | grep '^ZK host:' | sed 's,^ZK host:,,'` cmd=$"${@// /\\ }" for zookeeper in $hosts; do ssh $HBASE_SSH_OPTS $zookeeper $cmd 2>&1 | sed "s/^/$zookeeper: /" & if [ "$HBASE_SLAVE_SLEEP" != "" ]; then sleep $HBASE_SLAVE_SLEEP fi done fi
regionservers.sh的作用:
與zookeepers.sh類似,通過${HBASE_CONF_DIR}/regionservers配置文件,獲取regionserver機(jī)器列表,然后SSH向這些機(jī)器發(fā)送遠(yuǎn)程命令:
cd ${HBASE_HOME}; $bin/hbase-daemon.sh --config ${HBASE_CONF_DIR} start/stop regionserver
master-backup.sh的作用:
通過${HBASE_CONF_DIR}/backup-masters這個(gè)配置文件,獲取backup-masters機(jī)器列表(默認(rèn)配置中,這個(gè)配置文件并不存在,所以不會啟動backup-master),然后SSH向這些機(jī)器發(fā)送遠(yuǎn)程命令:
cd ${HBASE_HOME}; $bin/hbase-daemon.sh --config ${HBASE_CONF_DIR} start/stop master --backup
hbase-daemon.sh的作用:
無論是zookeepers.sh還是regionservers.sh或是master-backup.sh,最終都會調(diào)用本地的hbase-daemon.sh,其執(zhí)行過程如下:
1.運(yùn)行hbase-config.sh,裝載各種配置(java環(huán)境、log配置、進(jìn)程ID目錄等);
2.指定文件的執(zhí)行及日志輸出路徑;
# get arguments startStop=$1 JAVA=$JAVA_HOME/bin/java export HBASE_LOG_PREFIX=hbase-$HBASE_IDENT_STRING-$command-$HOSTNAME export HBASE_LOGFILE=$HBASE_LOG_PREFIX.log if [ -z "${HBASE_ROOT_LOGGER}" ]; then export HBASE_ROOT_LOGGER=${HBASE_ROOT_LOGGER:-"INFO,RFA"} fi if [ -z "${HBASE_SECURITY_LOGGER}" ]; then export HBASE_SECURITY_LOGGER=${HBASE_SECURITY_LOGGER:-"INFO,RFAS"} fi logout=$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.out loggc=$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.gc loglog="${HBASE_LOG_DIR}/${HBASE_LOGFILE}" pid=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.pid export HBASE_ZNODE_FILE=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.znode export HBASE_START_FILE=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.autorestart # hbase0.98 # thiscmd=$0,表示該hbase-daemon.sh文件的絕對路徑 # hbase1.0.1中如下,但是獲取到的值與上面相同 thiscmd="$bin/$(basename ${BASH_SOURCE-$0})" args=$@ case $startStop in (start) check_before_start hbase_rotate_log $logout hbase_rotate_log $loggc echo starting $command, logging to $logout # 如下命令會將internal_start作為參數(shù)再次傳給hbase-daemon.sh腳本 nohup $thiscmd --config "${HBASE_CONF_DIR}" internal_start $command $args < /dev/null > ${logout} 2>&1 & sleep 1; head "${logout}" ;; (autorestart) check_before_start hbase_rotate_log $logout hbase_rotate_log $loggc nohup $thiscmd --config "${HBASE_CONF_DIR}" internal_autorestart $command $args < /dev/null > ${logout} 2>&1 & ;; (internal_start) # Add to the command log file vital stats on our environment. echo "`date` Starting $command on `hostname`" >> $loglog echo "`ulimit -a`" >> $loglog 2>&1 nice -n $HBASE_NICENESS "$HBASE_HOME"/bin/hbase \ --config "${HBASE_CONF_DIR}" \ $command "$@" start >> "$logout" 2>&1 & echo $! > $pid wait cleanZNode ;; (internal_autorestart) touch "$HBASE_START_FILE" #keep starting the command until asked to stop. Reloop on software crash while true do lastLaunchDate=`date +%s` $thiscmd --config "${HBASE_CONF_DIR}" internal_start $command $args #if the file does not exist it means that it was not stopped properly by the stop command if [ ! -f "$HBASE_START_FILE" ]; then exit 1 fi #if the cluster is being stopped then do not restart it again. zparent=`$bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.parent` if [ "$zparent" == "null" ]; then zparent="/hbase"; fi zkrunning=`$bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool zookeeper.znode.state` if [ "$zkrunning" == "null" ]; then zkrunning="running"; fi zkFullRunning=$zparent/$zkrunning $bin/hbase zkcli stat $zkFullRunning 2>&1 | grep "Node does not exist" 1>/dev/null 2>&1 #grep returns 0 if it found something, 1 otherwise if [ $? -eq 0 ]; then exit 1 fi #If ZooKeeper cannot be found, then do not restart $bin/hbase zkcli stat $zkFullRunning 2>&1 | grep Exception | grep ConnectionLoss 1>/dev/null 2>&1 if [ $? -eq 0 ]; then exit 1 fi #if it was launched less than 5 minutes ago, then wait for 5 minutes before starting it again. curDate=`date +%s` limitDate=`expr $lastLaunchDate + 300` if [ $limitDate -gt $curDate ]; then sleep 300 fi done ;; (stop) rm -f "$HBASE_START_FILE" if [ -f $pid ]; then pidToKill=`cat $pid` # kill -0 == see if the PID exists if kill -0 $pidToKill > /dev/null 2>&1; then echo -n stopping $command echo "`date` Terminating $command" >> $loglog kill $pidToKill > /dev/null 2>&1 waitForProcessEnd $pidToKill $command else retval=$? echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval fi else echo no $command to stop because no pid file $pid fi rm -f $pid ;; (restart) # stop the command $thiscmd --config "${HBASE_CONF_DIR}" stop $command $args & wait_until_done $! # wait a user-specified sleep period sp=${HBASE_RESTART_SLEEP:-3} if [ $sp -gt 0 ]; then sleep $sp fi # start the command $thiscmd --config "${HBASE_CONF_DIR}" start $command $args & wait_until_done $! ;; (*) echo $usage exit 1 ;; esac
3.如果是start命令?
滾動out輸出文件,滾動gc日志文件,日志文件中輸出啟動時(shí)間+ulimit -a信息,如
“Mon Nov 26 10:31:42 CST 2012 Starting master on dwxx.yy.taobao” "..open files (-n) 65536.."
4.調(diào)用$HBASE_HOME/bin/hbase start master/regionserver/zookeeper
5.執(zhí)行wait,等待3中開啟的進(jìn)程結(jié)束
6.執(zhí)行cleanZNode,將regionserver在zk上登記的節(jié)點(diǎn)刪除,這樣做的目的是:在regionserver進(jìn)程意外退出的情況下,可以免去3分鐘的ZK心跳超時(shí)等待,直接由master進(jìn)行宕機(jī)恢復(fù)
7.如果是stop命令?
根據(jù)進(jìn)程ID,檢查進(jìn)程是否存在;調(diào)用kill命令,然后等待到進(jìn)程不存在為止
8.如果是restart命令?
調(diào)用stop后,再調(diào)用start。。。
$HBASE_HOME/bin/hbase的作用:
最終啟動的實(shí)現(xiàn)由這個(gè)腳本執(zhí)行。
1.可以通過敲入$HBASE_HOME/bin/hbase查看其usage
[mvtech3@cu-dmz3 bin]$ hbase Usage: hbase [<options>] <command> [<args>] Options: --config DIR Configuration direction to use. Default: ./conf --hosts HOSTS Override the list in 'regionservers' file Commands: Some commands take arguments. Pass no args or -h for usage. shell Run the HBase shell hbck Run the hbase 'fsck' tool hlog Write-ahead-log analyzer hfile Store file analyzer zkcli Run the ZooKeeper shell upgrade Upgrade hbase master Run an HBase HMaster node regionserver Run an HBase HRegionServer node zookeeper Run a Zookeeper server rest Run an HBase REST server thrift Run the HBase Thrift server thrift2 Run the HBase Thrift2 server clean Run the HBase clean up script classpath Dump hbase CLASSPATH mapredcp Dump CLASSPATH entries required by mapreduce version Print the version CLASSNAME Run the class named CLASSNAME
2.bin/hbase shell,這個(gè)就是常用的shell工具,運(yùn)維常用的DDL和DML都會通過此進(jìn)行,其具體實(shí)現(xiàn)(對hbase的調(diào)用)是用ruby寫的。
[mvtech3@cu-dmz3 bin]$ hbase shell HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 0.98.1-hadoop2, r1583035, Sat Mar 29 17:19:25 PDT 2014 hbase(main):001:0>
3.bin/hbase hbck
運(yùn)維常用工具,檢查集群的數(shù)據(jù)一致性狀態(tài),其執(zhí)行是直接調(diào)org.apache.hadoop.hbase.util.HBaseFsck中的main函數(shù)。
4.bin/hbase hlog
log分析工具,其執(zhí)行是直接調(diào)org.apache.hadoop.hbase.wal.WALPrettyPrinter中的main函數(shù)。
5.bin/hbase hfile
hfile分析工具,其執(zhí)行是直接調(diào)org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter中的main函數(shù)。
6.bin/hbase zkcli
查看/管理ZK的shell工具,其調(diào)用了org.apache.zookeeper.ZooKeeperMain的main函數(shù)。
7.bin/hbase master、regionserver、zookeeper
$HBASE_HOME/bin/hbase start master/regionserver/zookeeper 其執(zhí)行則直接調(diào)用 org.apache.hadoop.hbase.master.HMaster org.apache.hadoop.hbase.regionserver.HRegionServer org.apache.hadoop.hbase.zookeeper.HQuorumPeer 的main函數(shù),而這些main函數(shù)就是了new一個(gè)了Runnable的HMaster/HRegionServer/QuorumPeer,在不停的Running...
8.bin/hbase classpath 打印classpath
9.bin/hbase version 打印hbase版本信息
10.bin/hbase CLASSNAME
所有實(shí)現(xiàn)了main函數(shù)的類都可以通過這個(gè)腳本來運(yùn)行,比如前面的hlog hfile hbck工具,實(shí)質(zhì)是對這個(gè)接口的一個(gè)快捷調(diào)用,而其他未提供快捷方式的class我們也可以用這個(gè)接口調(diào)用,如Region merge 調(diào)用:$HBASE_HOME/bin/hbase/org.apache.hadoop.hbase.util.Merge。
腳本使用小結(jié):
1.開啟集群,start-hbase.sh
2.關(guān)閉集群,stop-hbase.sh
3.開啟/關(guān)閉所有的regionserver、zookeeper
hbase-daemons.sh start/stop regionserver/zookeeper
4.開啟/關(guān)閉單個(gè)regionserver、zookeeper
hbase-daemon.sh start/stop regionserver/zookeeper
5.開啟/關(guān)閉master
hbase-daemon.sh start/stop master,是否成為active master取決于當(dāng)前是否有active master。
感謝各位的閱讀!關(guān)于“HBase如何啟動腳本”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
分享題目:HBase如何啟動腳本
瀏覽路徑:http://vcdvsql.cn/article14/podpde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊、企業(yè)網(wǎng)站制作、電子商務(wù)、網(wǎng)站維護(hù)、軟件開發(fā)、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)