1 啓動集羣
start-all.sh
2 hive壓縮包解壓縮
tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /usr/local/
3 移動到規劃位置
mv /usr/local/apache-hive-1.2.1-bin/ /usr/local/hive-1.2.1
4 添加環境變量
[root@hadoop02 ~]# vi /etc/profile
追加內容如下:
export HIVE_HOME=/usr/local/hive-1.2.1
export PATH=$PATH:$HIVE_HOME/bin
5 加載環境變量
source /etc/profile
6 查看hive位置(which命令的作用是,在PATH變量指定的路徑中,搜索某個系統命令的位置,並且返回第一個搜索結果)
which hive
7 配置
[root@hadoop02 ~]# vi /usr/local/hive-1.2.1/conf/hive-site.xml
內容如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--指定根目錄-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<!--hive的元數據服務-->
<property>
<name>hive.metastore.uris</name>
<value>thrift://hadoop01:9083</value>
</property>
<!--配置mysql的連接字符串-->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<!--配置mysql的連接驅動-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<!--配置登錄mysql的用戶-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<!--配置登錄mysql的密碼-->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>
</configuration>
8 如果要在其它的服務器安裝hive,並訪問metastore的server,只需要按照上述步驟安裝後,在第7步中,將hive-site.xml配置文件設置爲以下內容
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.uris</name>
<value>thrift://hadoop01:9083</value>
</property>
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<!--hiveserver2的相關屬性配置-->
<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
</property>
</configuration>
9 測試
[root@hadoop02 ~]# hive
Logging initialized using configuration in jar:file:/usr/local/hive-1.2.1/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive> create table test2(a string, b int);
OK
Time taken: 1.241 seconds
hive> show tables;
OK
test
test2
Time taken: 0.23 seconds, Fetched: 2 row(s)
hive> quit;
[root@hadoop02 ~]#