Hadoop启动脚本分析
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
能看到这篇博客的你估计对Hadoop已经有一个系统的了解了,最起码各种搭建方式你应该是会的,不会也没有关系,可以参考我的笔记,里面有各种搭建方式,哈哈哈~
[yinzhengjie@s101 ~]$ cat `which xcall.sh`
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com #判断用户是否传参
if [ $# -lt ];then
echo "请输入参数"
exit
fi #获取用户输入的命令
cmd=$@ for (( i=;i<=;i++ ))
do
#使终端变绿色
tput setaf
echo ============= s$i $cmd ============
#使终端变回原来的颜色,即白灰色
tput setaf
#远程执行命令
ssh s$i $cmd
#判断命令是否执行成功
if [ $? == ];then
echo "命令执行成功"
fi
done
[yinzhengjie@s101 ~]$
xcall.sh 脚本内容,我在测试的时候经常使用它
一.start-all.sh脚本分析
[yinzhengjie@s101 ~]$ cat `which start-all.sh` | grep -v ^# | grep -v ^$
echo "This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh"
bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin"; pwd`
DEFAULT_LIBEXEC_DIR="$bin"/../libexec
HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
. $HADOOP_LIBEXEC_DIR/hadoop-config.sh
if [ -f "${HADOOP_HDFS_HOME}"/sbin/start-dfs.sh ]; then
"${HADOOP_HDFS_HOME}"/sbin/start-dfs.sh --config $HADOOP_CONF_DIR
fi
if [ -f "${HADOOP_YARN_HOME}"/sbin/start-yarn.sh ]; then
"${HADOOP_YARN_HOME}"/sbin/start-yarn.sh --config $HADOOP_CONF_DIR
fi
[yinzhengjie@s101 ~]$
从这个脚本中的第一行我们可以看出来,这个脚本已经过时了,取而代之的是:“This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh”,也就是 “start-dfs.sh”和“start-yarn.sh”。
二.start-dfs.sh 脚本分析
[yinzhengjie@s101 ~]$ more `which start-dfs.sh` | grep -v ^# | grep -v ^$
usage="Usage: start-dfs.sh [-upgrade|-rollback] [other options such as -clusterId]"
bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin"; pwd`
DEFAULT_LIBEXEC_DIR="$bin"/../libexec
HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
. $HADOOP_LIBEXEC_DIR/hdfs-config.sh
if [[ $# -ge ]]; then
startOpt="$1"
shift
case "$startOpt" in
-upgrade)
nameStartOpt="$startOpt"
;;
-rollback)
dataStartOpt="$startOpt"
;;
*)
echo $usage
exit
;;
esac
fi
nameStartOpt="$nameStartOpt $@"
NAMENODES=$($HADOOP_PREFIX/bin/hdfs getconf -namenodes)
echo "Starting namenodes on [$NAMENODES]"
"$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
--config "$HADOOP_CONF_DIR" \
--hostnames "$NAMENODES" \
--script "$bin/hdfs" start namenode $nameStartOpt
if [ -n "$HADOOP_SECURE_DN_USER" ]; then
echo \
"Attempting to start secure cluster, skipping datanodes. " \
"Run start-secure-dns.sh as root to complete startup."
else
"$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
--config "$HADOOP_CONF_DIR" \
--script "$bin/hdfs" start datanode $dataStartOpt
fi
SECONDARY_NAMENODES=$($HADOOP_PREFIX/bin/hdfs getconf -secondarynamenodes >/dev/null)
if [ -n "$SECONDARY_NAMENODES" ]; then
echo "Starting secondary namenodes [$SECONDARY_NAMENODES]"
"$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
--config "$HADOOP_CONF_DIR" \
--hostnames "$SECONDARY_NAMENODES" \
--script "$bin/hdfs" start secondarynamenode
fi
SHARED_EDITS_DIR=$($HADOOP_PREFIX/bin/hdfs getconf -confKey dfs.namenode.shared.edits.dir >&-)
case "$SHARED_EDITS_DIR" in
qjournal://*)
JOURNAL_NODES=$(echo "$SHARED_EDITS_DIR" | sed 's,qjournal://\([^/]*\)/.*,\1,g; s/;/ /g; s/:[0-9]*//g')
echo "Starting journal nodes [$JOURNAL_NODES]"
"$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
--config "$HADOOP_CONF_DIR" \
--hostnames "$JOURNAL_NODES" \
--script "$bin/hdfs" start journalnode ;;
esac
AUTOHA_ENABLED=$($HADOOP_PREFIX/bin/hdfs getconf -confKey dfs.ha.automatic-failover.enabled)
if [ "$(echo "$AUTOHA_ENABLED" | tr A-Z a-z)" = "true" ]; then
echo "Starting ZK Failover Controllers on NN hosts [$NAMENODES]"
"$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
--config "$HADOOP_CONF_DIR" \
--hostnames "$NAMENODES" \
--script "$bin/hdfs" start zkfc
fi
[yinzhengjie@s101 ~]$
以上的注释已经被我过滤掉了,从这个脚本中大致可以看出这个脚本是用来启动hdfs进程的,即分别是:NameNode,DataNode以及secondaryNameNode。
1>.单独启动NameNode脚本用法如下:
[yinzhengjie@s101 ~]$ hadoop-daemon.sh --hostnames s101 start namenode
starting namenode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-namenode-s101.out
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
NameNode
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$
以上是单独启动NameNode节点的脚本用法,如果你想要批量启动的话可以使用hadoop-daemons.sh命令,只不过由于我部署的集群环境只有一个NameNode节点,因此看不出来有任何效果。
[yinzhengjie@s101 ~]$ hadoop-daemons.sh --hostnames ` hdfs getconf -namenodes` start namenode
s101: starting namenode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-namenode-s101.out
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
NameNode
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ hadoop-daemons.sh --hostnames ` hdfs getconf -namenodes` start namenode
2>.单独启动DataNode脚本如下:
[yinzhengjie@s101 ~]$ hadoop-daemon.sh start datanode
starting datanode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-datanode-s101.out
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
DataNode
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$
以上是单独启动DataNode的脚本用法,想要执行如果你想要批量启动的话可以使用hadoop-daemons.sh命令,由于我有三个节点,看起来效果就很明显了。
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$ hadoop-daemons.sh start datanode
s102: starting datanode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-datanode-s102.out
s104: starting datanode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-datanode-s104.out
s103: starting datanode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-datanode-s103.out
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
命令执行成功
============= s102 jps ============
Jps
DataNode
命令执行成功
============= s103 jps ============
Jps
DataNode
命令执行成功
============= s104 jps ============
Jps
DataNode
命令执行成功
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ hadoop-daemons.sh start datanode
3>.单独启动secondaryNameNode
[yinzhengjie@s101 ~]$ hadoop-daemon.sh --hostnames s101 start secondarynamenode
starting secondarynamenode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-secondarynamenode-s101.out
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
SecondaryNameNode
Jps
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$
以上是单独启动secondaryNameNode的脚本用法,想要执行如果你想要批量启动的话可以使用hadoop-daemons.sh命令,由于我有三个节点,看起来效果就很明显了。
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ for i in `cat /soft/hadoop/etc/hadoop/slaves | grep -v ^#` ;do hadoop-daemons.sh --hostnames $i start secondarynamenode ;done
s102: starting secondarynamenode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-secondarynamenode-s102.out
s103: starting secondarynamenode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-secondarynamenode-s103.out
s104: starting secondarynamenode, logging to /soft/hadoop-2.7./logs/hadoop-yinzhengjie-secondarynamenode-s104.out
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
命令执行成功
============= s102 jps ============
Jps
SecondaryNameNode
命令执行成功
============= s103 jps ============
Jps
SecondaryNameNode
命令执行成功
============= s104 jps ============
Jps
SecondaryNameNode
命令执行成功
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ for i in `cat /soft/hadoop/etc/hadoop/slaves | grep -v ^#` ;do hadoop-daemons.sh --hostnames $i start secondarynamenode ;done
三.start-yarn.sh 脚本分析
[yinzhengjie@s101 ~]$ cat /soft/hadoop/sbin/start-yarn.sh | grep -v ^# | grep -v ^$
echo "starting yarn daemons"
bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin"; pwd`
DEFAULT_LIBEXEC_DIR="$bin"/../libexec
HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
. $HADOOP_LIBEXEC_DIR/yarn-config.sh
"$bin"/yarn-daemon.sh --config $YARN_CONF_DIR start resourcemanager
"$bin"/yarn-daemons.sh --config $YARN_CONF_DIR start nodemanager
[yinzhengjie@s101 ~]$
其实用法跟上面的类似,单独启动进程如下:
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ yarn-daemon.sh start nodemanager
starting nodemanager, logging to /soft/hadoop-2.7./logs/yarn-yinzhengjie-nodemanager-s101.out
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
NodeManager
Jps
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ yarn-daemon.sh start nodemanager
如果想要想要批量启动的,实操如下:
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
命令执行成功
============= s102 jps ============
Jps
命令执行成功
============= s103 jps ============
Jps
命令执行成功
============= s104 jps ============
Jps
命令执行成功
[yinzhengjie@s101 ~]$ yarn-daemons.sh start nodemanager
s102: starting nodemanager, logging to /soft/hadoop-2.7./logs/yarn-yinzhengjie-nodemanager-s102.out
s104: starting nodemanager, logging to /soft/hadoop-2.7./logs/yarn-yinzhengjie-nodemanager-s104.out
s103: starting nodemanager, logging to /soft/hadoop-2.7./logs/yarn-yinzhengjie-nodemanager-s103.out
[yinzhengjie@s101 ~]$ xcall.sh jps
============= s101 jps ============
Jps
命令执行成功
============= s102 jps ============
Jps
NodeManager
命令执行成功
============= s103 jps ============
Jps
NodeManager
命令执行成功
============= s104 jps ============
Jps
NodeManager
命令执行成功
[yinzhengjie@s101 ~]$
[yinzhengjie@s101 ~]$ yarn-daemons.sh start nodemanager
二.stop-all.sh脚本分析
[yinzhengjie@s101 ~]$ cat `which stop-all.sh` | grep -v ^# | grep -v ^$
echo "This script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh"
bin=`dirname "${BASH_SOURCE-$0}"`
bin=`cd "$bin"; pwd`
DEFAULT_LIBEXEC_DIR="$bin"/../libexec
HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
. $HADOOP_LIBEXEC_DIR/hadoop-config.sh
if [ -f "${HADOOP_HDFS_HOME}"/sbin/stop-dfs.sh ]; then
"${HADOOP_HDFS_HOME}"/sbin/stop-dfs.sh --config $HADOOP_CONF_DIR
fi
if [ -f "${HADOOP_HDFS_HOME}"/sbin/stop-yarn.sh ]; then
"${HADOOP_HDFS_HOME}"/sbin/stop-yarn.sh --config $HADOOP_CONF_DIR
fi
[yinzhengjie@s101 ~]$
看到第一行时:echo "This script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh",估计你已经明白是怎么回事了把,就是把上面的所有start参数换成了stop参数。从这个脚本中的第一行我们可以看出来,这个脚本已经过时了,取而代之的是:“This script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh”,也就是 “stop-dfs.sh”和“stop-yarn.sh”。
三.小结
综上所述,我们可以得到以下四个等式:
1>.start-all.sh = start-dfs.sh + start-yarn.sh
2>.stop-all.sh = stop-dfs.sh + stop-yarn.sh
3>.hadoop-damons.sh = hadoop-damon.sh + slaves
4>.yarn-damons.sh = yarn-damon.sh + slaves
Hadoop启动脚本分析的更多相关文章
-
4. hadoop启动脚本分析
4. hadoop启动脚本分析 1. hadoop的端口 ``` 50070 //namenode http port 50075 //datanode http port 50090 //2name ...
-
hadoop启动脚本分析及常见命令
进程------------------ [hdfs]start-dfs.sh NameNode NN DataNode DN SecondaryNamenode 2NN [yarn]start-ya ...
-
Hadoop 启动脚本分析与实战经验
start-all.sh脚本现在已经废弃,推荐使用start-dfs.sh和start-yarn.sh分别启动HDFS和YARN. 在新一代的Hadoop里面HDFS称为了统一存储的平台,而YARN成 ...
-
HBase配置&;启动脚本分析
本文档基于hbase-0.96.1.1-cdh5.0.2,对HBase配置&启动脚本进行分析 date:2016/8/4 author:wangxl HBase配置&启动脚本分析 剔除 ...
-
Spark配置&;启动脚本分析
本文档基于Spark2.0,对spark启动脚本进行分析. date:2016/8/3 author:wangxl Spark配置&启动脚本分析 我们主要关注3类文件,配置文件,启动脚本文件以 ...
-
hadoop启动脚本
记录一下一个简单的hadoop启动脚本 就是启动zookeeper集群,hadoop的HDFS和YRAN的脚本 start-cluster.sh 关于关闭的脚本,只需要顺序换一下,然后将start改为 ...
-
busybox rootfs 启动脚本分析(二)
上次分析了busybox的启动脚本,这次分析一下init.d中一些脚本的内容. 参考链接 http://www.cnblogs.com/helloworldtoyou/p/6169678.html h ...
-
busybox rootfs 启动脚本分析(一)
imx6文件系统启动脚本分析.开机运行/sbin/init,读取/etc/inittab文件,进行初始化. 参考链接 http://blog.163.com/wghbeyond@126/blog/st ...
-
Hadoop 2.0+YARN启动脚本分析与实战经验
start-all.sh脚本现在已经废弃,推荐使用start-dfs.sh和start-yarn.sh分别启动HDFS和YARN. 在新一代的Hadoop里面HDFS称为了统一存储的平台,而YARN成 ...
随机推荐
-
chrome下input[type=text]的placeholder不垂直居中的问题解决
http://blog.csdn.net/do_it__/article/details/6789699 <input type="text" placeholder=&qu ...
-
[python] 线程
来源:田飞雨 链接:http://www.jianshu.com/p/12cd213a93bf 虽然python中由于GIL的机制致使多线程不能利用机器多核的特性,但是多线程对于我们理解并发模型以及底 ...
-
HDOJ-三部曲-1015-The Cow Lexicon
The Cow Lexicon Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
-
algorithm之改变序列算法--待解决
简述:改变序列算法,参见http://www.cplusplus.com/reference/algorithm/?kw=algorithm 待解决问题:iterator_traits.std::mo ...
-
【iOS开发-48】九宫格布局案例:自己主动布局、字典转模型运用、id和instancetype差别、xib反复视图运用及与nib关系
本次九宫格案例: (1)导入app.plist和各种图片素材,方便兴许开发.实际开发中,也是如此. (2)把plist中数组导入进来. --由于本案例中app.plist终于是一个数组,数组里面是字典 ...
-
Maven - Maven基础
1-下载及安装 1.1 - Maven - 项目管理利器 http://maven.apache.org/ Apache组织的开源项目. Maven是一个基于POM(Project Object Mo ...
-
An owner of this repository has limited the ability to open a pull request to users that are collaborators on this repository.
git 无法发起:pull request,提示:An owner of this repository has limited the ability to open a pull request ...
-
web.xml 设置字符编码
个人理解 就是为了防止在前端输入的数据到了后台发生乱码 直接复制到web.xml里面就可以使用 亲测 能用!!! <!-- 前端过滤器设置字符编码 --> <filter> ...
-
SVN设置全局忽略提交文件或者目录
在目录中右击选择TortoiseSVN -> 设置 -> 常规设置 -> 全局忽略样式 修改全局忽略样式(可以设置忽略的文件或者目录,以空格隔开):*.o *.lo *.la *.a ...
-
12个非常有用的JavaScript技巧
在这篇文章中,我将分享12个非常有用的JavaScript技巧.这些技巧可以帮助你减少并优化代码. 1) 使用!!将变量转换成布尔类型 有时,我们需要检查一些变量是否存在,或者它是否具有有效值,从而将 ...