HBase如何启动脚本
这篇文章给大家分享的是有关HBase如何启动脚本的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
常用脚本主要包括:
1、$HBASE_HOME/bin/start-hbase.sh
启动整个集群
2、$HBASE_HOME/bin/stop-hbase.sh
停止整个集群
3、$HBASE_HOME/bin/hbase-daemons.sh
启动或停止,所有的regionserver或zookeeper或backup-master
4、$HBASE_HOME/bin/hbase-daemon.sh
启动或停止,单个master或regionserver或zookeeper
5、$HBASE_HOME/bin/hbase
最终启动的实现由这个脚本执行
一般通过start-hbase.sh来启动HBase集群,脚本执行流程如下:
#!/usr/bin/envbash#$?最后运行的命令的结束代码#$#传shell给脚本的参数个数#$0shell脚本本身的名字#$1shell脚本的第一个参数#$2shell脚本的第二个参数#$@shell脚本的所有参数的列表#Starthadoophbasedaemons.#Runthisonmasternode.usage="Usage:start-hbase.sh"bin=`dirname"${BASH_SOURCE-$0}"`bin=`cd"$bin">/dev/null;pwd`#1、装载相关配置."$bin"/hbase-config.sh#starthbasedaemonserrCode=$?#最后运行的命令的结束代码if[$errCode-ne0]#thenexit$errCodefi#2、解析参数(0.96版本及以后才可以带唯一参数autorestart,作用就是重启)if["$1"="autorestart"]#获取start-hbase.sh的参数,调用时未提供参数thencommandToRun="autorestart"elsecommandToRun="start"fi#HBASE-6504-onlytakethefirstlineoftheoutputincaseverbosegcisondistMode=`$bin/hbase--config"$HBASE_CONF_DIR"org.apache.hadoop.hbase.util.HBaseConfToolhbase.cluster.distributed|head-n1`#判定hbase是否为分布式模式,hbase-site.xml中配置的#3、调用相应的启动脚本if["$distMode"=='false']then"$bin"/hbase-daemon.sh--config"${HBASE_CONF_DIR}"$commandToRunmaster$@else"$bin"/hbase-daemons.sh--config"${HBASE_CONF_DIR}"$commandToRunzookeeper"$bin"/hbase-daemon.sh--config"${HBASE_CONF_DIR}"$commandToRunmaster"$bin"/hbase-daemons.sh--config"${HBASE_CONF_DIR}"--hosts"${HBASE_REGIONSERVERS}"$commandToRunregionserver"$bin"/hbase-daemons.sh--config"${HBASE_CONF_DIR}"--hosts"${HBASE_BACKUP_MASTERS}"$commandToRunmaster-backupfi
hbase-config.sh的作用:
装载相关配置,如HBASE_HOME目录、conf目录(HBASE_CONF_DIR)、regionserver机器列表(HBASE_REGIONSERVERS)、JAVA_HOME目录以及HBASE_BACKUP_MASTERS机器列表它会调用$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"exportHBASE_ENV_INIT="true"fi
hbase-env.sh的作用:
主要是配置JVM及其GC参数,还可以配置log目录及参数,配置是否需要hbase管理ZK,配置进程id目录等。
#exportJAVA_HOME=/usr/sca_app/java/jdk1.7.0#Wherelogfilesarestored.$HBASE_HOME/logsbydefault.#exportHBASE_LOG_DIR=${HBASE_HOME}/logs#TellHBasewhetheritshouldmanageit'sowninstanceofZookeeperornot.#exportHBASE_MANAGES_ZK=true
hbase-daemons.sh的作用:
根据需要启动的进程。
#Runahbasecommandonallslavehosts.#Modelledafter$HADOOP_HOME/bin/hadoop-daemons.shusage="Usage:hbase-daemons.sh[--config<hbase-confdir>]\[--hostsregionserversfile][start|stop]commandargs..."#ifnoargsspecified,showusageif[$#-le1];thenecho$usageexit1fibin=`dirname"${BASH_SOURCE-$0}"`bin=`cd"$bin">/dev/null;pwd`.$bin/hbase-config.shremote_cmd="cd${HBASE_HOME};$bin/hbase-daemon.sh--config${HBASE_CONF_DIR}$@"args="--hosts${HBASE_REGIONSERVERS}--config${HBASE_CONF_DIR}$remote_cmd"command=$2case$commandin(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这个类解析xml配置文件,获取ZK节点列表(即hbase.zookeeper.quorum的配置值),然后通过SSH向这些节点发送远程命令:
cd${HBASE_HOME};$bin/hbase-daemon.sh--config${HBASE_CONF_DIR}start/stopzookeeperif["$HBASE_MANAGES_ZK"="true"];thenhosts=`"$bin"/hbaseorg.apache.hadoop.hbase.zookeeper.ZKServerTool|grep'^ZKhost:'|sed's,^ZKhost:,,'`cmd=$"${@///\\}"forzookeeperin$hosts;dossh$HBASE_SSH_OPTS$zookeeper$cmd2>&1|sed"s/^/$zookeeper:/"&if["$HBASE_SLAVE_SLEEP"!=""];thensleep$HBASE_SLAVE_SLEEPfidonefi
regionservers.sh的作用:
与zookeepers.sh类似,通过${HBASE_CONF_DIR}/regionservers配置文件,获取regionserver机器列表,然后SSH向这些机器发送远程命令:
cd${HBASE_HOME};$bin/hbase-daemon.sh--config${HBASE_CONF_DIR}start/stopregionserver
master-backup.sh的作用:
通过${HBASE_CONF_DIR}/backup-masters这个配置文件,获取backup-masters机器列表(默认配置中,这个配置文件并不存在,所以不会启动backup-master),然后SSH向这些机器发送远程命令:
cd${HBASE_HOME};$bin/hbase-daemon.sh--config${HBASE_CONF_DIR}start/stopmaster--backup
hbase-daemon.sh的作用:
无论是zookeepers.sh还是regionservers.sh或是master-backup.sh,最终都会调用本地的hbase-daemon.sh,其执行过程如下:
1.运行hbase-config.sh,装载各种配置(java环境、log配置、进程ID目录等);
2.指定文件的执行及日志输出路径;
#getargumentsstartStop=$1JAVA=$JAVA_HOME/bin/javaexportHBASE_LOG_PREFIX=hbase-$HBASE_IDENT_STRING-$command-$HOSTNAMEexportHBASE_LOGFILE=$HBASE_LOG_PREFIX.logif[-z"${HBASE_ROOT_LOGGER}"];thenexportHBASE_ROOT_LOGGER=${HBASE_ROOT_LOGGER:-"INFO,RFA"}fiif[-z"${HBASE_SECURITY_LOGGER}"];thenexportHBASE_SECURITY_LOGGER=${HBASE_SECURITY_LOGGER:-"INFO,RFAS"}filogout=$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.outloggc=$HBASE_LOG_DIR/$HBASE_LOG_PREFIX.gcloglog="${HBASE_LOG_DIR}/${HBASE_LOGFILE}"pid=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.pidexportHBASE_ZNODE_FILE=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.znodeexportHBASE_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$startStopin(start)check_before_starthbase_rotate_log$logouthbase_rotate_log$loggcechostarting$command,loggingto$logout#如下命令会将internal_start作为参数再次传给hbase-daemon.sh脚本nohup$thiscmd--config"${HBASE_CONF_DIR}"internal_start$command$args</dev/null>${logout}2>&1&sleep1;head"${logout}";;(autorestart)check_before_starthbase_rotate_log$logouthbase_rotate_log$loggcnohup$thiscmd--config"${HBASE_CONF_DIR}"internal_autorestart$command$args</dev/null>${logout}2>&1&;;(internal_start)#Addtothecommandlogfilevitalstatsonourenvironment.echo"`date`Starting$commandon`hostname`">>$loglogecho"`ulimit-a`">>$loglog2>&1nice-n$HBASE_NICENESS"$HBASE_HOME"/bin/hbase\--config"${HBASE_CONF_DIR}"\$command"$@"start>>"$logout"2>&1&echo$!>$pidwaitcleanZNode;;(internal_autorestart)touch"$HBASE_START_FILE"#keepstartingthecommanduntilaskedtostop.RelooponsoftwarecrashwhiletruedolastLaunchDate=`date+%s`$thiscmd--config"${HBASE_CONF_DIR}"internal_start$command$args#ifthefiledoesnotexistitmeansthatitwasnotstoppedproperlybythestopcommandif[!-f"$HBASE_START_FILE"];thenexit1fi#iftheclusterisbeingstoppedthendonotrestartitagain.zparent=`$bin/hbaseorg.apache.hadoop.hbase.util.HBaseConfToolzookeeper.znode.parent`if["$zparent"=="null"];thenzparent="/hbase";fizkrunning=`$bin/hbaseorg.apache.hadoop.hbase.util.HBaseConfToolzookeeper.znode.state`if["$zkrunning"=="null"];thenzkrunning="running";fizkFullRunning=$zparent/$zkrunning$bin/hbasezkclistat$zkFullRunning2>&1|grep"Nodedoesnotexist"1>/dev/null2>&1#grepreturns0ifitfoundsomething,1otherwiseif[$?-eq0];thenexit1fi#IfZooKeepercannotbefound,thendonotrestart$bin/hbasezkclistat$zkFullRunning2>&1|grepException|grepConnectionLoss1>/dev/null2>&1if[$?-eq0];thenexit1fi#ifitwaslaunchedlessthan5minutesago,thenwaitfor5minutesbeforestartingitagain.curDate=`date+%s`limitDate=`expr$lastLaunchDate+300`if[$limitDate-gt$curDate];thensleep300fidone;;(stop)rm-f"$HBASE_START_FILE"if[-f$pid];thenpidToKill=`cat$pid`#kill-0==seeifthePIDexistsifkill-0$pidToKill>/dev/null2>&1;thenecho-nstopping$commandecho"`date`Terminating$command">>$loglogkill$pidToKill>/dev/null2>&1waitForProcessEnd$pidToKill$commandelseretval=$?echono$commandtostopbecausekill-0ofpid$pidToKillfailedwithstatus$retvalfielseechono$commandtostopbecausenopidfile$pidfirm-f$pid;;(restart)#stopthecommand$thiscmd--config"${HBASE_CONF_DIR}"stop$command$args&wait_until_done$!#waitauser-specifiedsleepperiodsp=${HBASE_RESTART_SLEEP:-3}if[$sp-gt0];thensleep$spfi#startthecommand$thiscmd--config"${HBASE_CONF_DIR}"start$command$args&wait_until_done$!;;(*)echo$usageexit1;;esac
3.如果是start命令?
滚动out输出文件,滚动gc日志文件,日志文件中输出启动时间+ulimit-a信息,如
“MonNov2610:31:42CST2012Startingmasterondwxx.yy.taobao”"..openfiles(-n)65536.."
4.调用$HBASE_HOME/bin/hbasestartmaster/regionserver/zookeeper
5.执行wait,等待3中开启的进程结束
6.执行cleanZNode,将regionserver在zk上登记的节点删除,这样做的目的是:在regionserver进程意外退出的情况下,可以免去3分钟的ZK心跳超时等待,直接由master进行宕机恢复
7.如果是stop命令?
根据进程ID,检查进程是否存在;调用kill命令,然后等待到进程不存在为止
8.如果是restart命令?
调用stop后,再调用start。。。
$HBASE_HOME/bin/hbase的作用:
最终启动的实现由这个脚本执行。
1.可以通过敲入$HBASE_HOME/bin/hbase查看其usage
[mvtech3@cu-dmz3bin]$hbaseUsage:hbase[<options>]<command>[<args>]Options:--configDIRConfigurationdirectiontouse.Default:./conf--hostsHOSTSOverridethelistin'regionservers'fileCommands:Somecommandstakearguments.Passnoargsor-hforusage.shellRuntheHBaseshellhbckRunthehbase'fsck'toolhlogWrite-ahead-loganalyzerhfileStorefileanalyzerzkcliRuntheZooKeepershellupgradeUpgradehbasemasterRunanHBaseHMasternoderegionserverRunanHBaseHRegionServernodezookeeperRunaZookeeperserverrestRunanHBaseRESTserverthriftRuntheHBaseThriftserverthrift2RuntheHBaseThrift2servercleanRuntheHBasecleanupscriptclasspathDumphbaseCLASSPATHmapredcpDumpCLASSPATHentriesrequiredbymapreduceversionPrinttheversionCLASSNAMERuntheclassnamedCLASSNAME
2.bin/hbaseshell,这个就是常用的shell工具,运维常用的DDL和DML都会通过此进行,其具体实现(对hbase的调用)是用ruby写的。
[mvtech3@cu-dmz3bin]$hbaseshellHBaseShell;enter'help<RETURN>'forlistofsupportedcommands.Type"exit<RETURN>"toleavetheHBaseShellVersion0.98.1-hadoop2,r1583035,SatMar2917:19:25PDT2014hbase(main):001:0>
3.bin/hbasehbck
运维常用工具,检查集群的数据一致性状态,其执行是直接调org.apache.hadoop.hbase.util.HBaseFsck中的main函数。
4.bin/hbasehlog
log分析工具,其执行是直接调org.apache.hadoop.hbase.wal.WALPrettyPrinter中的main函数。
5.bin/hbasehfile
hfile分析工具,其执行是直接调org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter中的main函数。
6.bin/hbasezkcli
查看/管理ZK的shell工具,其调用了org.apache.zookeeper.ZooKeeperMain的main函数。
7.bin/hbasemaster、regionserver、zookeeper
$HBASE_HOME/bin/hbasestartmaster/regionserver/zookeeper其执行则直接调用org.apache.hadoop.hbase.master.HMasterorg.apache.hadoop.hbase.regionserver.HRegionServerorg.apache.hadoop.hbase.zookeeper.HQuorumPeer的main函数,而这些main函数就是了new一个了Runnable的HMaster/HRegionServer/QuorumPeer,在不停的Running...
8.bin/hbaseclasspath打印classpath
9.bin/hbaseversion打印hbase版本信息
10.bin/hbaseCLASSNAME
所有实现了main函数的类都可以通过这个脚本来运行,比如前面的hloghfilehbck工具,实质是对这个接口的一个快捷调用,而其他未提供快捷方式的class我们也可以用这个接口调用,如Regionmerge调用:$HBASE_HOME/bin/hbase/org.apache.hadoop.hbase.util.Merge。
脚本使用小结:
1.开启集群,start-hbase.sh
2.关闭集群,stop-hbase.sh
3.开启/关闭所有的regionserver、zookeeper
hbase-daemons.shstart/stopregionserver/zookeeper
4.开启/关闭单个regionserver、zookeeper
hbase-daemon.shstart/stopregionserver/zookeeper
5.开启/关闭master
hbase-daemon.shstart/stopmaster,是否成为activemaster取决于当前是否有active master。
感谢各位的阅读!关于“HBase如何启动脚本”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。