http://qing.weibo.com/tj/53dcb3de330005fr.html
发表于:2011年11月08日 15:16
0
HBase cluster startup process:
假如我们HDFS已经安装完成, 现在来将HBase拷贝到NN, DN上, 做好配置, 准备启动.
先从start-hbase.sh入手, 看看集群的启动顺序:
1. 首先获得当前source的目录(bin目录)
bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin">/dev/null; pwd`
2. 运行bin/hbase-config.sh和conf/hbase-env.sh设置相关的环境变量, 可以通过参数另外指定conf目录.
设置的变量有:
hbase-config.sh:
HBASE_HOME, HBASE_CONF_DIR, HBASE_REGIONSERVERS, HBASE_BACKUP_MASTERS
hbase-env.sh:
JAVA_HOME, HBASE_CLASSPATH, HBASE_HEAPSIZE, HBASE_OPTS, HBASE_REGIONSERVERS, HBASE_SSH_OPTS,
HBASE_LOG_DIR, HBASE_IDENT_STRING, HBASE_NICENESS, HBASE_PID_DIR,HBASE_SLAVE_SLEEP, HBASE_MANAGES_ZK
JMX: HBASE_JMX_BASE, HBASE_MASTER_OPTS, HBASE_REGIONSERVER_OPTS, HBASE_THRIFT_OPTS, HBASE_ZOOKEEPER_OPTS
3. 启动HBase的相关进程
distMode=`$bin/hbase org.apache.hadoop.hbase.util.HBaseConfTool hbase.cluster.distributed`
判断是否是分布式模式
True: 仅启动本地master
"$bin"/hbase-daemon.sh start master
False: 启动Zookeeper --> master --> regionservers --> master-backup
"$bin"/hbase-daemons.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
"$bin"/hbase-daemons.sh --config "${HBASE_CONF_DIR}" \
--hosts "${HBASE_BACKUP_MASTERS}" start master-backup
通过hbase-daemon.sh启动master, hbase-daemons.sh启动zk,rs和master-bk.
4. hbase-daemons.sh: 直接看代码:
#The command run on remote server
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)
# ssh to zk server, run $args
exec "$bin/zookeepers.sh" $args
;;
(master-backup)
# ssh to master-backup server, run $args
exec "$bin/master-backup.sh" $args
;;
(*)
# ssh to regionservers, run $args
exec "$bin/regionservers.sh" $args
;;
esac
5. hbase-daemon.sh : Runs a Hadoop hbase command as a daemon.
* 获取命令参数(start/stop, command), 设置log目录和级别, 获得进程pid和权限
* start: 创建pid_dir,设置log输出目录, 启动进程
nohup nice -n $HBASE_NICENESS "$HBASE_HOME"/bin/hbase --config " ${HBASE_CONF_DIR}" $command start "$@" > "$logout" 2>&1 < /dev/null &
* stop: kill -9 `cat $pid` > /dev/null 2>&1, 然后rm $pid, 真直接...
* restart: 先stop, 在start
$thiscmd --config "${HBASE_CONF_DIR}" stop $command $args &
wait & sleep
$thiscmd --config "${HBASE_CONF_DIR}" start $command $args &
基本上到这里就我们了解了, 不管是master还是regionserver, 他们启动本地进程都是通过hbase-daemon.sh, 最后都是通过bin/hbase来进行启动.
6. bin/hbase: 这个shell有点长.
先看看usage:
Usage: hbase <command>
where <command> is one of:
shell run the HBase shell
zkcli run the ZooKeeper shell
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 an HBase Thrift server
avro run an HBase Avro server
migrate upgrade an hbase.rootdir
hbck run the hbase 'fsck' tool
classpath dump hbase CLASSPATH
or
CLASSNAME run the class named CLASSNAME
Most commands print help when invoked w/o parameters.
hbase的运行步骤为:
* 组装$ClassPath, 包括了HBASE_CONF_DIR, jre lib, 开发环境下还包括(maven main classes, test classes, 依赖包), webapp, HBASE_HOME下的jar包.
* log目录变量设置.
* 针对windows下面集群的配置, 这个就略过了.
* 根据command来制定运行类$CLASS(重要啦):
shell: org.jruby.Main ${HBASE_HOME}/bin/hirb.rb
master: org.apache.hadoop.hbase.master.HMaster $HBASE_OPTS $HBASE_MASTER_OPTS
regionserver: org.apache.hadoop.hbase.regionserver.HRegionServer $HBASE_OPTS $HBASE_REGIONSERVER_OPTS
thrift: org.apache.hadoop.hbase.thrift.ThriftServer $HBASE_OPTS $HBASE_THRIFT_OPTS
rest: org.apache.hadoop.hbase.rest.Main $HBASE_OPTS $HBASE_REST_OPTS
avro: org.apache.hadoop.hbase.avro.AvroServer $HBASE_OPTS $HBASE_AVRO_OPTS
migrate: org.apache.hadoop.hbase.util.Migrate
hbck: org.apache.hadoop.hbase.util.HBaseFsck
zookeeper: org.apache.hadoop.hbase.zookeeper.HQuorumPeer $HBASE_OPTS $HBASE_ZOOKEEPER_OPTS
zkcli: org.apache.zookeeper.ZooKeeperMain `"$bin"/hbase org.apache.hadoop.hbase.zookeeper.ZooKeeperMainServerArg`
classpath: $CLASSPATH
* 给$HBASE_OPTS添加一些log设置.
* 运行class啦~~
"$JAVA" $JAVA_HEAP_MAX $HBASE_OPTS -classpath "$CLASSPATH" $CLASS "$@"
好了, HBase的启动脚本这就过了一遍,通过这个流程我们可以知道, stop-hbase也是一样通过hbase-daemons.sh, hbase-daemon.sh和bin/hbase来完成的.
要想把hbase的集群管理弄好, 详细了解它的各种运行脚本也是必须的, 等什么时候空了在详细的整理一下HBase的环境变量和JVM启动参数.
下次我们在来分别看看master, regionserver运行class的流程, 以对master和regionserver的启动过程有个大致的了解.