today i will learn to hit the hbase source codes.
for the rule from simple to difficult,i will get a standalone mode to run hbase to do this.
ok,let's look at the shell
start-hbase.sh
it will start certain daemons ,e.g., HMaster,HResionServer,Zookeeper(if any) etc.details listed below:
if [ "$distMode" == 'false' ] then "$bin"/hbase-daemon.sh start master else "$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 fi
yes,the relase of hbase list one more daemon named "maser-backup" then hbase-0.20.6,but now i dont care it as i will consume it when need.
---
今天启动0.94启动不了,发现异常:
Exception in thread "main" java.lang.NoClassDefFoundError: hadoop,class:org/apache/hadoop/hbase/util/GetJavaProperty,params:java/library/path
刚开始以为是导入到eclipse引起的,但后来想想只是导入没有做其它修改应该不是这个原因.
由于对shell不熟,经过:docs阅读 -> goolge 后发现没相关问题,再阅读源码,调度.最終定位到bin/hbase文件:
for 0.94
HADOOP_IN_PATH=$(PATH="${HADOOP_HOME:-${HADOOP_PREFIX}}/bin:$PATH" which hadoop 2>/dev/null) #echo "xx $HADOOP_IN_PATH" if [ -f ${HADOOP_IN_PATH} ]; then HADOOP_JAVA_LIBRARY_PATH=$(HADOOP_CLASSPATH="$CLASSPATH" ${HADOOP_IN_PATH} \ org.apache.hadoop.hbase.util.GetJavaProperty java.library.path 2>/dev/null) if [ -n "$HADOOP_JAVA_LIBRARY_PATH" ]; then JAVA_LIBRARY_PATH=$(append_path "${JAVA_LIBRARY_PATH}" "$HADOOP_JAVA_LIBRARY_PATH") fi CLASSPATH=$(append_path "${CLASSPATH}" `${HADOOP_IN_PATH} classpath 2>/dev/null`) fi
but 0.92:
#If avail, add Hadoop to the CLASSPATH and to the JAVA_LIBRARY_PATH if [ ! -z $HADOOP_HOME ]; then HADOOPCPPATH="" if [ -z $HADOOP_CONF_DIR ]; then HADOOPCPPATH=$(append_path "${HADOOPCPPATH}" "${HADOOP_HOME}/conf") else HADOOPCPPATH=$(append_path "${HADOOPCPPATH}" "${HADOOP_CONF_DIR}") fi if [ "`echo ${HADOOP_HOME}/hadoop-core*.jar`" != "${HADOOP_HOME}/hadoop-core*.jar" ] ; then HADOOPCPPATH=$(append_path "${HADOOPCPPATH}" `ls ${HADOOP_HOME}/hadoop-core*.jar | head -1`) else HADOOPCPPATH=$(append_path "${HADOOPCPPATH}" `ls ${HADOOP_HOME}/hadoop-common*.jar | head -1`) HADOOPCPPATH=$(append_path "${HADOOPCPPATH}" `ls ${HADOOP_HOME}/hadoop-hdfs*.jar | head -1`) HADOOPCPPATH=$(append_path "${HADOOPCPPATH}" `ls ${HADOOP_HOME}/hadoop-mapred*.jar | head -1`) fi for i in "${HADOOP_HOME}/lib/"*.jar; do HADOOPCPPATH="${HADOOPCPPATH}:$i" done CLASSPATH=$(append_path "${CLASSPATH}" "${HADOOPCPPATH}") if [ -d "${HADOOP_HOME}/lib/native" ]; then JAVA_PLATFORM=`CLASSPATH=${HADOOPCPPATH} ${JAVA} org.apache.hadoop.util.PlatformName | sed -e "s/ /_/g"` if [ -d "${HADOOP_HOME}/lib/native/${JAVA_PLATFORM}" ]; then JAVA_LIBRARY_PATH=$(append_path "${JAVA_LIBRARY_PATH}" "${HADOOP_HOME}/lib/native/${JAVA_PLATFORM}") fi fi fi
其实区别就是在这里,可能是这版本不再考虑HADOOP_HOME所以完全没有再利用它来处理.
而在xx处输出是:/path/to/hadoop/bin/hadoop,再结合异常,断定了在添加hadoop到classpath时直接利用hadoop(shell)执行了GetJavaProperty(forjava.lib.path)引起的异常,当然这是可选的.所以当我把HADOP_IN_PATH comment后便正常操作了.
经证实,是因为hadoop与hbase安装在同一台机器上引起的,因为hbase从$PATH中读取了hadoop (shell),于是乎使用hadoop相关jars来运行.