手机版
你好,游客 登录 注册
背景:
阅读新闻

Hadoop相关启动脚本分析

[日期:2012-03-18] 来源:Linux社区  作者:dinosoft [字体:大 中 小]

资料:

  1. ${parameter/pattern/string}  
  2.     The pattern is expanded to produce a pattern just as in filename expansion. Parameter is expanded and the longest match of  
  3. pattern against its value is replaced with string. If pattern begins with ‘/’, all matches of pattern are replaced with string.   
  4. Normally only the first match is replaced. If pattern begins with ‘#’, it must match at the beginning of the expanded value of  
  5. parameter. If pattern begins with ‘%’, it must match at the end of the expanded value of parameter. If string is null, matches of  
  6. pattern are deleted and the / following pattern may be omitted. If parameter is ‘@’ or ‘*’, the substitution operation is   
  7. applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable  
  8. subscripted with ‘@’ or ‘*’, the substitution operation is applied to each member of the array in turn, and the expansion is   
  9. the resultant list.   
  10.   
  11. Bash supports the $"..." quoting syntax to do locale-specific translation of the characters between the double quotes.   

疑问这里能解开我之前的一个疑惑:master怎么去启动slaves的。

原来是通过ssh命令微笑

Hadoop-config.sh

  1. # resolve links - $0 may be a softlink  
  2.   
  3. this="$0"  
  4.   
  5. while [ -h "$this" ]; do  
  6.   ls=`ls -ld "$this"`  
  7.   link=`expr "$ls" : '.*-> \(.*\)$'`  
  8.   if expr "$link" : '.*/.*' > /dev/null; then  
  9.     this="$link"  
  10.   else  
  11.     this=`dirname "$this"`/"$link"  
  12.   fi  
  13. done  
取个绝对地址也搞得这么蛋疼。取出链接 -> 后面的部分。如果带有/就是绝对路径链接?不对吧??惊恐不然就是相对链接,需要拼装上当前目录。

果然是bug。https://issues.apache.org/jira/browse/HADOOP-7089 我用的是0.20.203版本。可以看看fix好的版本

  1. # Resolve links ($0 may be a softlink) and convert a relative path  
  2. # to an absolute path.  NB: The -P option requires bash built-ins  
  3. # or POSIX:2001 compliant cd and pwd.  
  4. this="${BASH_SOURCE-$0}"  
  5. common_bin=$(cd -P -- "$(dirname -- "$this")" && pwd -P)  
  6. script="$(basename -- "$this")"  
  7. this="$common_bin/$script"  
奇怪,在gnu的manual没到${BASH_SOURCE-$0} 这种 Shell Parameter Expansion,这里才有 http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02 坑爹啊抓狂

--  的作用是表示参数接收已结束 http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap01.html#tag_01_11  

也就是说,比如

grep -- -v file
-v是内容,不是grep的参数了。


man pwd ,找到

-P, --physical
              avoid all symlinks


hadoop

  1. exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $HADOOP_OPTS -classpath "$CLASSPATH" $CLASS "$@"  

最终启动java class

相关阅读:

Hadoop datanode启动失败:Hadoop安装目录权限的问题 http://www.linuxidc.com/Linux/2011-12/49389.htm
在Eclipse下搭建Hadoop开发环境各种问题的解决 http://www.linuxidc.com/Linux/2012-02/54597.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款