免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2321 | 回复: 0
打印 上一主题 下一主题

[Hive] hive 快速安装 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:52 |只看该作者 |倒序浏览
在上一篇hadoop 快速安装的基础上,进行搭建hive。<br><br>Hive 是建立在 Hadoop
上的数据仓库基础构架。它提供了一系列的工具,<br>可以用来进行数据提取转化加载(ETL),这是一种可以存储、<br>查询和分析存储在 Hadoop
中的大规模数据的机制。Hive 定义了简单的<br>类SQL 查询语言,称为 QL,它允许熟悉 SQL 的用户查询数据。同时,<br>这个语言也允许熟悉
MapReduce 开发者的开发自定义的 mapper 和 <br>reducer 来处理内建的 mapper 和 reducer
无法完成的复杂的分析工作。<p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">具体介绍请看:https://cwiki.apache.org/confluence/display/Hive/Home</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">具体架构是:</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><a href="http://blog.chinaunix.net/attachment/201108/17/22270773_1313578885ITTl.jpg" target="_blank" target="_blank"><img src="http://blog.chinaunix.net/attachment/201108/17/22270773_1313578885ITTl.jpg" .load="imgResize(this, 650);" ;="" border="0"></a></p><p>主要分为以下几个部分:</p>
<ul><li>用户接口,包括 CLI,Client,WUI。</li><li>元数据存储,通常是存储在关系数据库如 mysql, derby 中。</li><li>解释器、编译器、优化器、执行器。</li><li>Hadoop:用 HDFS 进行存储,利用 MapReduce 进行计算。</li></ul>
<ol><li>用户接口主要有三个:CLI,Client 和 WUI。其中最常用的是 CLI,Cli 启动的时候,会同时启动一个 Hive
副本。Client 是 Hive 的客户端,用户连接至 Hive Server。在启动 Client 模式的时候,需要指出 Hive
Server 所在节点,并且在该节点启动 Hive Server。 WUI 是通过浏览器访问 Hive。</li><li>Hive 将元数据存储在数据库中,如 mysql、derby。Hive 中的元数据包括表的名字,表的列和分区及其属性,表的属性(是否为外部表等),表的数据所在目录等。</li><li>解释器、编译器、优化器完成 HQL 查询语句从词法分析、语法分析、编译、优化以及查询计划的生成。生成的查询计划存储在 HDFS 中,并在随后有 MapReduce 调用执行。</li><li>Hive 的数据存储在 HDFS 中,大部分的查询由 MapReduce 完成(包含 * 的查询,比如 select * from tbl 不会生成 MapRedcue 任务)。</li></ol>Hive原数据存储格式<br>Hive 将元数据存储在 RDBMS 中,有三种模式可以连接到数据库:<br>1.Single User Mode: 此模式连接到一个 In-memory 的数据库 Derby,一般用于 Unit Test<br><a href="attachment/201108/17/22270773_1313579067PsAS.jpg" target="_blank" target="_blank"><img src="attachment/201108/17/22270773_1313579067PsAS.jpg" .load="imgResize(this, 650);" ;="" border="0"></a><br>2.Multi User Mode:通过网络连接到一个数据库中,是最经常使用到的模式。<br><br><a href="http://blog.chinaunix.net/attachment/201108/17/22270773_1313579136GU6R.jpg" target="_blank" target="_blank"><img src="http://blog.chinaunix.net/attachment/201108/17/22270773_1313579136GU6R.jpg" .load="imgResize(this, 650);" ;="" border="0"></a><br><br><br><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">3.Remote Server Mode:用于非 Java 客户端访问元数据库,在服务器端启动一个 MetaStoreServer,客户端利用 Thrift 协议通过 MetaStoreServer 访问元数据库</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><a href="http://blog.chinaunix.net/attachment/201108/17/22270773_13135792962616.jpg" target="_blank" target="_blank"><img src="http://blog.chinaunix.net/attachment/201108/17/22270773_13135792962616.jpg" .load="imgResize(this, 650);" ;="" border="0"></a></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">在原数据的存储中,本文章使用第二种模式。</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">使用的包有:</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">1.hive-0.6.0.tar.gz&nbsp; 2.mysql-5.5.9-linux2.6-x86_64.tar.gz 3.mysql-connector-java-5.1.11-bin.jar <br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">配置步骤:</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">1.cd /data &amp;&amp; tar -zxvf hive-0.6.0.tar.gz &amp;&amp; mv mysql-connector-java-5.1.11-bin.jar hive-0.6.0/lib</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">2. chown -R hadoop:hadoop hive-0.6.0</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">3. cd /data/hive-0.6.0/conf &amp;&amp; vi&nbsp; hive-site.xml</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">&lt;property&gt;<br>&lt;name&gt;mapred.job.tracker&lt;/name&gt;<br>&lt;value&gt;hadoop-237-13.pconline.ctc:9001&lt;/value&gt; // /etc/hosts文件中已制定这个hostname 对应的ip<br>&lt;description&gt;xxxx&lt;/description&gt;<br>&lt;/property&gt;</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">&lt;property&gt;<br>&lt;name&gt;javax.jdo.option.ConnectionURL&lt;/name&gt;<br>&lt;value&gt;jdbc:mysql://localhost:3306/hiveMetaData?createDatabaseIfNotExist=true&lt;/value&gt;<br>&lt;description&gt;JDBC connect string for a JDBC metastore&lt;/description&gt;<br>&lt;/property&gt;</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br>&nbsp;//以下是配置mysql jdbc的数据源,按需填写<br>&lt;property&gt;<br>&lt;name&gt;javax.jdo.option.ConnectionDriverName&lt;/name&gt;<br>&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;<br>&lt;description&gt;Driver class name for a JDBC metastore&lt;/description&gt;<br>&lt;/property&gt;<br><br>&lt;property&gt;<br>&nbsp; &lt;name&gt;javax.jdo.option.ConnectionUserName&lt;/name&gt;<br>&nbsp; &lt;value&gt;hadoophive&lt;/value&gt;<br>&nbsp; &lt;description&gt;username to use against metastore database&lt;/description&gt;<br>&lt;/property&gt;<br><br>&lt;property&gt;<br>&nbsp; &lt;name&gt;javax.jdo.option.ConnectionPassword&lt;/name&gt;<br>&nbsp; &lt;value&gt;123456&lt;/value&gt;<br>&nbsp; &lt;description&gt;password to use against metastore database&lt;/description&gt;<br>&lt;/property&gt;</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">4.vi hive-log4j.properties</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">&nbsp;&nbsp; 在这里我只配置:hive.log.dir=/data/hive-0.6.0/log //目录需存在<br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">&nbsp;&nbsp; 可以不进行配置,默认为/tmp/${system user}<br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">5. useradd&nbsp; mysql<br></p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">6. cd /data &amp;&amp; tar -zxvf&nbsp; mysql-5.5.9-linux2.6-x86_64.tar.gz &amp;&amp; ln -s /data/mysql-5.5.9-linux2.6-x86_64 /usr/local/mysql</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">7. chown -R mysql:mysql /usr/local/mysql /data/mysql-5.5.9-linux2.6-x86_64</p><p class="p16" style="margin-bottom: 0pt; margin-top: 0pt;">8. 配置/etc/my.cnf</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">9.cd /data/mysql-5.5.9-linux2.6-x86_64/ &amp;&amp; MicrosoftInternetExplorer402DocumentNotSpecified7.8Normal0<span style="font-size: 10.5pt; font-family: 'Times New Roman';">scripts/mysql_install_db&nbsp;--user=mysql</span></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 10.5pt; font-family: 'Times New Roman';">10. /etc/init.d/mtysql.server start</span></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 10.5pt; font-family: 'Times New Roman';">11.bin/mysql -u root //按需修改root密码 这里省略</span></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><span style="font-size: 10.5pt; font-family: 'Times New Roman';">12.</span><span><span> mysql&gt;CREATE&nbsp;USER&nbsp;</span><span class="string">'hadoophive'</span><span>@</span><span class="string">'%'</span><span>&nbsp;IDENTIFIED&nbsp;BY&nbsp;</span><span class="string">'123456'</span><span>;&nbsp; <br></span></span></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><span><span>13. mysql&gt;</span></span><span>GRANT&nbsp;ALL&nbsp;PRIVILEGES&nbsp;ON&nbsp;*.*&nbsp;TO&nbsp;<span class="string">'hadoophive'</span><span>@</span><span class="string">'%'</span></span></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><span><span class="string">到这里你可以启动hive,如果启动后能登陆出现hive&gt;,那安装算告一段落了</span></span></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><span><span class="string">14.cd /data/</span></span>hive-0.6.0/bin &amp;&amp; ./hive --service hiveserver 10000 &gt; /data/hive-0.6.0/logs/stdout_${_time}.log 2&gt; /data/hive-0.6.0/logs/stderr_${_time}.log &amp;</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">15.cd <span><span class="string">/data/</span></span>hive-0.6.0/bin &amp;&amp; ./hive</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">结果如下:<br></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">[hadoop@hadoop-237-13 bin]$ ./hive</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">Hive history file=/tmp/hadoop/hive_job_log_hadoop_201108171926_25725236.txt<br>hive&gt;&nbsp;</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">额外测试:</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">一。创建表<br></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">1.hive&gt;create table test(id INT,name STRING);</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">2.show tables;</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">出现你的表就代表操作成功。</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">二。使用外部数据</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">$HADOOP_HOME/bin/hadoop fs -mkdir /img</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">$HADOOP_HOME/bin/hadoop fs -put access.log /img</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">hive&gt;CREATE EXTERNAL TABLE IMG_ANA(clientIp STRING,tmp1 STRING,tmp2 STRING,time STRING,finename STRING,status STRING,size INT,reffer STRING,useragent STRING,tmp3 STRING,machineip STRING,mastatus STRING,tmp4 INT,tmp5 STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY "|" STORED AS TEXTFILE LOCATION '/img/acchive';</p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;">具体参数语法请查看<strong style="color: rgb(94, 88, 162); font-size: 14px;"><span style="color: rgb(51, 51, 51); font-weight: normal; font-size: 12px;">http://wiki.apache.org/hadoop/Hive/LanguageManual <br></span></strong></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><strong style="color: #5e58a2; font-size: 14px; "><span style="color: #333333; font-weight: normal; font-size: 12px; ">Create Table
CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name
[(col_name data_type [COMMENT col_comment], ...)]
[COMMENT table_comment]
[PARTITIONED BY (col_name data_type
[COMMENT col_comment], ...)]
[CLUSTERED BY (col_name, col_name, ...)
[SORTED BY (col_name [ASC|DESC], ...)]
INTO num_buckets BUCKETS]
[ROW FORMAT row_format]
[STORED AS file_format]
[LOCATION hdfs_path]

