Linux 系统基于 Hadoop 安装 Hive
【注意】安装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
- 将hive的二进制包上传到服务器中并解压到/opt/hive目录下
root@hserver1:~# mkdir /opt/hive
root@hserver1:~# tar zxf apache-hive-2.3.7-bin.tar.gz -C /opt/hive/
- 修改环境变量配置,在/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
- 进入到/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>
- 所以需要根据如上的配置在hadoop中新建一个HDFS目录
$HADOOP_HOME/bin/hadoop fs -mkdir -p /user/hive/warehouse
- 为刚才新建的目录赋予读写权限
$HADOOP_HOME/bin/hadoop fs -chmod 777 /user/hive/warehouse
- 再新建一个/tmp/hive目录并赋予读写权限
$HADOOP_HOME/bin/hadoop fs -mkdir -p /tmp/hive
$HADOOP_HOME/bin/hadoop fs -chmod 777 /tmp/hive
- 检查创建的两个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
- 将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
- 将hive-site.xml文件中的${system:user.name}都替换为root
sed -i 's/${system:user.name}/root/g' hive-site.xml
- hive需要搭配MySQL数据库使用,本文不对MySQL的安装进行说明,可参考其他笔记。安装完成后需要注意MySQL的访问权限配置。
- 安装完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>
- 搜索
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>
- 搜索
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>
- 搜索
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>
- 搜索
hive.metastore.schema.verification
,将对应的value修改为false
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
- 将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
- 将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的元数据库。操作步骤如下:
- 进入hive目录
cd /opt/hive/apache-hive-2.3.7-bin/bin
- 执行如下命令进行初始化
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
- 初始化成功后,可以看到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命令行
- 启动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>
- 启动成功后就进入了hive的命令行模式,首先执行查看函数的命令
hive> show functions;
OK
!
!=
$sum0
%
&
*
+
......
......
xpath_string
year
|
~
Time taken: 7.45 seconds, Fetched: 271 row(s)
- 查看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以服务的方式启动,步骤如下:
- 进去hive的安装路径的 bin 目录下,执行如下命令
nohup ./hiveserver2 &
- 命令执行完成后,服务会默认监听在10000端口
root@hserver1:~# netstat -anplut | grep 10000
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 18935/java
- 在其他机器上可以使用beeline命令远程连接hive数据库(hive安装路径 bin 目录下也带有beeline命令)
beeline -u jdbc:hive2://hserver1:10000/irp_sns_hive -n root
3. 测试新建表和导入数据
- 在hive中新建数据库
hive> create database db_hive_edu;
OK
Time taken: 1.062 seconds
- 创建数据表
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
- 将文件数据写入到表中,首先在操作系统上的/home目录下新建一个名为student.txt的文件,并在文件中添加如下内容(注意,id和name之间是tab键,不是空格,因为在上面创建表的语句中用了terminated by '\t',所以这个文本里id和name的分割必须是用TAB键。行与行之间不能有空格,否则会将NULL导入表中,文件的格式也要使用unix格式):
001 aaron
002 alex
003 tom
004 peter
005 jackson
- 编辑完成后开始导入,在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
- 使用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)
此时可以在namenode的web界面上查看到刚才导入的信息(注意hive使用的HDFS目录是/user/hive/warehouse)
点击表的名字其实就相当于直接访问http://192.168.92.11:50070/explorer.html#/user/hive/warehouse/db_hive_edu.db/student,进入页面后可以看到student.txt这个文件
点击文件的名字可以查看到文件中的信息
进入到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的更多相关文章
- Linux中基于hadoop安装hive(CentOS7+hadoop2.8.0+hive2.1.1)
http://blog.csdn.net/pucao_cug/article/details/71773665
- 基于Linux系统geth的安装
转载地址 https://blog.csdn.net/qq_36124194/article/details/83658580 基于Linux系统geth的安装 安装ethereum sudo apt ...
- Windows10系统下Hadoop和Hive开发环境搭建填坑指南
前提 笔者目前需要搭建数据平台,发现了Windows系统下,Hadoop和Hive等组件的安装和运行存在大量的坑,而本着有坑必填的目标,笔者还是花了几个晚上的下班时候在多个互联网参考资料的帮助下完成了 ...
- linux系统下怎么安装.deb文件
linux系统下怎么安装.deb文件? deb 是 ubuntu .debian 的格式.rpm 是 redhat .fedora .suse 的格式. 他们不通用(虽然可以转换一下). deb是de ...
- linux系统下怎么安装.deb文件?
linux系统下怎么安装.deb文件? deb 是 ubuntu .debian 的格式. rpm 是 redhat .fedora .suse 的格式. 他们不通用(尽管能够转换一下). deb是d ...
- Linux 系统下Eclipse安装及使用
Linux 系统下Eclipse安装及使用 我们在搞上层开发的时候,都是在Windows下使用Eclipse,那么如果是Linux应用开发,就必须要在Linux中安装Eclipse,用于C/C++开发 ...
- Jenkins:VMware虚拟机Linux系统的详细安装和使用教程
jenkins:VMware虚拟机Linux系统的详细安装和使用教程 (一) 不是windows安装虚拟机可跳过 1.Windows安装VMware 2.VMware安装linux系统 3.windo ...
- 【Oracle RAC】Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂)
[Oracle RAC]Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂) 2 Oracle11gR2 RAC数据库安装准备工作2.1 安装环境介绍2.2 数据库安装软件 ...
- 【Oracle RAC】Linux系统Oracle12c RAC安装配置详细记录过程V2.0(图文并茂)
[Oracle RAC]Linux系统Oracle12c RAC安装配置详细过程V2.0(图文并茂) 2 Oracle12c RAC数据库安装准备工作2.1 安装环境介绍2.2 数据库安装软件下载3 ...
随机推荐
- Group Convolution组卷积
思路按照常规卷积到组卷积来. 常规卷积: 如果输入feature map尺寸为C∗H∗W C*H*WC∗H∗W,卷积核有N NN个,输出feature map与卷积核的数量相同也是N NN,每个卷积核 ...
- 普转提Day1
T1 给定一个长度为N的序列,去掉其中连续的一部分使得剩下的部分没有重复元素. 很显然可以发现去掉的一部分只有三种情况:开头.中间.最后. 那么我们只需要枚举Hash就可以了.复杂度O(N^2). 不 ...
- sping cloud入门
可以参考原文 https://www.cnblogs.com/sam-uncle/archive/2018/04/25/8943471.html 注册服务 https://www.cnblogs.co ...
- Python单向链表的实现
链表由一系列不必在内存中相连的结构构成,这些对象按线性顺序排序.每个结构含有表元素和指向后继元素的指针.最后一个单元的指针指向NULL.为了方便链表的删除与插入操作,可以为链表添加一个表头. 删除操作 ...
- const放在函数前后的区别
转载:const放在函数前后的区别 一.const修饰指针 int b = 500; 1.const int * a = & b; 2.int const * a = & b; 3.i ...
- 【题解】SP10570 【LONGCS - Longest Common Substring】
\(\color{Red}{Link}\) \(\text{Solution:}\) 还是\(\text{Suffix Tree.}\) 根据\(\color{Blue}{Link}\)我们可以得到一 ...
- SQL数据库删除和还原的时候提示 被占用 记录一下
设置离线 1)ALTER DATABASE [datebase] SET OFFLINE WITH ROLLBACK IMMEDIATE设置在线 2)ALTER DATABASE [datebase] ...
- 【5】进大厂必须掌握的面试题-Java面试-spring
spring面试问题 Q1.什么是spring? Spring本质上是一个轻量级的集成框架,可用于用Java开发企业应用程序. Q2.命名Spring框架的不同模块. 一些重要的Spring Fram ...
- day19 Pyhton学习 递归函数
# 函数的递归 : 在一个函数的内部调用它自己 # import sys # sys.setrecursionlimit(1000000) # 设置递归的最大深度 # 总结 # 1.递归函数的定义 : ...
- elasticsearch要点及常用查询
目录 elasticsearch要点及常用查询 查询与过滤 明确查询和过滤各自的优缺点,以及适用场景. 性能上的差异 适用场景 1.kibana 中操作es-查询 Mapping映射基础 mappin ...