Installation and Configuration Explanation Hive

Detailed Since it is, then we can not only know how to install hive, the following basic Speaking from the hive, if you know, then please venue Installation and Configuration

What is the hive

hive installation and configuration

hive test


hive

  Here briefly explain, good configuration hive to help a bit. hadoop hive is built on, of course, only if you build a hive useless wrong. Said simply, if mapreduce call hadoop in DBA-oriented time, then problems will appear, because not everyone works mapreduce DBA can understand, if in order to manage data and need to learn a new technology, from reality life, the company also needs to spend money on more technology coming.

  Joke, hadoop to store data and computing and promotion of technology, and it belongs to the field of data linked to the database, so hadoop and DBA hook is what makes sense, on this basis, we DBA needs to create an appropriate technology.

  It achieved this hive, hive to type SQL statements (HiveQL) to implement the data management under the hadoop. hive belongs to the category of data warehouse, then, databases and data warehouses in the end what is the difference, here briefly explain: The database focuses on OLTP (online transaction processing), data warehousing focus OLAP (online analytical processing); that is to say, for example, mysql the database class is more focused on data processing in a short time, and vice versa.

No hive: user .....-> mapreduce ...-> hadoop data (may need to be mapreduce)

There hive: user ...-> HQL (SQL) -> hive ...-> mapreduce ...-> hadoop data (SQL statement will only need)


 hive installation and configuration

installation

One: Download hive-- Address: http://mirror.bit.edu.cn/apache/hive/

 In hive-2.1.1 here as an example, as shown:

The hive extracted to / usr / local:

[root@s100 local]# tar -zxvf apache-hive-2.1.1-bin.tar.gz -C /usr/local/

Rename the file as a hive file:

[root@s100 local]# mv apache-hive-2.1.1-bin hive

 

Modify environment variables / etc / profile:

[root@s100 local]# vim /etc/profile

 

1 #hive
2 export HIVE_HOME=/usr/local/hive
3 export PATH=$PATH:$HIVE_HOME/bin

Perform source /etc.profile:

Execution hive --version

[root@s100 local]# hive --version

 

 There hive version of the show, the installation was successful!

Configuration

[root@s100 conf]# cd /usr/local/hive/conf/

Modify hive-site.xml:

There is no, we have to copy a template:

[root@s100 conf]# cp hive-default.xml.template hive-site.xml
[root@s100 conf]# vim hive-site.xml 

 

1.配置hive-site.xml(第5点的后面有一个单独的hive-site.xml配置文件,这个如果有疑问可以用后面的配置文件,更容易明白)

主要是mysql的连接信息(在文本的最开始位置)

复制代码
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
–><configuration>
<!– WARNING!!! This file is auto generated for documentation purposes ONLY! –>
<!– WARNING!!! Any changes you make to this file will be ignored by Hive. –>
<!– WARNING!!! You must make your changes in hive-site.xml instead. –>
<!– Hive Execution Parameters –>

    <span style="color: #008000;">&lt;!--</span><span style="color: #008000;"> 插入一下代码 </span><span style="color: #008000;">--&gt;</span>
<span style="color: #0000ff;">&lt;</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;</span>javax.jdo.option.ConnectionUserName<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;用户名(这4是新添加的,记住删除配置文件原有的哦!)</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>root<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>
<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>
<span style="color: #0000ff;">&lt;</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;</span>javax.jdo.option.ConnectionPassword<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;密码</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>123456<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>
<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>

<property>
<name>javax.jdo.option.ConnectionURL</name>mysql
<value>jdbc:mysql://192.168.1.68:3306/hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>mysql驱动程序
<value>com.mysql.jdbc.Driver</value>
</property>
<!– 到此结束代码 –>

<property>
<name>hive.exec.script.wrapper</name>
<value/>
<description/>
</property>

复制代码

2.复制mysql的驱动程序到hive/lib下面(这里已经拷贝好了)

[root@s100 lib]# ll mysql-connector-java-5.1.18-bin.jar 
-rw-r--r-- 1 root root 789885 1月   4 01:43 mysql-connector-java-5.1.18-bin.jar

 

3.在mysql中hive的schema(在此之前需要创建mysql下的hive数据库)

1 [root@s100 bin]# pwd
2 /usr/local/hive/bin
3 [root@s100 bin]# schematool -dbType mysql -initSchema

4.执行hive命令

[root@localhost hive]# hive

成功进入hive界面,hive配置完成

5.查询mysql(hive这个库是在 schematool -dbType mysql -initSchema 之前创建的!)

复制代码
 1 [root@localhost ~]# mysql -uroot -p123456
 2 Welcome to the MySQL monitor.  Commands end with ; or \g.
 3 Your MySQL connection id is 10
 4 Server version: 5.1.73 Source distribution
 5 
 6 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
 7 
 8 Oracle is a registered trademark of Oracle Corporation and/or its
 9 affiliates. Other names may be trademarks of their respective
