本篇内容介绍了“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=
In order to limit the maximum number of reducers:
set hive.exec.reducers.max=
In order to set a constant number of reducers:
set mapreduce.job.reduces=
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
(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 |
+----------------+--+
“Hive的安装和配置方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
本文名称:Hive的安装和配置方法
链接分享:http://lswzjz.com/article/jieiip.html