</span></strong></p><p><strong style="color: #5e58a2; font-size: 14px; ">CREATE TABLE 创建一个指定名字的表。如果相同名字的表已经存在,则抛出异常;用户可以用 IF NOT EXIST 选项来忽略这个异常。</strong></p><strong style="color: #5e58a2; font-size: 14px; ">
<p>EXTERNAL 关键字可以让用户创建一个外部表,在建表的同时指定一个指向实际数据的路径(LOCATION),Hive
创建内部表时,会将数据移动到数据仓库指向的路径;若创建外部表,仅记录数据所在的路径,不对数据的位置做任何改变。在删除表的时候,内部表的元数据和数
据会被一起删除,而外部表只删除元数据,不删除数据。</p>
<p>LIKE 允许用户复制现有的表结构,但是不复制数据。</p>
<p>用户在建表的时候可以自定义 SerDe 或者使用自带的 SerDe。如果没有指定 ROW FORMAT 或者 ROW FORMAT
DELIMITED,将会使用自带的 SerDe。在建表的时候,用户还需要为表指定列,用户在指定表的列的同时也会指定自定义的 SerDe,Hive
通过 SerDe 确定表的具体的列的数据。</p>
<p>如果文件数据是纯文本,可以使用 STORED AS TEXTFILE。如果数据需要压缩,使用 STORED AS SEQUENCE 。</p>
<p>有分区的表可以在创建的时候使用 PARTITIONED BY
语句。一个表可以拥有一个或者多个分区,每一个分区单独存在一个目录下。而且,表和分区都可以对某个列进行 CLUSTERED BY
操作,将若干个列放入一个桶(bucket)中。也可以利用SORT BY 对数据进行排序。这样可以为特定应用提高性能。</p>
<p>表名和列名不区分大小写,SerDe 和属性名区分大小写。表和列的注释是字符串。</p><p><strong style="color: rgb(94, 88, 162); font-size: 14px;"><span style="color: rgb(51, 51, 51); font-weight: normal; font-size: 12px;">$HADOOP_HOME/bin/hadoop fs -ls /img 能看出</span></strong><strong style="color: #5e58a2; font-size: 14px; "><span style="color: #333333; font-weight: normal; font-size: 12px; ">/img/acchive证明创建成功</span></strong></p><p>再做一次数据导入$HADOOP_HOME/bin/hadoop fs -put access.log /img/acchive</p><p>hive&gt;select * from iIMG_ANA limit 10;返回数据则为成功啦。</p><p><br></p><p>hive搭建很简单,要看看如何使用起来才行<br></p></strong><p></p><p class="p0" style="margin-bottom: 0pt; margin-top: 0pt;"><br></p>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP