Hive安装和配置

Hive简介

(1) hive不支持OLTP处理

(2)Hive 1.2 及之后需要java1.7或更新版本


Hive安装

(1)hive可以安装在任何一个机器上,前提是这个机器必须要有hadoop软件(可以不启动hdfs,yarn等进程),因为Hive需要用到hadoop软件下的一些jar包

(2)hive1.x默认在哪个目录下启动就会在该目录下创建一个目录metastore_db存放用户产生的元数据,这样很不方便使用,会导致每个用户看到不一样的内容,因此可以使用mysql存放元数据


下载链接:

http://mirror.olnevhost.net/pub/apache/hive/


[root@Darren2 local]# tar -zxvf apache-hive-1.2.2-bin.tar.gz

[root@Darren2 apache-hive-1.2.2-bin]# bin/hive


hive> create database testdb;

hive> show databases;

hive> use testdb;

hive> create table t1(c1 int,c2 string)

    > row format delimited

    > fields terminated by ',';


[root@Darren2 hive]# hdfs dfs -ls -R /user/hive/warehouse/

drwxr-xr-x   - root supergroup          0 2017-11-25 14:25 /user/hive/warehouse/testdb.db

drwxr-xr-x   - root supergroup          0 2017-11-25 14:25 /user/hive/warehouse/testdb.db/t1


[root@Darren2 hive]# cat /tmp/t1.data

1,aaa

2,bbb

3,ccc

hive>select * from t1;

1    aaa

2    bbb

3    ccc

hive> select * from t1 where c2 = 'bbb';

2    bbb


hive> select count(*) from t1 group by c1;

Query ID = root_20171125143038_249cc07f-270b-422c-a165-4da49e05e6c7

Total jobs = 1

Launching Job 1 out of 1

Number of reduce tasks not specified. Estimated from input data size: 1

In order to change the average load for a reducer (in bytes):

  set hive.exec.reducers.bytes.per.reducer=<number>

In order to limit the maximum number of reducers:

  set hive.exec.reducers.max=<number>

In order to set a constant number of reducers:

  set mapreduce.job.reduces=<number>

Starting Job = job_1511577448141_0003, Tracking URL =http://Darren2:8088/proxy/application_1511577448141_0003/

Kill Command = /usr/local/hadoop/bin/hadoop job  -kill job_1511577448141_0003

Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1

2017-11-25 14:30:51,203 Stage-1 map = 0%,  reduce = 0%

2017-11-25 14:31:00,747 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 1.52 sec

2017-11-25 14:31:09,057 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 2.86 sec

MapReduce Total cumulative CPU time: 2 seconds 860 msec

Ended Job = job_1511577448141_0003

MapReduce Jobs Launched:

Stage-Stage-1: Map: 1  Reduce: 1   Cumulative CPU: 2.86 sec   HDFS Read: 6747 HDFS Write: 6 SUCCESS

Total MapReduce CPU Time Spent: 2 seconds 860 msec

OK

1

1

1

Time taken: 31.234 seconds, Fetched: 3 row(s)


也可以通过浏览器访问查看job执行的进度:http://192.168.163.102:8088/


元数据存放在mysql中配置方法

创建对应的hive库,启动hive的时候,会在其下生成很多对应的表


(1)创建连接mysql的配置文件hive-site.xml

[root@Darren2 conf]# vim /usr/local/hive-1.2.2/conf/hive-site.xml

<configuration>

<property>

<name>javax.jdo.option.ConnectionURL</name>

<value>jdbc:mysql://localhos:3306/hive?create=true</value>

</property>

<property>

<name>javax.jdo.option.ConnectionDriverName</name>

<value>com.mysql.jdbc.Driver</value>

</property>

<property>

<name>javax.jdo.option.ConnectionUserName</name>

<value>root</value>

</property>

<property>

<name>javax.jdo.option.ConnectionPassword</name>

<value>147258</value>

</property>

</configyration>


(2)下载java连接mysql的驱动mysql-connector-java-5.1.45.tar.gz

https://dev.mysql.com/downloads/file/?id=474257

解压之后把jar包mysql-connector-java-5.1.45-bin.jar放在hive-1.2.2/lib目录下


(3)在mysql创建hive库

root@localhost [(none)]>create database hive;


(4)测试

[root@Darren2 conf]# cd /usr/local/hive-1.2.2/bin/

[root@Darren2 bin]# ./hive


使用beeline客户端连接hiveserver2的方法

在一个节点上启动hiveserver2服务,可以查看是否监听到10000这个端口来判断是否能启动成功,然后在另外一个节点上使用beeline客户端连接hiveserver2,用户使用root,密码无


#启动hiveserver2

[root@Darren2 bin]# ./hiveserver2


#使用另一个节点连接:

[root@Darren2 bin]# ./beeline

beeline> !connect jdbc:hive2://192.168.163.102:10000

Connecting to jdbc:hive2://192.168.163.102:10000

Enter username for jdbc:hive2://192.168.163.102:10000: root

Enter password for jdbc:hive2://192.168.163.102:10000:

Connected to: Apache Hive (version 1.2.2)

Driver: Hive JDBC (version 1.2.2)

Transaction isolation: TRANSACTION_REPEATABLE_READ

0: jdbc:hive2://192.168.163.102:10000> show databases;

+----------------+--+

| database_name  |

+----------------+--+

| default        |

| testdb1        |

| testdb2        |

+----------------+--+



本文转自 Darren_Chen 51CTO博客,原文链接:http://blog.51cto.com/darrenmemos/2065773,如需转载请自行联系原作者
上一篇:Android 数据绑定之: RecyclerView


下一篇:HIVE之 Sqoop 1.4.6 安装、hive与oracle表互导