10 owners.
11 
12 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
13 
14 mysql> use hive
15 Reading table information for completion of table and column names
16 You can turn off this feature to get a quicker startup with -A
17 
18 Database changed
19 mysql> show tables;
20 +---------------------------+
21 | Tables_in_hive            |
22 +---------------------------+
23 | AUX_TABLE                 |
24 | BUCKETING_COLS            |
25 | CDS                       |
26 | COLUMNS_V2                |
27 | COMPACTION_QUEUE          |
28 | COMPLETED_COMPACTIONS     |
复制代码

备注 (这里不计入正文不要重复配置hive-site.xml)

配置文件hive-site.xml

这里不得不说一下,如果你的 schematool -dbType mysql -initSchema 并没有执行成功怎么办,小博主昨天在这卡了一天,最后根据伟大的百度和hive官方文档,直接写了一个hive-site.xml配置文本:

复制代码
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
        <property>
                <name>javax.jdo.option.ConnectionURL</name>
                <value>jdbc:mysql://localhost:3306/hahive</value>(mysql地址localhost)
        </property>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;</span>javax.jdo.option.ConnectionDriverName<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;(mysql的驱动)</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>com.mysql.jdbc.Driver<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>

    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;</span>javax.jdo.option.ConnectionUserName<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;(用户名)</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>root<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>

    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;</span>javax.jdo.option.ConnectionPassword<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;(密码)</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>123456<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>

    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;</span>hive.metastore.schema.verification<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">name</span><span style="color: #0000ff;">&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>false<span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">value</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">property</span><span style="color: #0000ff;">&gt;</span>

</configuration>

复制代码

 

 


 

那我们做这些事干什么的呢,下面小段测试大家感受一下

hive测试:

备注:这里是第二个配置文件的演示:所以数据库名称是hahive数据库!

1.需要知道现在的hadoop中的HDFS存了什么

[root@localhost conf]# hadoop fs -lsr /

2.进入hive并创建一个测试库和测试表

[root@localhost conf]# hive

 创建库:

1 hive> create database hive_1;
2 OK
3 Time taken: 1.432 seconds

 显示库:

1 hive> show databases;
2 OK
3 default
4 hive_1
5 Time taken: 1.25 seconds, Fetched: 2 row(s)

 创建库成功!

3.查询一下HDFS有什么变化

多了一个库hive_1

娜莫喔们的mysql下的hahive库有什么变化

?
1
mysql> use hahive;
?
1
2
3
4
5
6
7
8
mysql> select * from DBS;
+-------+-----------------------+------------------------------------------------+---------+------------+------------+
| DB_ID | DESC                  | DB_LOCATION_URI                                | NAME    | OWNER_NAME | OWNER_TYPE |
+-------+-----------------------+------------------------------------------------+---------+------------+------------+
|     1 | Default Hive database | hdfs: //localhost/user/hive/warehouse           | default | public     | ROLE       |
|     6 | NULL                  | hdfs: //localhost/user/hive/warehouse/hive_1.db | hive_1  | root       | USER       |
+-------+-----------------------+------------------------------------------------+---------+------------+------------+
2 rows in set (0.00 sec)

4.在hive_1下创建一个表hive_01

?
1
2
3
4
5
6
7
8
9
10
11
hive> use hive_1;
OK
Time taken: 0.754 seconds
hive> create table hive_01 (id int ,name string );
OK
Time taken: 2.447 seconds
hive> show tables;
OK
hive_01 (表创建成功)
Time taken: 0.31 seconds, Fetched: 2 row(s)
hive>

HDFS下的情况:

mysql下:

?
1
2
3
4
5
6
7
mysql> select * from TBLS;
+--------+-------------+-------+------------------+-------+-----------+-------+----------+---------------+--------------------+--------------------+
| TBL_ID | CREATE_TIME | DB_ID | LAST_ACCESS_TIME | OWNER | RETENTION | SD_ID | TBL_NAME | TBL_TYPE      | VIEW_EXPANDED_TEXT | VIEW_ORIGINAL_TEXT |
+--------+-------------+-------+------------------+-------+-----------+-------+----------+---------------+--------------------+--------------------+
|      6 |  1514286051 |     6 |                0 | root  |         0 |     6 | hive_01  | MANAGED_TABLE | NULL               | NULL               |
+--------+-------------+-------+------------------+-------+-----------+-------+----------+---------------+--------------------+--------------------+
2 rows in set (0.00 sec)

娜莫在web端是什么样子的呢!

 

总的来说,hive其实就和mysql差不多呢!那么后面就不说了

最后,浏览别人博客的时候都会有版权声明,感觉好6的样子,小博主以后也写一段╭(╯^╰)╮


 版权声明:

本文作者:魁·帝小仙

博文地址:http://www.cnblogs.com/dxxblog/p/8193967.html

欢迎对小博主的博文内容批评指点,如果问题,可评论或邮件联系([email protected]

欢迎转载,转载请在文章页面明显位置给出原文链接,谢谢

 

Guess you like

Origin blog.csdn.net/yimenglin/article/details/90234752