How to Install hive?

How to Install hive?

March 12, 2018 0 By Nitikesh Pattanayak

Download hive from : http://www-eu.apache.org/dist/hive/  or http://www-us.apache.org/dist/hive/ 

After download use the below command:

tar zxvf apache-hive-0.14.0-bin.tar.gz

Copy the files to “/usr/local”, so that any user can access hive.

mv apache-hive-0.14.0-bin /usr/local/hive

Setting up environment for Hive:

You can set up the Hive environment by appending the following lines to ~/.bashrc file:

export HIVE_HOME=/usr/local/hive

export PATH=$PATH:$HIVE_HOME/bin

export CLASSPATH=$CLASSPATH:/usr/local/Hadoop/lib/*:.

export CLASSPATH=$CLASSPATH:/usr/local/hive/lib/*:.

 

Configuring Hive:

Commands:

$ cd $HIVE_HOME/conf

$ cp hive-env.sh.template hive-env.sh

Modify the hive-env.sh file by adding  the line:

export HADOOP_HOME=/usr/local/Hadoop

 

Now Hive installation has been done. To store the data from Hive, we need one Data Store. Here we are using Apache Derby for our Data Store.

$ cd ~

$ wget http://archive.apache.org/dist/db/derby/db-derby-10.4.2.0/db-derby-10.4.2.0-bin.tar.gz

$ tar zxvf db-derby-10.4.2.0-bin.tar.gz

$ mv db-derby-10.4.2.0-bin /usr/local/derby

$ export DERBY_HOME=/usr/local/derby

$ export PATH=$PATH:$DERBY_HOME/bin

$ export CLASSPATH=$CLASSPATH:$DERBY_HOME/lib/derby.jar:$DERBY_HOME/lib/derbytools.jar

$ source ~/.bashrc

$ mkdir $DERBY_HOME/data

$ cd $HIVE_HOME/conf

$ cp hive-default.xml.template hive-site.xml

 

Modify hive-site.xml and add the lines between the <configuration> and </configuration> tags:

 

<property>

<name>javax.jdo.option.ConnectionURL</name>

<value>jdbc:derby://localhost:1527/metastore_db;create=true </value>

<description>JDBC connect string for a JDBC metastore </description>

</property>

 

Create a file named jpox.properties and append the following lines into it:

 

javax.jdo.PersistenceManagerFactoryClass = org.jpox.PersistenceManagerFactoryImpl

org.jpox.autoCreateSchema = false

org.jpox.validateTables = false

org.jpox.validateColumns = false

org.jpox.validateConstraints = false

org.jpox.storeManagerType = rdbms

org.jpox.autoCreateSchema = true

org.jpox.autoStartMechanismMode = checked

org.jpox.transactionIsolation = read_committed

javax.jdo.option.DetachAllOnCommit = true

javax.jdo.option.NontransactionalRead = true

javax.jdo.option.ConnectionDriverName = org.apache.derby.jdbc.ClientDriver

javax.jdo.option.ConnectionURL = jdbc:derby://hadoop1:1527/metastore_db;create = true

javax.jdo.option.ConnectionUserName = APP

javax.jdo.option.ConnectionPassword = mine

 

Verifying Hive Installation

Before running Hive, you need to create the /tmp folder and a separate Hive folder in HDFS. Here, we use the /user/hive/warehouse folder. You need to set write permission for these newly created folders as shown below:

chmod g+w

Now set them in HDFS before verifying Hive. Use the following commands:

$ $HADOOP_HOME/bin/hadoop fs -mkdir /tmp 
$ $HADOOP_HOME/bin/hadoop fs -mkdir /user/hive/warehouse
$ $HADOOP_HOME/bin/hadoop fs -chmod g+w /tmp 
$ $HADOOP_HOME/bin/hadoop fs -chmod g+w /user/hive/warehouse

The following commands are used to verify Hive installation:

$ cd $HIVE_HOME
$ bin/hive

On successful installation of Hive, you get to see the following response:

Logging initialized using configuration in jar:file:/home/hadoop/hive-0.9.0/lib/hive-common-0.9.0.jar!/hive-log4j.properties 
Hive history file=/tmp/hadoop/hive_job_log_hadoop_201312121621_1494929084.txt
………………….
hive>

The following sample command is executed to display all the tables:

hive> show tables; 
OK 
Time taken: 2.798 seconds 
hive>