【注意】安装hive前提是要先安装hadoop集群,并且hive只需要在hadoop的namenode节点集群里安装即可(在所有的namenode上安装),可以不在datanode节点的机器上安装。

一、安装和配置Hive

1. 下载Hive

Hive的官方下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.7/apache-hive-2.3.7-bin.tar.gz

2. 安装Hive

  1. 将hive的二进制包上传到服务器中并解压到/opt/hive目录下
root@hserver1:~# mkdir /opt/hive
root@hserver1:~# tar zxf apache-hive-2.3.7-bin.tar.gz -C /opt/hive/
  1. 修改环境变量配置,在/etc/profile文件中添加如下内容
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HADOOP_HOME=/opt/hadoop/hadoop-2.9.2
export HADOOP_CONF_DIR=${HADOOP_HOME}/etc/hadoop
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_HOME}/lib/native
export HADOOP_OPTS="-Djava.library.path=${HADOOP_HOME}/lib"
export HIVE_HOME=/opt/hive/apache-hive-2.3.7-bin
export HIVE_CONF_DIR=${HIVE_HOME}/conf
export CLASS_PATH=.:${JAVA_HOME}/lib:${HIVE_HOME}/lib:$CLASS_PATH
export PATH=.:${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:${HIVE_HOME}/bin:$PATH 

3. 配置Hive

  1. 进入到/opt/hive/apache-hive-2.3.7-bin/conf目录下,将hive-default.xml.template文件复制一份,并且改名为hive-site.xml。在hive-site.xml文件中存在如下一段配置
  <property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
  1. 所以需要根据如上的配置在hadoop中新建一个HDFS目录
$HADOOP_HOME/bin/hadoop fs -mkdir -p /user/hive/warehouse
  1. 为刚才新建的目录赋予读写权限
$HADOOP_HOME/bin/hadoop fs -chmod 777 /user/hive/warehouse
  1. 再新建一个/tmp/hive目录并赋予读写权限
$HADOOP_HOME/bin/hadoop fs -mkdir -p /tmp/hive
$HADOOP_HOME/bin/hadoop fs -chmod 777 /tmp/hive
  1. 检查创建的两个hdfs目录是否创建成功
root@hserver1:/opt/hive/apache-hive-2.3.7-bin/conf# $HADOOP_HOME/bin/hadoop fs -ls /user/hive
Found 1 items
drwxrwxrwx - root supergroup 0 2020-05-07 15:17 /user/hive/warehouse
root@hserver1:/opt/hive/apache-hive-2.3.7-bin/conf# $HADOOP_HOME/bin/hadoop fs -ls /tmp
Found 1 items
drwxrwxrwx - root supergroup 0 2020-05-07 15:42 /tmp/hive
  1. 将hive-site.xml文件中的${system:java.io.tmpdir}替换为hive的临时目录,本文中替换为/opt/hive/tmp,该目录如果不存在则要自己手工创建,并且赋予读写权限。
sed -i 's/${system:java.io.tmpdir}/\/opt\/hive\/tmp/g' hive-site.xml
  1. 将hive-site.xml文件中的${system:user.name}都替换为root
sed -i 's/${system:user.name}/root/g' hive-site.xml
  1. hive需要搭配MySQL数据库使用,本文不对MySQL的安装进行说明,可参考其他笔记。安装完成后需要注意MySQL的访问权限配置。
  2. 安装完MySQL后,需要修改hive-site.xml文件中关于MySQL相关的配置,首先搜索javax.jdo.option.ConnectionURL,将该name对应的value修改为MySQL的地址
  <property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.92.11:3306/hive?createDatabaseIfNotExist=true</value>
</property>
  1. 搜索javax.jdo.option.ConnectionDriverName,将该name对应的value修改为MySQL驱动类路径
  <property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
  1. 搜索javax.jdo.option.ConnectionUserName,将对应的value修改为MySQL数据库登录名
  <property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>Username to use against metastore database</description>
</property>
  1. 搜索javax.jdo.option.ConnectionPassword,将对应的value修改为MySQL数据库登录密码
  <property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
<description>password to use against metastore database</description>
</property>
  1. 搜索hive.metastore.schema.verification,将对应的value修改为false
  <property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
  1. 将hive-env.sh.template文件复制一份,改名为hive-env.sh并且添加如下内容
export HADOOP_HOME=/opt/hadoop/hadoop-2.9.2
export HIVE_CONF_DIR=/opt/hive/apache-hive-2.3.7-bin/conf
export HIVE_AUX_JARS_PATH=/opt/hive/apache-hive-2.3.7-bin/lib
  1. 将MySQL驱动包上传到hive的lib目录下,驱动包下载地址:https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-5.1.41.tar.gz
root@hserver1:/opt/hive/apache-hive-2.3.7-bin/lib# ll mysql-connector-java-5.1.41.jar
-rw-r--r-- 1 root root 992808 May 7 16:19 mysql-connector-java-5.1.41.jar

二、启动Hive并测试

1. 初始化hive数据库

在启动hive之前,首先要将mysql设置为hive的元数据库。操作步骤如下:

  1. 进入hive目录
cd /opt/hive/apache-hive-2.3.7-bin/bin
  1. 执行如下命令进行初始化
root@hserver1:/opt/hive/apache-hive-2.3.7-bin/bin# schematool -initSchema -dbType mysql
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/apache-hive-2.3.7-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/hadoop-2.9.2/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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://192.168.92.11:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Thu May 07 16:31:56 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Thu May 07 16:31:58 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Initialization script completed
Thu May 07 16:32:03 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
schemaTool completed
  1. 初始化成功后,可以看到MySQL数据库的hive库中已经创建了一些表
mysql> show tables;
+---------------------------+
| Tables_in_hive |
+---------------------------+
| AUX_TABLE |
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| COMPACTION_QUEUE |
| COMPLETED_COMPACTIONS |
...
...
| WRITE_SET |
+---------------------------+
57 rows in set (0.01 sec)

2. 启动hive

2.1 启动hive命令行
  1. 启动hive需要进入到hive的bin目录下执行如下命令:
root@hserver1:/opt/hive/apache-hive-2.3.7-bin/bin# ./hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/apache-hive-2.3.7-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/hadoop-2.9.2/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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:/opt/hive/apache-hive-2.3.7-bin/lib/hive-common-2.3.7.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>
  1. 启动成功后就进入了hive的命令行模式,首先执行查看函数的命令
hive> show functions;
OK
!
!=
$sum0
%
&
*
+
......
......
xpath_string
year
|
~
Time taken: 7.45 seconds, Fetched: 271 row(s)
  1. 查看sum函数的详细信息
hive> desc function sum;
OK
sum(x) - Returns the sum of a set of numbers
Time taken: 0.232 seconds, Fetched: 1 row(s)
2.2 以服务的方式启动

上面的启动方式只适用于本地操作hive,如果希望hive启动后,可以在其他机器上远程连接,那么就需要让hive以服务的方式启动,步骤如下:

  1. 进去hive的安装路径的 bin 目录下,执行如下命令
nohup ./hiveserver2 &
  1. 命令执行完成后,服务会默认监听在10000端口
root@hserver1:~# netstat -anplut | grep 10000
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 18935/java
  1. 在其他机器上可以使用beeline命令远程连接hive数据库(hive安装路径 bin 目录下也带有beeline命令)
beeline -u jdbc:hive2://hserver1:10000/irp_sns_hive -n root

3. 测试新建表和导入数据

  1. 在hive中新建数据库
hive> create database db_hive_edu;
OK
Time taken: 1.062 seconds
  1. 创建数据表
hive> create database db_hive_edu;
OK
Time taken: 1.062 seconds
hive> use db_hive_edu;
OK
Time taken: 0.053 seconds
hive> create table student(id int,name string) row format delimited fields terminated by '\t';
OK
Time taken: 1.719 seconds
  1. 将文件数据写入到表中,首先在操作系统上的/home目录下新建一个名为student.txt的文件,并在文件中添加如下内容(注意,id和name之间是tab键,不是空格,因为在上面创建表的语句中用了terminated by '\t',所以这个文本里id和name的分割必须是用TAB键。行与行之间不能有空格,否则会将NULL导入表中,文件的格式也要使用unix格式):
001	aaron
002 alex
003 tom
004 peter
005 jackson
  1. 编辑完成后开始导入,在hive命令行中执行如下命令导入
hive> load data local inpath '/home/student.txt' into table db_hive_edu.student;
Loading data to table db_hive_edu.student
OK
Time taken: 4.403 seconds
  1. 使用select命令查看数据是否写入成功
hive> select * from student;
OK
1 aaron
2 alex
3 tom
4 peter
5 jackson
Time taken: 3.981 seconds, Fetched: 5 row(s)
  1. 此时可以在namenode的web界面上查看到刚才导入的信息(注意hive使用的HDFS目录是/user/hive/warehouse)

  2. 点击表的名字其实就相当于直接访问http://192.168.92.11:50070/explorer.html#/user/hive/warehouse/db_hive_edu.db/student,进入页面后可以看到student.txt这个文件

  3. 点击文件的名字可以查看到文件中的信息

  4. 进入到MySQL数据库中,使用如下语句也可以查询到hive创建表的信息

mysql> select * from TBLS \G
*************************** 1. row ***************************
TBL_ID: 1
CREATE_TIME: 1588841019
DB_ID: 6
LAST_ACCESS_TIME: 0
OWNER: root
RETENTION: 0
SD_ID: 1
TBL_NAME: student
TBL_TYPE: MANAGED_TABLE
VIEW_EXPANDED_TEXT: NULL
VIEW_ORIGINAL_TEXT: NULL
IS_REWRITE_ENABLED:
1 row in set (0.00 sec)

Linux 系统基于 Hadoop 安装 Hive的更多相关文章

  1. Linux中基于hadoop安装hive(CentOS7+hadoop2.8.0+hive2.1.1)

    http://blog.csdn.net/pucao_cug/article/details/71773665

  2. 基于Linux系统geth的安装

    转载地址 https://blog.csdn.net/qq_36124194/article/details/83658580 基于Linux系统geth的安装 安装ethereum sudo apt ...

  3. Windows10系统下Hadoop和Hive开发环境搭建填坑指南

    前提 笔者目前需要搭建数据平台,发现了Windows系统下,Hadoop和Hive等组件的安装和运行存在大量的坑,而本着有坑必填的目标,笔者还是花了几个晚上的下班时候在多个互联网参考资料的帮助下完成了 ...

  4. linux系统下怎么安装.deb文件

    linux系统下怎么安装.deb文件? deb 是 ubuntu .debian 的格式.rpm 是 redhat .fedora .suse 的格式. 他们不通用(虽然可以转换一下). deb是de ...

  5. linux系统下怎么安装.deb文件?

    linux系统下怎么安装.deb文件? deb 是 ubuntu .debian 的格式. rpm 是 redhat .fedora .suse 的格式. 他们不通用(尽管能够转换一下). deb是d ...

  6. Linux 系统下Eclipse安装及使用

    Linux 系统下Eclipse安装及使用 我们在搞上层开发的时候,都是在Windows下使用Eclipse,那么如果是Linux应用开发,就必须要在Linux中安装Eclipse,用于C/C++开发 ...

  7. Jenkins:VMware虚拟机Linux系统的详细安装和使用教程

    jenkins:VMware虚拟机Linux系统的详细安装和使用教程 (一) 不是windows安装虚拟机可跳过 1.Windows安装VMware 2.VMware安装linux系统 3.windo ...

  8. 【Oracle RAC】Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂)

    [Oracle RAC]Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂) 2 Oracle11gR2 RAC数据库安装准备工作2.1 安装环境介绍2.2 数据库安装软件 ...

  9. 【Oracle RAC】Linux系统Oracle12c RAC安装配置详细记录过程V2.0(图文并茂)

    [Oracle RAC]Linux系统Oracle12c RAC安装配置详细过程V2.0(图文并茂) 2 Oracle12c RAC数据库安装准备工作2.1 安装环境介绍2.2 数据库安装软件下载3 ...

