﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-笔记-随笔分类-大数据</title><link>http://www.blogjava.net/yuxh/category/55178.html</link><description>way</description><language>zh-cn</language><lastBuildDate>Wed, 29 Mar 2017 08:24:07 GMT</lastBuildDate><pubDate>Wed, 29 Mar 2017 08:24:07 GMT</pubDate><ttl>60</ttl><item><title>Hive2.1源码分析(一）启动脚本</title><link>http://www.blogjava.net/yuxh/archive/2017/03/29/432418.html</link><dc:creator>yuxh</dc:creator><author>yuxh</author><pubDate>Wed, 29 Mar 2017 08:01:00 GMT</pubDate><guid>http://www.blogjava.net/yuxh/archive/2017/03/29/432418.html</guid><wfw:comment>http://www.blogjava.net/yuxh/comments/432418.html</wfw:comment><comments>http://www.blogjava.net/yuxh/archive/2017/03/29/432418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yuxh/comments/commentRss/432418.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yuxh/services/trackbacks/432418.html</trackback:ping><description><![CDATA[最近在网上看到的相关材料都比较陈旧，也太简略，参看了一下其他人的内容，针对Hive2.1.1做点分享：<br /><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微软雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;">1）下载apache-hive-2.1.1-bin.tar.gz</div><div style="margin: 0px; color: #000000; font-family: mononoki,Helvetica,&quot;Hiragino Sans GB&quot;,微软雅黑,&quot;Microsoft YaHei UI&quot;,SimSun,SimHei,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><p style="margin: 0px;">2）解压缩，下面的命令行如启动报错，请自行查略Hive启动配置</p><div style="margin: 0px;">3）启动<span style="line-height: 1.5;">hiveserver2</span>&nbsp;<span style="line-height: 1.5;">（非必须，使用jdbc访问的时候才使用）<br /><div>bin目录下</div></span></div><div style="margin: 0px;">hive --service hiveserver2 -p10001来启动<span style="line-height: 1.5;">hiveserver2</span>&nbsp;<span style="line-height: 1.5;">服务(默认为10000端口)</span></div><div style="margin: 0px;">nohup hive --service hiverserver2 -p10001可以在后台跑</div><div style="margin: 0px;">4）<span style="line-height: 1.5;">hive脚本运行流程</span><div style="margin: 0px;">bin目录下，使用命令方法为：</div><div style="margin: 0px;"><div>./hive &lt;parameters&gt; --service serviceName &lt;service parameters&gt;</div></div><div style="margin: 0px;">举例：hive --debug :</div><div style="margin: 0px;">&nbsp; &nbsp;查看bin/hive文件</div><div style="margin: 0px;">流程中会判断$1=&#8216;--debug&#8217;则$DEBUG=&#8216;--debug&#8217;</div><div style="margin: 0px;">&nbsp;<div style="margin: 0px;">if [ "$DEBUG" ]; then</div><div style="margin: 0px;">&nbsp; if [ "$HELP" ]; then //<span style="line-height: 1.5;">如还有--help，就会执行debug_help方法。</span></div></div></div><div style="margin: 0px;"><div style="margin: 0px;"><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; debug_help</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; exit 0</div><div style="margin: 0px;">&nbsp; else</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; get_debug_params "$DEBUG"</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; export <span style="color: red;">HADOOP_CLIENT_OPTS</span>="$HADOOP_CLIENT_OPTS $HIVE_MAIN_CLIENT_DEBUG_OPTS"//<span style="line-height: 1.5;">设置HIVE_MAIN_CLIENT_DEBUG_OPTS的参数中加入debug相应参数</span></div><div style="margin: 0px;">&nbsp; fi</div><div style="margin: 0px;">fi</div></div><div style="margin: 0px;"></div><div style="margin: 0px;"><div style="margin: 0px;">if [ "$SERVICE" = "" ] ; then</div><div style="margin: 0px;">&nbsp; if [ "$HELP" = "_help" ] ; then</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; SERVICE="help"</div><div style="margin: 0px;">&nbsp; else</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; SERVICE="cli" &nbsp; &nbsp; //默认赋值cli</div><div style="margin: 0px;">&nbsp; fi</div><div style="margin: 0px;">fi</div></div><div style="margin: 0px;">这个shell脚本很多变量应该是在其他sh文件中定义，其中$SERVICE_LIST就是其他很多sh文件的最开始形成的：export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} "</div><div style="margin: 0px;"></div><div style="margin: 0px;"><div style="margin: 0px;">hive脚本最后的<span data-wiz-span="data-wiz-span" style="color: #ff0000;">$TORUN "$@"</span>&nbsp;，默认情况下TORUN其实就是cli,即执行/ext/cli.sh脚本，该脚本中主要是调用/ext/util/execHiveCmd.sh 来执行最后的CliDriver。</div><div style="margin: 0px;">&nbsp;【<span style="line-height: 1.5;">shell脚本中的$*，$@和$#</span><div style="margin: 0px;">举例说：</div><div style="margin: 0px;">脚本名称叫test.sh 入参三个: 1 2 3</div><div style="margin: 0px;">运行test.sh 1 2 3后</div><div style="margin: 0px;">$*为"1 2 3"（一起被引号包住）</div><div style="margin: 0px;">$@为"1" "2" "3"（分别被包住）</div><div style="margin: 0px;">$#为3（参数数量）</div><span data-wiz-span="data-wiz-span">】</span></div><div style="margin: 0px;">即exec $HADOOP jar ${HIVE_LIB}/$JAR<span data-wiz-span="data-wiz-span">&nbsp;$CLASS $HIVE_OPTS "$@" //1<br /></span></div><div style="margin: 0px;">其中:</div><div style="margin: 0px;">$HADOOP=<span style="line-height: 1.5;">$HADOOP_HOME/bin/hadoop</span><span style="line-height: 1.5;">&nbsp;【hive脚本中定义</span><span style="line-height: 1.5;">HADOOP=$HADOOP_HOME/bin/hadoop】</span></div><div style="margin: 0px;">$CLASS=org.apache.hadoop.hive.cli.CliDriver【传入的第一个参数，在cli.sh中有定义】</div><div style="margin: 0px;"></div><div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微软雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;">hadoop脚本（2.7.3为例）中最终会执行：</div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微软雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0px;"># Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; HADOOP_OPTS="$HADOOP_OPTS $<span data-wiz-span="data-wiz-span" style="color: #ff0000;">HADOOP_CLIENT_OPTS</span>"</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; #make sure security appender is turned off</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"</div><div style="margin: 0px;">&nbsp;</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; export CLASSPATH=$CLASSPATH</div><div style="margin: 0px;">&nbsp;&nbsp;&nbsp; exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@" //2</div></div><div style="margin: 0px; color: #000000; font-family: mononoki,Helvetica,&quot;Hiragino Sans GB&quot;,微软雅黑,&quot;Microsoft YaHei UI&quot;,SimSun,SimHei,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">hive的debug参数就是在启动hive脚本时放到HADOOP_OPTS中的</div></div><div style="margin: 0px;"></div><div style="margin: 0px;"><div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微软雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0px;"><div style="margin: 0px;"><div style="margin: 0px;"><div><div style="margin: 0px; color: #000000; font-family: mononoki, Helvetica, 'Hiragino Sans GB', 微软雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0px;"><div style="margin: 0px;"><div style="margin: 0px;">1和2处结合可得到最终的运行命令，查看一下运行结果：ps -ef|grep CliDriver</div></div></div></div></div></div></div></div></div></div><br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">&nbsp;&nbsp;</span><span style="color: #000000; ">/</span><span style="color: #000000; ">usr</span><span style="color: #000000; ">/</span><span style="color: #000000; ">java</span><span style="color: #000000; ">/</span><span style="color: #000000; ">jdk1.</span><span style="color: #000000; ">8</span><span style="color: #000000; ">.0_101</span><span style="color: #000000; ">/</span><span style="color: #000000; ">bin</span><span style="color: #000000; ">/</span><span style="color: #000000; ">java&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Xmx256m&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.net.preferIPv4Stack</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.log.dir</span><span style="color: #000000; ">=</span><span style="color: #000000; ">..&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.log.file</span><span style="color: #000000; ">=</span><span style="color: #000000; ">hadoop.log&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.home.dir</span><span style="color: #000000; ">=</span><span style="color: #000000; ">..&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.id.str</span><span style="color: #000000; ">=</span><span style="color: #000000; ">root&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.root.logger</span><span style="color: #000000; ">=</span><span style="color: #000000; ">INFO,console&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.library.path</span><span style="color: #000000; ">=</span><span style="color: #000000; ">..&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.policy.file</span><span style="color: #000000; ">=</span><span style="color: #000000; ">hadoop</span><span style="color: #000000; ">-</span><span style="color: #000000; ">policy.xml&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.net.preferIPv4Stack</span><span style="color: #000000; ">=</span><span style="color: #0000FF; ">true</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Xmx512m&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dproc_hivecli&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">XX:</span><span style="color: #000000; ">+</span><span style="color: #000000; ">UseParallelGC&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">agentlib:jdwp</span><span style="color: #000000; ">=</span><span style="color: #000000; ">transport</span><span style="color: #000000; ">=</span><span style="color: #000000; ">dt_socket,server</span><span style="color: #000000; ">=</span><span style="color: #000000; ">y,address</span><span style="color: #000000; ">=</span><span style="color: #000000; ">8000</span><span style="color: #000000; ">,suspend</span><span style="color: #000000; ">=</span><span style="color: #000000; ">y&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dlog4j.configurationFile</span><span style="color: #000000; ">=</span><span style="color: #000000; ">hive</span><span style="color: #000000; ">-</span><span style="color: #000000; ">log4j2.properties&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Djava.util.logging.config.file</span><span style="color: #000000; ">=</span><span style="color: #000000; ">..<br />&nbsp;&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">Dhadoop.security.logger</span><span style="color: #000000; ">=</span><span style="color: #000000; ">INFO,NullAppender&nbsp;org.apache.hadoop.util.RunJar </span><span style="color: #000000; "></span><span style="color: #000000; ">/</span><span style="color: #000000; ">yuxh</span><span style="color: #000000; ">/</span><span style="color: #000000; ">app</span><span style="color: #000000; ">/</span><span style="color: #000000; ">apache</span><span style="color: #000000; ">-</span><span style="color: #000000; ">hive</span><span style="color: #000000; ">-</span><span style="color: #000000; ">2</span><span style="color: #000000; ">.</span><span style="color: #000000; ">*/</span><span style="color: #000000; ">lib</span><span style="color: #000000; ">/</span><span style="color: #000000; ">hive</span><span style="color: #000000; ">-</span><span style="color: #000000; ">cli</span><span style="color: #000000; ">-</span><span style="color: #000000; ">2</span><span style="color: #000000; ">.</span><span style="color: #000000; ">*</span><span style="color: #000000;">.jar&nbsp;org.apache.hadoop.hive.cli.CliDriver</span></div></div></div></div></div><img src ="http://www.blogjava.net/yuxh/aggbug/432418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yuxh/" target="_blank">yuxh</a> 2017-03-29 16:01 <a href="http://www.blogjava.net/yuxh/archive/2017/03/29/432418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>