Hive安装

Hive安装

hive是基于Hadoop的一个数据仓库工具,用来进行数据提取、转化、加载,这是一种可以存储、查询和分析存储在Hadoop中的大规模数据的机制。hive数据仓库工具能将结构化的数据文件映射为一张数据库表,并提供SQL查询功能,能将SQL语句转变成MapReduce任务来执行。Hive的优点是学习成本低,可以通过类似SQL语句实现快速MapReduce统计,使MapReduce变得更加简单,而不必开发专门的MapReduce应用程序。hive十分适合对数据仓库进行统计分析。

准备

hive下载地址:https://hive.apache.org/downloads.html

我选择下载的是2.3.8,及用于Hadoop2.xy

[jdes@wangjing jdes]$ tar zxvf apache-hive-2.3.8-bin.tar.gz 

添加环境变量

hive是基于hadoop运行的所已要先装配成功hadoop

hadoop安装:https://blog.csdn.net/qq_44769485/article/details/114270920

再/etc/profile下配置环境变量

[jdes@wangjing ~]$ vim /etc/profile
export HIVE_HOME=/home/jdes/hive-2.3.8  #你自己的安装路径
export PATH=$PATH:$HIVE_HOME/bin

将数据库设置为mysql

hive是通过jdbc连接数据库的,默认数据库并不是mysql,所以治理要添加一下配置

  • 首先赋值默认配置模板,默认的模板是不被使用的

    [jdes@wangjing conf]$ cp hive-default.xml.template hive-site.xml
    
  • 打开配置文件最后一行

    [jdes@wangjing conf]$ vim hive-site.xml
    在文件的最下面(</configuration>上面)配置,否则不起效
    shift+g跳到最后一行
    
  • 添加配置

    <!--jdbc连接部分-->
    <property>
    	<name>javax.jdo.option.ConnectionUserName</name>
    	<value>你的mysql数据库用户名</value>
    </property>
    
    <property>
    	<name>javax.jdo.option.ConnectionPassword</name>
    	<value>你的mysql数据库密码</value>
    </property>
    
    <property>
    	<name>javax.jdo.option.ConnectionURL</name>
    	<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
    </property>
    
    <property>
    	<name>javax.jdo.option.ConnectionDriverName</name>
    	<value>com.mysql.jdbc.Driver</value>
    </property>
    <!--jdbc连接部分-->
    
  • 修改配置文件2

    在hive-site.xml文件夹中加入如下代码块(也可以全局替换)

    <property>
        <name>system:java.io.tmpdir</name>
        <value>/usr/local/apache-hive-2.3.8-bin/tmp</value>这个是你自己建立的目录,需要自己建在hive下面
     </property>
    

启动

先检验一下

[jdes@wangjing apache-hive-2.3.8-bin]$ cd bin/
[jdes@wangjing bin]$ ./schematool -dbType mysql -initSchema

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/jdes/apache-hive-2.3.8-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/jdes/hadoop-2.7.1/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL:	 jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver :	 com.mysql.jdbc.Driver
Metastore connection User:	 root
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to load driver
Underlying cause: java.lang.ClassNotFoundException : com.mysql.jdbc.Driver
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

启动hive

[jdes@wangjing bin]$ ./hive

which: no hbase in (/home/jdes/hadoop-2.7.1/bin:.:/usr/java/jdk1.8.0_121/bin:/home/jdes/hadoop-2.7.1/bin:.:/usr/java/jdk1.8.0_121/bin:/home/jdes/hadoop-2.7.1/bin:.:/usr/java/jdk1.8.0_121/bin:/usr/java/jdk1.8.0_121/bin:.:/usr/java/jdk1.8.0_121/bin:/home/jdes/hadoop-2.7.1/bin:.:/usr/java/jdk1.8.0_121/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/hive/bin:/home/jdes/hive-2.7.1/bin:/home/jdes/hive-2.3.8/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/jdes/hive-2.3.8/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/jdes/hadoop-2.7.1/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in jar:file:/home/jdes/hive-2.3.8/lib/hive-common-2.3.8.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> 

这时我们show databases;会出先问题

hive> show databases;
OK
Failed with exception java.io.IOException:java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:user.name%7D
Time taken: 2.867 seconds
  • 解决方法:

    执行替换命令,修改hive-site.xml文件

    [jdes@wangjing conf]$ sed -i "s/system.user.name/user.name/g" `grep system.user.name -rl hive-site.xml`
    

再启动并输入show databases;

[jdes@wangjing conf]$ ./hive
which: no hbase in (/usr/local/hadoop-2.7.1/bin:/usr/local/jdk1.8.0_281/bin:/usr/local/jdk1.8.0_281/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive-2.3.8/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop-2.7.1/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in jar:file:/usr/local/hive-2.3.8/lib/hive-common-2.3.8.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> show databases;
OK
default
Time taken: 2.849 seconds, Fetched: 1 row(s)
hive>

完成!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

善良的牙膏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值