Hive是基於Hadoop構建的壹套數據倉庫分析系統,它提供了豐富的SQL查詢方式來分析存儲在hadoop?分布式文件系統中的數據。其在Hadoop的架構體系中承擔了壹個SQL解析的過程,它提供了對外的入口來獲取用戶的指令然後對指令進行分析,解析出壹個MapReduce程序組成可執行計劃,並按照該計劃生成對應的MapReduce任務提交給Hadoop集群處理,獲取最終的結果。元數據——如表模式——存儲在名為metastore的數據庫中。
系統環境ip地址1?hadoop-master
ip地址2 hadoop-slave
MySQL安裝在master機器上,hive服務器也安裝在master上
Hive下載下載源碼包,最新版本可自行去官網下載
[hadoop@hadoop-master?~]$?wget?hive的下載地址[hadoop@hadoop-master?~]$?tar?-zxf?apache-hive-1.2.1-bin.tar.gz?
[hadoop@hadoop-master?~]$?ls
apache-hive-1.2.1-bin?apache-hive-1.2.1-bin.tar.gz?dfs?hadoop-2.7.1?Hsource?tmp12341234配置環境變量[root@hadoop-master?hadoop]#?vi?/etc/profile
HIVE_HOME=/home/hadoop/apache-hive-1.2.1-bin
PATH=$PATH:$HIVE_HOME/bin
export?HIVE_NAME?PATHMetastore
metastore是hive元數據集中存放地。它包括兩部分:服務和後臺數據存儲。有三種方式配置metastore:內嵌metastore、本地metastore以及遠程metastore。?
本次搭建中采用MySQL作為遠程倉庫,部署在hadoop-master節點上,hive服務端也安裝在hive-master上,hive客戶端即hadoop-slave訪問hive服務器。
創建Hive用戶mysql>CREATE?USER?'hive'?IDENTIFIED?BY?'hive';mysql>GRANT?ALL?PRIVILEGES?ON?*.*?TO?'hive'@'hadoop-master'?WITH?GRANT?OPTION;
mysql>flush?privileges;123123Hive用戶登錄[hadoop@hadoop-master?~]mysql?-h?hadoop-master?-uhive
mysql>set?password?=?password('hive');1212創建Hive數據庫mysql>create?database?hive;配置Hive
修改配置文件?
進入到hive的配置文件目錄下,找到hive-default.xml.template,cp份為hive-default.xml?
另創建hive-site.xml並添加參數
[hadoop@hadoop-master?conf]$?pwd/home/hadoop/apache-hive-1.2.1-bin/conf
[hadoop@hadoop-master?conf]$?vi?hive-site.xml
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop-master:3306/hive?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>javax.jdo.option.ConnectionUserName</name>
<value>hive<value>
<description>username?to?use?against?metastore?database</description>
</property>
<property>?
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password?to?use?against?metastore?database</description>?
</property>?
</configuration>Hive客戶端配置[hadoop@hadoop-master?~]$?scp?-r?apache-hive-1.2.1-bin/?hadoop@hadoop-slave:/home/hadoop
[hadoop@hadoop-slave?conf]$?vi?hive-site.xml
<configuration>
<property>?
<name>hive.metastore.uris</name>?
<value>thrift://hadoop-master:9083</value>?
</property>
</configuration>Hive啟動
要啟動metastore服務
[hadoop@hadoop-master?~]$?hive?--service?metastore?&[hadoop@hadoop-master?~]$?jps
10288?RunJar?#多了壹個進程
9365?NameNode
9670?SecondaryNameNode
11096?Jps
9944?NodeManager
9838?ResourceManager
9471?DataNodeHive服務器端訪問[hadoop@hadoop-master?~]$?hive
Logging?initialized?using?configuration?in?jar:file:/home/hadoop/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive>?show?databases;
OK
default
src
Time?taken:?1.332?seconds,?Fetched:?2?row(s)
hive>?use?src;
OK
Time?taken:?0.037?seconds
hive>?create?table?test1(id?int);
OK
Time?taken:?0.572?seconds
hive>?show?tables;
OK
abc
test
test1
Time?taken:?0.057?seconds,?Fetched:?3?row(s)
hive>Hive客戶端訪問[hadoop@hadoop-slave?conf]$?hive
Logging?initialized?using?configuration?in?jar:file:/home/hadoop/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive>?show?databases;
OK
default
src
Time?taken:?1.022?seconds,?Fetched:?2?row(s)
hive>?use?src;
OK
Time?taken:?0.057?seconds
hive>?show?tables;
OK
abc
test
test1
Time?taken:?0.218?seconds,?Fetched:?3?row(s)
hive>?create?table?test2(id?int?,name?string);
OK
Time?taken:?5.518?seconds
hive>?show?tables;
OK
abc
test
test1
test2
Time?taken:?0.102?seconds,?Fetched:?4?row(s)