我已经在我的 ubuntu 12.04 单节点上安装了 Hadoop。我正在尝试执行一个 init 脚本以使 Hadoop 在启动时运行,但每次执行时它都会询问密码。
#!/bin/sh
### BEGIN INIT INFO
# Provides: hadoop services
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Hadoop services
# Short-Description: Enable Hadoop services including hdfs
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HADOOP_BIN=/home/naveen/softwares/hadoop-1.0.3/bin
NAME=hadoop
DESC=hadoop
USER=naveen
ROTATE_SUFFIX=
test -x $HADOOP_BIN || exit 0
RETVAL=0
set -e
cd /
start_hadoop () {
set +e
su $USER -s /bin/sh -c $HADOOP_BIN/start-all.sh > /var/log/hadoop/startup_log
case "$?" in
0)
echo SUCCESS
RETVAL=0
;;
1)
echo TIMEOUT - check /var/log/hadoop/startup_log
RETVAL=1
;;
*)
echo FAILED - check /var/log/hadoop/startup_log
RETVAL=1
;;
esac
set -e
}
stop_hadoop () {
set +e
if [ $RETVAL = 0 ] ; then
su $USER -s /bin/sh -c $HADOOP_BIN/stop-all.sh > /var/log/hadoop/shutdown_log
RETVAL=$?
if [ $RETVAL != 0 ] ; then
echo FAILED - check /var/log/hadoop/shutdown_log
fi
else
echo No nodes running
RETVAL=0
fi
set -e
}
restart_hadoop() {
stop_hadoop
start_hadoop
}
case "$1" in
start)
echo -n "Starting $DESC: "
start_hadoop
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
stop_hadoop
echo "$NAME."
;;
force-reload|restart)
echo -n "Restarting $DESC: "
restart_hadoop
echo "$NAME."
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload}" >&2
RETVAL=1
;;
esac
exit $RETVAL
请告诉我如何在不输入密码的情况下运行 Hadoop。
答案1
为运行 Hadoop 的用户设置 ssh 密钥
ssh-keygen
将公钥复制到 ~/.ssh/authorized_keys
cat ~/.ssh/public_key_name >> ~/.ssh/authorized_keys
以该用户身份运行 ssh localhost 来测试密钥。
如果可行,则 Hadoop 无需任何进一步配置即可使用它。
答案2
你可能想要 :
- 检查你的 sshd 配置(在 /etc/ssh/sshd_config 中)并确保 PubkeyAuthentication 设置为 yes
使用 hadoop 系统用户 ssh-keygen 生成密钥对,并复制到 authorized_keys 文件中
cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
确保文件的所有权正确
chown 600 $HOME/.ssh/authorized_keys
最后按照在线文档进行操作,不要忘记您的 hadoop-env.sh 配置。