HIVE配置手冊
1)下載hive目前最新版本是hive-0.6.0,但是不支持hadoop-0.21.0,所以需要安裝hadoop-0.20.2或者以下版本
解壓到每臺服務(wù)器的/data/soft
解壓
- root@master:/data/soft# tar zxvf hive-0.6.0.tar.gz
root@master:/data/soft# tar zxvf hive-0.6.0.tar.gz
建立軟連
- root@master:/data/soft# ln -s hive-0.6.0.tar.gz hive
root@master:/data/soft# ln -s hive-0.6.0.tar.gz hive
2)配置hive1.修改bin/hive-config.sh,添加jdk支持
- export JAVA_HOME=/usr/local/jdk
- export HIVE_HOME=/data/soft/hive
- export HADOOP_HOME=/data/soft/hadoop
export JAVA_HOME=/usr/local/jdkexport HIVE_HOME=/data/soft/hiveexport HADOOP_HOME=/data/soft/hadoop
2.在HDFS中創(chuàng )建目錄,并且將其開(kāi)放g+w模式
- root@master:/data/soft#hadoop fs –mkdir /tmp
- root@master:/data/soft#hadoop fs –mkdir /user/hive/warehouse
- root@master:/data/soft#hadoop fs –chmod g+w /tmp
- root@master:/data/soft#hadoop fs –chmod g+w /user/hive/warehouse
root@master:/data/soft#hadoop fs –mkdir /tmproot@master:/data/soft#hadoop fs –mkdir /user/hive/warehouseroot@master:/data/soft#hadoop fs –chmod g+w /tmproot@master:/data/soft#hadoop fs –chmod g+w /user/hive/warehouse
通過(guò)我的試驗,以上創(chuàng )建目錄的步驟是可以省略的,Hive會(huì )自動(dòng)創(chuàng )建需要的目錄
3. 修改conf/hive-default.xml,這個(gè)是hive的關(guān)鍵配置,所以一般不要直接修改,新建hive-site.xml文件,將修改的內容在這個(gè)里面配置。
- <property>
- <name>hive.exec.scratchdir</name>
- <value>/data/work/hive/tmp</value>
- <description>Scratch space for Hive jobs</description>
- </property>
- <property>
- <name>hive.querylog.location</name>
- <value>/data/work/hive/querylog</value>
- </property>
- <property>
- <name>hive.hwi.listen.host</name>
- <value>0.0.0.0</value>
- <description>This is the host address the Hive Web Interface will listen on</description>
- </property>
- <property>
- <name>hive.hwi.listen.port</name>
- <value>9999</value>
- <description>This is the port the Hive Web Interface will listen on</description>
- </property>
<property><name>hive.exec.scratchdir</name><value>/data/work/hive/tmp</value><description>Scratch space for Hive jobs</description></property><property><name>hive.querylog.location</name><value>/data/work/hive/querylog</value></property><property><name>hive.hwi.listen.host</name><value>0.0.0.0</value><description>This is the host address the Hive Web Interface will listen on</description></property><property><name>hive.hwi.listen.port</name><value>9999</value><description>This is the port the Hive Web Interface will listen on</description></property>
3)運行hive - root@master:/data/soft/hive/bin# ./hive
- Hive history file=/tmp/root/hive_job_log_root_201101241057_361521373.txt
- hive>
root@master:/data/soft/hive/bin# ./hiveHive history file=/tmp/root/hive_job_log_root_201101241057_361521373.txthive>
4)測試hive1.創(chuàng )建數據表
- hive> create TABLE pokes( id INT, name string);
- OK
- Time taken: 8.192 seconds
hive> create TABLE pokes( id INT, name string);OKTime taken: 8.192 seconds
默認是使用輸入格式(input format)為text ,分割符號使用^A(ctrl-a).
2.創(chuàng )建分區的數據表
- hive> CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);
- OK
- Time taken: 36.562 seconds
hive> CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);OKTime taken: 36.562 seconds
包含2列和一個(gè)分區列(ds)。分區列是一個(gè)虛擬列。它不是數據自身的一部分,但是它由得到分區,詳細數據加載到里面
3.顯示數據表
hive> SHOW TABLES;
顯示所有的數據表
hive> SHOW TABLES '.*s';
只顯示以's'結尾的數據表
4.查詢(xún)
- hive> select * from pokes;
- OK
- Time taken: 0.505 seconds
hive> select * from pokes;OKTime taken: 0.505 seconds
5.從本地加載數據
- hive> LOAD DATA LOCAL INPATH './examples/files/kv1.txt' OVERWRITE INTO TABLE pokes;
hive> LOAD DATA LOCAL INPATH './examples/files/kv1.txt' OVERWRITE INTO TABLE pokes;
這個(gè)文件位于hive的安裝目錄下,
examples/files/kv1.txt6.從hdfs加載數據
- LOAD DATA INPATH '/jd/files/kv1.txt' OVERWRITE INTO TABLE pokes;
LOAD DATA INPATH '/jd/files/kv1.txt' OVERWRITE INTO TABLE pokes;
去掉
LOCAL ,就是從HDFS加載
關(guān)鍵字
OVERWRITE意味著(zhù),數據表已經(jīng)存在的數據將被刪除。省略OVERWRITE,數據文件將會(huì )添加到原有數據列表里
7. 刪除數據表
- hive> drop table pokes;
- OK
- Time taken: 0.726 seconds
hive> drop table pokes;OKTime taken: 0.726 seconds
5)Heap size設置Hive默認-Xmx4096m
修改hive/bin/ext/util/ execHiveCmd.sh
HADOOP_HEAPSIZE=256
6)啟動(dòng)Hive Thrift Server - hive --service hiveserver
hive --service hiveserver
默認使用10000端口,也可以使用HIVE_PORT來(lái)指定端口
- root@master:/data/soft/hive/bin# ./hive --service hiveserver --help
- usage HIVE_PORT=xxxx ./hive --service hiveserver
- HIVE_PORT : Specify the server port
root@master:/data/soft/hive/bin# ./hive --service hiveserver --helpusage HIVE_PORT=xxxx ./hive --service hiveserverHIVE_PORT : Specify the server port
7)啟動(dòng)hwi
bin/hive --service hwi
取消日志的方式
- nohup bin/hive --service hwi > /dev/null 2> /dev/null &
nohup bin/hive --service hwi > /dev/null 2> /dev/null &
相關(guān)資料
http://wiki.apache.org/hadoop/Hive/GettingStarted
http://wiki.apache.org/hadoop/Hive/LanguageManual