打开/etc/hbase/conf/hbase-env.sh,找到以下内容:
# Enable remote JDWP debugging of major HBase processes. Meant for Core Developers
# export HBASE_MASTER_OPTS="$HBASE_MASTER_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8070"
# export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8071"
# export HBASE_THRIFT_OPTS="$HBASE_THRIFT_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8072"
# export HBASE_ZOOKEEPER_OPTS="$HBASE_ZOOKEEPER_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8073"
如果想远程调式hbase-master进程,请去掉对HBASE_MASTER_OPTS的注释,其他依次类推。注意,我这里使用的是cdh-4.3.0中的hbase。
配置hive远程调试
停止hive-server2进程,然后以下面命令启动hive-server2
hive --service hiveserver --debug
进程会监听在8000端口等待调试连接。如果想更改监听端口,可以修改配置文件:${HIVE_HOME}bin/ext/debug.sh
如果Hadoop是0.23以上版本,debug模式启动Cli会报错:
ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
打开${Hadoop_HOME}/bin/hadoop,注释掉以下代码
# Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
配置yarn远程调试
请在以下代码添加调试参数:
if [ "$COMMAND" = "classpath" ] ; then
if $cygwin; then
CLASSPATH=`cygpath -p -w "$CLASSPATH"`
fi
echo $CLASSPATH
exit
elif [ "$COMMAND" = "rmadmin" ] ; then
CLASS='org.apache.hadoop.yarn.client.RMAdmin'
YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
elif [ "$COMMAND" = "application" ] ; then
class="org".apache.hadoop.yarn.client.cli.ApplicationCLI
YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
elif [ "$COMMAND" = "node" ] ; then
class="org".apache.hadoop.yarn.client.cli.NodeCLI
YARN_OPTS="$YARN_OPTS $YARN_CLIENT_OPTS"
elif [ "$COMMAND" = "resourcemanager" ] ; then
CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/rm-config/log4j.properties
CLASS='org.apache.hadoop.yarn.server.resourcemanager.ResourceManager'
YARN_OPTS="$YARN_OPTS $YARN_RESOURCEMANAGER_OPTS"
if [ "$YARN_RESOURCEMANAGER_HEAPSIZE" != "" ]; then
JAVA_HEAP_MAX="-Xmx""$YARN_RESOURCEMANAGER_HEAPSIZE""m"
fi
elif [ "$COMMAND" = "nodemanager" ] ; then
CLASSPATH=${CLASSPATH}:$YARN_CONF_DIR/nm-config/log4j.properties
CLASS='org.apache.hadoop.yarn.server.nodemanager.NodeManager'
YARN_OPTS="$YARN_OPTS -server $YARN_NODEMANAGER_OPTS"
if [ "$YARN_NODEMANAGER_HEAPSIZE" != "" ]; then
JAVA_HEAP_MAX="-Xmx""$YARN_NODEMANAGER_HEAPSIZE""m"
fi
elif [ "$COMMAND" = "proxyserver" ] ; then
CLASS='org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer'
YARN_OPTS="$YARN_OPTS $YARN_PROXYSERVER_OPTS"
if [ "$YARN_PROXYSERVER_HEAPSIZE" != "" ]; then
JAVA_HEAP_MAX="-Xmx""$YARN_PROXYSERVER_HEAPSIZE""m"
fi
例如: 如果你想调试resourcemanager代码,请在elif [ "$COMMAND" = "resourcemanager" ] 分支内添加如下代码:
YARN_RESOURCEMANAGER_OPTS="$YARN_RESOURCEMANAGER_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6001"
其他进程,参照上面即可。
注意:端口不要冲突。
配置mapreduce远程调试
如果想要调试Map 或Reduce Task,则修改bin/hadoop已经没用了,因为bin/hadoop中没有Map Task的启动参数。
此时需要修改mapred-site.xml
在一个TaskTracker上,只能启动一个Map Task或一个Reduce Task,否则启动时会有端口冲突。因此要修改所有TaskTracker上的conf/hadoop-site.xml中的配置项:
在Eclipse中使用方法:
打开eclipse,找到Debug Configurations...,添加一个Remout Java Application:
在source中可以关联到hive的源代码,然后,单击Debug按钮进入远程debug模式。
编写个jdbc的测试类,运行代码,这时候因为hive-server2端没有设置端点,故程序可以正常运行直到结束。
在hive代码中设置一个断点,如ExecDriver.java的execute方法中设置断点,然后再运行jdbc测试类。