安装配置Hive

1、下载Hive tar并解压

wget http://archive.apache.org/dist/hive/hive-2.1.0/apache-hive-2.1.0-bin.tar.gz

tar -xzf apache-hive-2.1.0-bin.tar.gz

2、配置环境

vi /etc/profile

export HIVE_HOME=/home/edureka/apache-hive-2.1.0-bin
export PATH=$PATH:/home/edureka/apache-hive-2.1.0-bin/bin

source /etc/profile

3、查看Hive版本

hive --version

4、在HDFS上创建Hive目录

hdfs dfs -mkdir -p /user/hive/warehouse

hdfs dfs -mkdir /tmp

5、为表设置读写权限

hdfs dfs -chmod g+w /user/hive/warehouse

hdfs dfs -chmod g+w /tmp

6、在hive-env.sh文件中设置hadoop路径

cd apache-hive-2.1.0-bin/

vi conf/hive-env.sh

export HADOOP_HOME=/usr/local/hadoop
export HADOOP_HEAPSIZE=512
export HIVE_CONF_DIR=/usr/local/hive/conf

7、编辑 hive-site.xml

vi conf/hive-site.xml

 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
 3 Licensed to the Apache Software Foundation (ASF) under one or more
 4 contributor license agreements. See the NOTICE file distributed with
 5 this work for additional information regarding copyright ownership.
 6 The ASF licenses this file to You under the Apache License, Version 2.0
 7 (the "License"); you may not use this file except in compliance with
 8 the License. You may obtain a copy of the License at
 9 
10 http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 -->
18 <configuration>
19 <property>
20 <name>javax.jdo.option.ConnectionURL</name>
21 <value>jdbc:derby:;databaseName=/home/edureka/apache-hive-2.1.0-bin/metastore_db;create=true</value>
22 <description>
23 JDBC connect string for a JDBC metastore.
24 To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
25 For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
26 </description>
27 </property>
28 <property>
29 <name>hive.metastore.warehouse.dir</name>
30 <value>/user/hive/warehouse</value>
31 <description>location of default database for the warehouse</description>
32 </property>
33 <property>
34 <name>hive.metastore.uris</name>
35 <value/>
36 <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
37 </property>
38 <property>
39 <name>javax.jdo.option.ConnectionDriverName</name>
40 <value>org.apache.derby.jdbc.EmbeddedDriver</value>
41 <description>Driver class name for a JDBC metastore</description>
42 </property>
43 <property>
44 <name>javax.jdo.PersistenceManagerFactoryClass</name>
45 <value>org.datanucleus.api.jdo.JDOPersistenceManagerFactory</value>
46 <description>class implementing the jdo persistence</description>
47 </property>
48 </configuration>

8、初始化Derby数据库,Hive默认数据库

bin/schematool -initSchema -dbType derby

9、登录Hive

hive

10、运行几个语句

1 show databases;
2 
3 create table employee (id string, name string, dept string) row format delimited fields terminated by ‘	’ stored as textfile;
4 
5 show tables;
6 
7 LOAD DATA LOCAL INPATH '/srv/ftp/employee.txt' OVERWRITE INTO TABLE employee;
8 
9 select * from employee;

11、退出Hive

exit;

 参考:https://www.edureka.co/blog/apache-hive-installation-on-ubuntu

原文地址:https://www.cnblogs.com/kingshine007/p/8337110.html