hadoop三----基於hadoop僞分佈式整合hive和hbase

hadoop的生態圈:java

wKioL1XehMCDbOyNAAE-pDP5hro554.jpg


ETLmysql

        數據的抽取、轉換、加載web


1)安裝hivesql

  1.解壓shell

  # tar zvxf hive-0.13.0.tar.gz -C /usr/local
  # cd /usr/local
  # ln -sv   /usr/local/ hive-0.12.0  /usr/local/ hive

 2.替換jar包,保持hbase0.98與hadoop1.2一致 數據庫

  # cd /usr/hive/lib
  # rm -rf hbase-0.94*
  # find /usr/hbase/lib -name "hbase*.jar"|xargs -i cp {} ./

  重點檢查下zookeeper和protobuf的jar包是否和hbase保持一致,若是不一致,拷貝protobuf.**.jar和zookeeper-3.4.5.jar到hive/lib下。apache

 3.準備mysql當元數據庫vim

   拷貝mysql的jdbc jar包mysql-connector-java-5.1.10-bin.jar也拷貝到hive-0.12.0/lib下,拷貝完成後修改權限:bash

   # chmod 777 mysql-connector-java-5.1.10-bin.jarapp

 4.檢查hbase與hive鏈接包是否存在,若是不存在拷貝一個到lib下  

 # cd /usr/hive/lib
 # find -name hive-hbase-handler*

 wKioL1XehhyQs9L6AABrGQV-vLc165.jpg

 5.配置mysql

  安裝mysql:

  # yum install -y mysql mysql-server

 安裝完成後啓動mysql: 

# service mysqld start
# mysql

 mysql相關操做:

  ①修改root密碼(可本身根據狀況修改):

   update user set password=password('hadoop'where user='root';

  創建數據庫hive

  create database hive;

  ③受權 

  #  grant  all  on  hive.*  to  'root' @ '%'   identified  by  'hadoop' ;  
  # flush  privileges ;

 6.修改hive-site.xml配置

   <property>
  <name>hive.aux.jars.path</name>
  <value>file:///usr/local/hive/lib/hive-hbase-handler-0.13.1.jar,file:///usr/local/hbase/lib/protobuf-java-2.5.0.jar,file:///usr/local/hbase/lib/hbase-client-0.98.6.1-hadoop1.jar,file:///usr/local/hive/lib/hive-common-0.13.1.jar,file:///usr/local/hive/lib/zookeeper-3.4.5.jar</value>
 </property>
 
<property>
  <name>hive.metastore.uris</name>
  <value>thrift://10.15.62.228:9083</value>
  <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
</property>
 
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <!--<value>jdbc:derby:;databaseName=metastore_db;create=true</value>-->
  <value>jdbc:mysql://10.15.62.228:3306/hive??createDatabaseIfNotExist=true</value>
  <description>JDBC connect string for a JDBC metastore</description>
</property>
 
<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <!--<value>org.apache.derby.jdbc.EmbeddedDriver</value>-->
  <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_user</value>
  <description>username to use against metastore database</description>
</property>
 
<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>mysql密碼</value>
  <description>password to use against metastore database</description>
</property>


 7.在HDFS上新建目錄並受權

  # hadoop fs -mkdir     /hive/warehouse

   # hadoop fs -mkdir      /hive/scratchdir

 # hadoop fs -chmod g+w  /hive/warehouse

 # hadoop fs -chmod g+w   /hive/scratchdir

  這裏建立的目錄名對應配置文件中的選項:

  wKioL1Xeh3OQX_fFAACW5DFBgds990.jpg

 8.修改其餘配置:

  ①修改hadoop中的hadoop-env.sh

   # vim /usr/hadoop/etc/hadoop/hadoop-env.sh

  修改以下:

   wKioL1Xeh9fS-eXQAAElniZWB_8033.jpg

  ②修改hive中配置

  # cd /usr/hive/conf
  # mv hive-default.xml.template hive-default.xml
  # mv hive-env.sh.template hive-env.sh
  # cd /usr/hive/bin
  # vim hive-config.sh

 修改內容以下:

  wKioL1XeiCDhB3iSAAElniZWB_8792.jpg 

  (2)啓動hive(元數據庫啓動後會卡住,放着無論,開啓開啓另外一個終端便可)

    1.啓動hadoop和hbase

    2.啓動hive元數據庫   

   # cd /usr/hive/bin
   # hive  --service metastore -hiveconf hive.root.logger=DEBUG,console

   3.在新開的終端啓動hive 

   # cd /usr/hive/bin

   # hive


  (3)測試

分別啓動hive和hbase shell
hive> CREATE TABLE pokes (foo INT, bar STRING); 
OK
Time taken: 6.294 seconds
hive> show tables;
OK
pokes
Time taken: 0.131 seconds, Fetched: 1 row(s)
 
.在hive中建立表,語句以下:
hive> CREATE TABLE hbase_table_1(key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val") TBLPROPERTIES ("hbase.table.name" = "xyz");
OK
Time taken: 63.667 seconds

建立以後分別查看hbase和hive中的變化:
hive> show tables;                                                                                                                    OK                                                                                        
hbase_table_1
pokes
Time taken: 0.718 seconds, Fetched: 2 row(s)
hive> select * from hbase_table_1;
OK
1	abc
Time taken: 32.543 seconds, Fetched: 1 row(s)
 
hbase(main):047:0> list
TABLE                                                                                                                                 
xyz                                                                                                                                   
1 row(s) in 17.3310 seconds
 
=> ["xyz"]
hbase(main):048:0> put 'xyz','1','cf1:val','abc'
0 row(s) in 7.9590 seconds
 
hbase(main):049:0> scan 'xyz'
ROW                                COLUMN+CELL                                                                                        
 1                                 column=cf1:val, timestamp=1413433021803, value=abc                                                 
1 row(s) in 1.1650 seconds

  

  (4)配置hive的web接口:

apache-hive-0.13.1沒有war包,使用hive-0.12.0的hive-hwi-0.12.0.war
# cp /usr/local/hive-0.12.0/lib/hive-hwi-0.12.0.war /usr/local/apache-hive-0.13.1-bin/lib/
# chown hadoop.hadoop /usr/local/apache-hive-0.13.1-bin/lib/hive-hwi-0.12.0.war
 
修改hive-site.xml
<property>
  <name>hive.hwi.war.file</name>
  <!--<value>lib/hive-hwi-@VERSION@.war</value>-->
  <value>lib/hive-hwi-0.12.0.war</value>
  <description>This sets the path to the HWI war file, relative to ${HIVE_HOME}. </description>
</property>
 
$ hive --service hwi &


hive的hwi界面:

   wKiom1XehyKyWjUsAAGg-yDaITM574.jpg

Region Servers  zabbix.zkg.com

wKioL1XeiXnA2AyzAAKErvsX1fQ606.jpg wKioL1XeiauzhX23AAP7Ub7nJQI136.jpgwKiom1Xeh72A8nkyAALriV_Ljoo218.jpg

wKioL1XeifSxGVvNAATLkW83Mdk953.jpg

wKioL1XeihOhqEILAAUHNG2PpMk933.jpg

hadoop:

wKiom1XeiDuBcSWHAAPyZ1FU6T8768.jpg wKiom1XeiHqCEW_QAAK18agbcoY875.jpg

wKiom1XeiMHRuH5XAAK18agbcoY674.jpg

至此說明hive和hbase整合成

相關文章
相關標籤/搜索