随机推荐

  1. Mac鼠标灵敏度调节

    系统的调节到最大还是无法满足你的时候那么你就该看看我接下来的操作了,请看: 查看 首先打开终端,输入一下命令: defaults read -g com.apple.mouse.scaling 此命令 ...

  2. PJzhang:CVE-2020-1472微软NetLogon权限提升漏洞~复现

    猫宁~~~ 虚拟机上进行 安装windows 2008 R2 查看服务器ip 本地连接属性,取消ipv6,ip设置为192.168.43.158,子网掩码255.255.255.0,网关192.168 ...

  3. 软件定义网络实验记录⑤--OpenFlow 协议分析和 OpenDaylight 安装

    一.实验目的 回顾 JDK 安装配置,了解 OpenDaylight 控制的安装,以及 Mininet 如何连接: 通过抓包获取 OpenFlow 协议,验证 OpenFlow 协议和版本,了解协议内 ...

  4. 【字符串算法】AC自动机

    国庆后面两天划水,甚至想接着发出咕咕咕的叫声.咳咳咳,这些都不重要!最近学习了一下AC自动机,发现其实远没有想象中的那么难. AC自动机的来历 我知道,很多人在第一次看到这个东西的时侯是非常兴奋的.( ...

  5. 【题解】[SDOI2016]征途

    Link 题目大意:给定序列,将它划分为\(m\)段使得方差最小,输出\(s^2*m^2\)(一个整数). \(\text{Solution:}\) 这题我通过题解中的大佬博客学到了一般化方差柿子的写 ...

  6. 用C写一个简单的推箱子游戏(一)

    我现在在读大二,我们有一门课程叫<操作系统>,课程考查要求我们可以写一段程序或者写Windows.iOS.Mac的发展历程.后面我结合网上的资料参考,就想用自己之前简单学过的C写一关的推箱 ...

  7. Java防止文件被篡改之文件校验和

    Java防止文件被篡改之文件校验和转载:请注明出处,谢谢! 1.为什么要防止文件被篡改?  答案是显然的,为了保证版权,系统安全性等.之前公司开发一个系统,技术核心是一个科学院院士的研究成果,作为一款 ...

  8. ZooKeeper伪分布式集群安装及使用

    ZooKeeper伪分布式集群安装及使用 让Hadoop跑在云端系列文章,介绍了如何整合虚拟化和Hadoop,让Hadoop集群跑在VPS虚拟主机上,通过云向用户提供存储和计算的服务. 现在硬件越来越 ...

  9. 多Y轴图的尝试

    最近的一篇文章中需要绘制多Y轴图形,Excel只能做双Y轴图,又尝试了Origin,SigmaPlot,Igor等软件,手动做起来相当繁琐,批量做更是觉得费劲,干脆尝试在MeteoInfoLab里实现 ...

  10. golang通过cgo调用lua

    目录 1.前期准备 2.测试go代码 3.完成的一个学习项目 4.总结 1.前期准备 1.第三方库:https://github.com/aarzilli/golua 2.下载lua源码:https: ...