CentOS配置Hive

hive搭建共分爲三種模式:一、embedded,二、local,三、remote serverjava

在這裏,主要是配置第3種模式:remote server模式,以下圖所示:mysql

 

個人環境共三臺虛擬機:Host0,Host2,Host3sql

在remote server模式中,Host0:Hive-server2數據庫

            Host2:Hive-metastoreide

            Host3:MySQL serveroop

一、分別在Host0,Host2和Host3中安裝hive-server2,hive-metastore,mysql-server測試

yum install hive-server2 -y
yum install hive-metastore -y
yum install mysql-server -y 

二、在MySQL server中建立hive數據庫以及hive用戶,並設置hive用戶能夠遠程登陸spa

create database hive;
create user hive identified by '123456';
grant all PRIVILEGES on *.* to hive@’%’ identified by123456’;
flush privileges;

三、在hive-metastore中設置hive配置文件,使其能鏈接到MySQL servercode

  hive配置文件位置:/etc/hive/conf/hive-site.xmlserver

  向hive-site.xml中添加下列內容

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://Host3:3306/hive?characterEncoding=UTF-8</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>
</property>
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>123456</value>
</property>
<property>
  <name>hive.metastore.warehouse.dir</name>
  <!-- base hdfs path -->
  <value>/user/hive/warehouse</value>
  <description>location of default database for the warehouse</description>
</property>

四、在hdfs上建立hive.metastore.warehouse.dir目錄,並修改權限

sudo -u hdfs hadoop fs -mkdir -p /user/hive/warehouse
sudo -u hdfs hadoop fs -chown -R hive:hive /user/hive

五、在hive-server2中設置hive配置文件,使其能鏈接到hive-metastore

  hive配置文件位置:/etc/hive/conf/hive-site.xml

  向hive-site.xml中添加下列內容

<property>
  <name>hive.metastore.uris</name>
  <value>thrift://Host2:9083</value>
</property>

六、分別在Host0,Host2中啓動hive-server2,hive-metastore

service hive-server2 start
service hive-metastore start

七、在另外一臺虛擬機中進行測試(須要安裝hive)

[root@client ~]# beeline 
which: no hbase in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_60/bin:/root/bin)
Beeline version 1.1.0-cdh5.8.0 by Apache Hive
beeline> !connect jdbc:hive2://Host0:10000
scan complete in 11ms
Connecting to jdbc:hive2://Host0:10000
Enter username for jdbc:hive2://Host0:10000: 1
Enter password for jdbc:hive2://Host0:10000: *
Connected to: Apache Hive (version 1.1.0-cdh5.8.0)
Driver: Hive JDBC (version 1.1.0-cdh5.8.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://Host0:10000> show tables;
INFO  : Compiling command(queryId=hive_20160912015858_bd9495d2-191f-429c-bf01-a165821b6d9a): show tables
INFO  : Semantic Analysis Completed
INFO  : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:tab_name, type:string, comment:from deserializer)], properties:null)
INFO  : Completed compiling command(queryId=hive_20160912015858_bd9495d2-191f-429c-bf01-a165821b6d9a); Time taken: 0.027 seconds
INFO  : Concurrency mode is disabled, not creating a lock manager
INFO  : Executing command(queryId=hive_20160912015858_bd9495d2-191f-429c-bf01-a165821b6d9a): show tables
INFO  : Starting task [Stage-0:DDL] in serial mode
INFO  : Completed executing command(queryId=hive_20160912015858_bd9495d2-191f-429c-bf01-a165821b6d9a); Time taken: 0.061 seconds
INFO  : OK
+-----------+--+
| tab_name  |
+-----------+--+
+-----------+--+
No rows selected (0.389 seconds)

須要注意的是:若是在hiveserver2方式中沒有使用Kerberos,則上述密碼能夠隨意寫

八、在Hive中建立表,並將數據導入表中

CREATE TABLE test(id int, A int, B int, C int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
load data inpath '/user/sqoop/sample' into table test;
/user/sqoop/sample表中的數據格式爲:11419,9,160,48格式當執行load data inpath '/user/sqoop/sample' into table test;後,/user/sqoop/sample裏的數據就mv到了/user/hive/warehouse/test中去了,/user/sqoop/sample目錄爲空。
相關文章
相關標籤/搜索