栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

centos下安装hive(单机版)

centos下安装hive(单机版)

说明

1、hive以来与hadoop,所以要服务器上要有hadoop才能安装hive

2、hive需要依赖与mysql,所以需要现有MySQL服务才能安装hive

安装

下载地址

http://archive.apache.org/dist/hive/ 

解压

tar -zxvf /opt/software/apache-hive-3.1.2bin.tar.gz -C /opt/module/ 

修改环境变量

# 新增文件
vim /etc/profile.d/my_env.sh

# 新增内容
#HIVE_HOME 
export HIVE_HOME=/opt/module/hive 
export PATH=$PATH:$HIVE_HOME/bin

刷新环境变量

source /etc/profile.d/my_env.sh

解决冲突

mv $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.jar $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.bak

配置hadoop

vim /etc/profile
# 新增
export HADOOP_HOME=/opt/hadoop/hadoop-3.3.1

初始化元数据库

bin/schematool -dbType derby -initSchema
启动及使用

启动hadoop

sbin/start-all.sh

http://192.168.31.229:9870/explorer.html#/
http://192.168.31.229:8088/cluster

关闭防火墙

#查看状态
firewall-cmd --state
#这个亲测可用
systemctl stop firewalld.service
#开机禁止启动
systemctl disable firewalld.service

启动

bin/hive

报错

Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /tmp/hive. Name node is in safe mode.

原因

hadoop 处在安全模式

解决

## 进入hadoop的bin目录 执行↓
hadoop dfsadmin -safemode leave 

配置hadoop权限

hdfs dfs -chmod -R 777 /
hdfs dfs -chmod -R 777 /tmp

使用hive

-- 此过程比较慢
hive> show databases;
hive> show tables; 
hive> create table test(id int); 
hive> insert into test values(1);
hive> select * from test; 

查看监控日志

cat /tmp/root/hive.log 
hive+MySQL

修改配置文件

# 新增配置文件 
vim $HIVE_HOME/conf/hive-site.xml

新增




    
    
        javax.jdo.option.ConnectionURL
        jdbc:mysql://192.168.1.110:3306/metastore?useSSL=false
    

    
    
        javax.jdo.option.ConnectionDriverName
        com.mysql.jdbc.Driver
    

    
    
        javax.jdo.option.ConnectionUserName
        root
    

    
    
        javax.jdo.option.ConnectionPassword
        123456
    

    
    
        hive.metastore.schema.verification
        false
    

    
    
        hive.metastore.event.db.notification.api.auth
        false
    

    
    
        hive.metastore.warehouse.dir
        /user/hive/warehouse
    
 

在mysql中新增数据源

create database metastore; 

初始化

 schematool -initSchema -dbType mysql verbose

报错

[root@localhost bin]#  schematool -initSchema -dbType mysql verbose
metastore connection URL:	 jdbc:mysql://192.168.1.110:3306/metastore?useSSL=false
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 ***

原因:没有驱动包

解决办法:

下载jar包

mysql-connector-java-5.1.32.jar

放入hive的lib目录下

重新初始化即可

初始化后数据库中增加74张表

启动及使用

启动

bin/hive

使用

hive> show databases; 
hive> show tables; 
hive> create table test (id int); 
hive> insert into test values(1); 
hive> select * from test; 
hive> show databases; 
hive> show tables; 
hive> select * from aa; 
使用元数据服务方式访问hive

修改hive-site.xml

cd /opt/module/hive/conf
vim hive-site.xml
 
 
    hive.metastore.uris 
    thrift://hadoop102:9083 
 

启动metastore

hive --service metastore

启动后重新打开一个会话 启动hive

bin/hive 
使用jdbc访问hive

修改hadoop的配置文件

vim core-site.xml

新增


    hadoop.proxyuser.root.hosts
    *


    hadoop.proxyuser.root.groups
    *


如果不配置应该是无法用java访问

修改hive-site.xml

 
 
    hive.server2.thrift.bind.host         
    192.168.1.102 
 

 
 
    hive.server2.thrift.port 
    10000 



启动server2

hive --service metastore
bin/hive --service hiveserver2

# 后台启动

nohub hive --service metastore &
nohub bin/hive --service hiveserver2 &

启动beeline

bin/beeline -u jdbc:hive2://192.168.1.102:10000 -n root 

进入客户端

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/728696.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号