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 ...
随机推荐
- 【FastDFS】小伙伴们说在CentOS 8服务器上搭建FastDFS环境总报错?
写在前面 在[冰河技术]微信公众号的[分布式存储]专题中,我们分别搭建了单节点FastDFS环境和高可用FastDFS集群环境.但是,之前的环境都是基于CentOS 6.8服务器进行搭建的.很多小伙伴 ...
- puTTY远程登录时,连接不上
可能接收远程登录的SSH服务没启动 解决办法,控制台输入,service sshd start
- 听我的,看完这30道MySQL基础题再去面试
可以微信搜索公众号「 后端技术学堂 」回复「1024」获取50本计算机电子书,回复「进群」拉你进读者技术交流群,文章每周持续更新,我们下期见! 一个典型的互联网产品架构包含接入层.逻辑处理层以及存储层 ...
- BUU reverse xxor
下载下来的是个elf文件,因为懒得上Linux,直接往IDA里扔, 切到字符串的那个窗口,发现Congratulation!,应该是程序成功执行的表示, 双击,按'x',回车跟入 找到主函数: 1 _ ...
- 性能测试Jmeter安装
一. Jmeter下载地址: http://jmeter.apache.org/download_jmeter.cgi 二. JDK下载地址: https://www.oracle.com/tec ...
- springmvc 源码分析(三) -- 自定义处理器映射器和自定义处理器适配器,以及自定义参数解析器 和错误跳转自定页面
测试环境搭建: 本次搭建是基于springboot来实现的,代码在码云的链接:https://gitee.com/yangxioahui/thymeleaf.git DispatcherServlet ...
- hystrix ,feign,ribbon的超时时间配置,以及原理分析
背景,网上看到很多关于hystrix的配置都是没生效的,如: 一.先看测试环境搭建: order 服务通过feign 的方式调用了product 服务的getProductInfo 接口 //---- ...
- OpenCV中threshold函数的使用
转自:https://blog.csdn.net/u012566751/article/details/77046445 一篇很好的介绍threshold文章: 图像的二值化就是将图像上的像素点的灰度 ...
- ReverseFind的用法 ; 查找字符中最后一个字符
转载:https://blog.csdn.net/frivolousinstant/article/details/52796922 ReverseFind CString::ReverseFind ...
- vscode编写python,引用本地py文件出现红色波浪线
前言 引用本地py文件出现红色波浪线,如下图: 原因 经过查询得知,vscode中的python插件默认使用的是pylint来做代码检查,因此需要对pylint做一些配置 解决方案 在setting. ...