hadoop开启远程调试

1. 修改bin/hadoop,在启动daemon进程之前加入如下代码:

# Turn on debug mode if neccesary
debug_file="$bin/hadoop.debug"
is_debug_enabled()
{
if [ -f $debug_file ]; then
cat $debug_file | grep $1 >/dev/null 2>&1
fi
}

case "$COMMAND" in
namenode)
DEBUG_PORT=11000
;;
datanode)
DEBUG_PORT=11001
;;
jobtracker)
DEBUG_PORT=11002
;;
tasktracker)
DEBUG_PORT=11003
;;
secondarynamenode)
DEBUG_PORT=11004
;;
esac

if is_debug_enabled $COMMAND && [ ! -z $DEBUG_PORT ]; then
echo "debug for $COMMAND is enabled, port is $DEBUG_PORT"
HADOOP_OPTS="$HADOOP_OPTS -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=$DEBUG_PORT,suspend=y,server=y"
fi

想要调试哪个进程,即在bin/hadoop.debug中添加该进程的角色如namenode/datanode,调试端口号是直接写死在脚本的。

2. eclipse中,debug -> debug configuration -> 添加remote java application -> 填入ip和DEBUG_PORT号。

Debug Configurations _005

留下评论