hive2.0单机、伪分布搭建

1. 所需要的环境

Hive 2.0需要以下运行环境: 
Java 1.7以上(强烈建议使用Java 1.8) 
Hadoop 2.X

2. 下载、解压Hive安装包

Hive官网地址: http://hive.apache.org/ 
例如:

wget "http://mirrors.cnnic.cn/apache/hive/hive-2.0.0/apache-hive-2.0.0-bin.tar.gz"
tar -xzvf apache-hive-2.0.0-bin.tar.gz
mv apache-hive-2.0.0-bin /opt/hive-2.0.0

3. 配置环境变量(可选)

将hive-2.0.0/bin添加到path,以方便访问

vi /etc/profile

在末尾添加:

HIVE_HOME=/opt/hive-2.0.0
PATH=$PATH:$HIVE_HOME/bin

4. 启动单机模式

Hive和Hadoop一样,有3种启动模式,分别是单机模式,伪分布模式,分布模式。这里先来说一下单机模式的启动方式。 
集群模式安装在http://blog.csdn.net/lnho2015/article/details/51355511

4.1 修改配置文件

1.hive-env.sh
cp hive-env.sh.template hive-env.sh
在hive-env.sh中添加:
# Set HADOOP_HOME to point to a specific hadoop install directory
export HADOOP_HOME=/opt/hadoop/hadoop-2.7.2
# Hive Configuration Directory can be controlled by
export HIVE_CONF_DIR=/opt/hive/hive-2.1.0/conf

2.hive-site.xml
cd /opt/hive-2.0.0/conf
vi hive-site.xml //也可以用hive-default.xml.template去改,不过这个文件中的配置项太多了

输入以下内容后保存:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
    <name>hive.metastore.warehouse.dir</name>
    <value>/opt/hive-2.0.0/warehouse</value>
    <description>location of default database for the warehouse</description>
</property>
<property>
   <name>javax.jdo.option.ConnectionURL</name>
   <value>jdbc:derby:/opt/hive-2.0.0/metastore_db;create=true</value>
   <description>JDBC connect string for a JDBC metastore</description>
</property>
</configuration>

注意:使用derby存储方式时,运行hive会在当前目录生成一个derby文件和一个metastore_db目录。这种存储方式的弊端是在同一个目录下同时只能有一个hive客户端能使用数据库,如果换一个地址启动hive则不能共享元数据。

如果使用sparksql操作hive表,也要注意在启动hive的当前目录启动。

4.2 初始化数据库

schematool -initSchema -dbType derby


出现以下几行说明初始化成功:

Starting metastore schema initialization to 2.0.0
Initialization script hive-schema-2.0.0.derby.sql
Initialization script completed
schemaTool completed

4.3 启动程序

mkdir -p /opt/hive-2.0.0/warehouse       // 创建元数据存储文件夹
chmod a+rwx /opt/hive-2.0.0/warehouse    // 修改文件权限
hive


如果出现hive>提示符则说明启动成功

5. 常见错误

5.1 运行hive时出现

Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)

错误原因: 
数据库没有初始化,请参照4.2

5.2 使用schematool初始化数据库时出现

Initialization script hive-schema-2.0.0.derby.sql
Error: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
*** schemaTool failed ***

错误原因:数据库文件夹中已经存在一些文件,解决方法就是清空数据库文件夹(也就是前面配置的/opt/hive-2.0.0/metastore_db文件夹

5.3 hive查询异常:Cannot create directory /tmp/hive-root/。。。Name node is in safe mode.

解决办法:关闭安全模式

hadoop dfsadmin -safemode leave 


5.4hive配置遇到的问题( Relative path in absolute URI:${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D)

解决方案如下:
1.
查看hive-site.xml配置,会看到配置值含有"system:java.io.tmpdir"的配置项
2.
新建文件夹/home/grid/hive-0.14.0-bin/iotmp
3.将含有"system:java.io.tmpdir"的配置项的值修改为如上地址
启动hive,成功!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值