Hadoop: Hive Instalasi

From OnnoWiki
Revision as of 08:10, 14 November 2015 by Onnowpurbo (talk | contribs)
Jump to navigation Jump to search

Sumber: http://doctuts.readthedocs.org/en/latest/hive.html


Sumber

URL

http://apache.claz.org/hive/stable/

Sebagai user biasa. Download & Extract

wget http://apache.claz.org/hive/stable/apache-hive-1.2.1-bin.tar.gz
tar zxvf apache-hive-1.2.1-bin.tar.gz
sudo mkdir /usr/lib/hive
sudo mv apache-hive-1.2.1-bin /usr/lib/hive

SETTING Hive environment variable

cd
sudo gedit  ~/.bashrc

Copy paste kalimat ini di bagian bawah file .bashrc

# Set HIVE_HOME
export HIVE_HOME="/usr/lib/hive/apache-hive-1.2.1-bin"
PATH=$PATH:$HIVE_HOME/bin
export PATH

==SETTING HADOOP_PATH di HIVE config.sh


cd  /usr/lib/hive/apache-hive-1.2.1-bin/bin
sudo gedit hive-config.sh

Go to the line where the following statements are written

# Allow alternate conf dir location.
HIVE_CONF_DIR="${HIVE_CONF_DIR:-$HIVE_HOME/conf"
export HIVE_CONF_DIR=$HIVE_CONF_DIR
export HIVE_AUX_JARS_PATH=$HIVE_AUX_JARS_PATH

Below this write the following

export HADOOP_HOME=/usr/local/hadoop    (write the path where hadoop file is there)

Create Hive directories within HDFS

Command

user@ubuntu:~$ hadoop fs -mkdir /usr/hive/warehouse

Setting READ/WRITE permission for table

Command

user@ubuntu:~$ hadoop fs -chmod g+w /usr/hive/warehouse

HIVE launch

Command

user@ubuntu:~$ hive

Hive shell will prompt: OUTPUT

Shell will look like

Logging initialized using configuration in jar:file:/usr/lib/hive/apache-hive-0.13.0-bin/lib/hive- common-0.13.0.jar!/hive-log4j.properties hive>

Creating a database

Command

hive> create database mydb;

OUTPUT

OK Time taken: 0.369 seconds hive>

Configuring hive-site.xml:

Open with text-editor and change the following property

<property>
    <name>hive.metastore.local</name>
    <value>TRUE</value>
    <description>controls whether to connect to remove metastore server or open a new metastore server in Hive Client JVM</description>
</property>

<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://usr/lib/hive/apache-hive-0.13.0-bin/metastore_db? createDatabaseIfNotExist=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
</property>

<property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    <description>Driver class name for a JDBC metastore</description>
</property>

<property>
    <name>hive.metastore.warehouse.dir</name>
    <value>/usr/hive/warehouse</value>
    <description>location of default database for the warehouse</description>
 </property>

Writing a Script

Open a new terminal (CTRL+ALT+T)

user@ubuntu:~$ sudo gedit sample.sql

create database sample; use sample; create table product(product int, productname string, price float)[row format delimited fields terminated by ',';] describe product;

load data local inpath ‘/home/hduser/input_to_product.txt’ into table product

select * from product;

SAVE and CLOSE

user@ubuntu:~$ sudo gedit input_to_product.txt user@ubuntu:~$ cd /usr/lib/hive/apache-hive-0.13.0-bin/ $ bin/hive -f /home/hduser/sample.sql





Referensi