1. 程式人生 > >hadoop-2.10.0安裝hive-2.3.6

hadoop-2.10.0安裝hive-2.3.6

公司建立數倉,hive是必不可少的,hive是建立在hadoop基礎上的資料庫,前面已經搭建起了hadoop高可用,要學習hive,先從搭建開始,下面梳理一下hive搭建過程

1.下載hive安裝包 ,下載地址:https://hive.apache.org/downloads.html 

找到自己hadoop對應的版本下載安裝,我這裡下載的是 apache-hive-2.3.6-bin.tar.gz

2.安裝hive,將安裝包解壓到/opt/soft下,並建立軟連結

tar -zxvf apache-hive-2.3.6-bin.tar.gz -C /opt/soft/
cd /opt/soft
mv apache-hive-2.3.6-bin hive-2.3.6
ln -s hive-2.3.6 hive

3.配置環境變數/etc/profile

vim /etc/profile

#hive export HIVE_HOME=/opt/soft/hive export PATH=$PATH:$HIVE_HOME/bin

儲存後別忘記編譯一下

source /etc/profile

4.配置hive配置檔案,hive元資料預設儲存到derby資料庫中,我們這裡使用mysql來儲存,hive-site.xml配置資訊較多建議下載到windows下修改,然後再傳上去

首先複製預設的配置檔案模板,裡面已經包含hive所有的預設配置資訊

cp hive-default.xml.template hive-site.xml

修改hive-site.xml配置檔案,將元資料存放資料庫改為mysql,在hive-site.xml中找到下列屬性,修改為:

<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.ConnectionURL</name>
    <value>jdbc:mysql://192.168.118.1:3306/hive2</value>
    <description>
      JDBC connect string for a JDBC metastore.
      To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
      For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
    </description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>root</value>
    <description>Username to use against metastore database</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>111111</value>
    <description>password to use against metastore database</description>
  </property>

資料庫驅動為mysql驅動com.mysql.jdbc.Driver,URL改為mysql的hive2(自定義)資料庫,使用者名稱密碼為自己資料庫對應的使用者名稱密碼

修改hive配置的一些目錄,指定到自己選擇的目錄,搜尋以 ${system 開頭的 value 替換為自己的目錄,我這裡替換為:/home/hdfs/hive下相關目錄

  <property>
    <name>hive.exec.local.scratchdir</name>
    <value>/home/hdfs/hive</value>
    <description>Local scratch space for Hive jobs</description>
  </property>
<property>
    <name>hive.downloaded.resources.dir</name>
    <value>/home/hdfs/hive/downloads</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
  </property>
  <property>
    <name>hive.querylog.location</name>
    <value>/home/hdfs/hive/querylog</value>
    <description>Location of Hive run time structured log file</description>
  </property>
  <property>
    <name>hive.server2.logging.operation.log.location</name>
    <value>/home/hdfs/hive/server2_logs</value>
    <description>Top level directory where operation logs are stored if logging functionality is enabled</description>
  </property>

修改許可權驗證為false

 <property>
    <name>hive.server2.enable.doAs</name>
    <value>false</value>
    <description>
      Setting this property to true will have HiveServer2 execute
      Hive operations as the user making the calls to it.
    </description>
  </property>

5.既然修改元資料存放在mysql庫裡,就需要將mysql驅動包放入到hive/lib中,注意mysql版本和驅動包一致

mv mysql-connector-java-8.0.18.jar /opt/soft/hive/lib/

6.在mysql資料庫中建立hive2庫

7.初始化hive的元資料(表結構)到mysql中。

cd /opt/soft/hive/bin
schematool -dbType mysql -initSchema

出現如下資訊,代表成功

 

也可以檢視mysql中hive2庫,所有表初始化完成

 

 

8.啟動hadoop,如果沒有安裝可以參考:centos7搭建hadoop2.10高可用(HA)

start-all.sh

9.啟動hive

hive

 

 檢視目前只有default資料庫

建立資料庫:

create database myhivedb2;

 

 檢視建立的mysqhivedb2已經出來了

我們查一下hdfs中是否建立了對應的目錄

hdfs dfs -ls -R /user/hive/

 

 也可以檢視mysql中hive2庫的dbs表:

 

 至此hive環境搭建完成

&n