標籤:
Hive的預設資料庫為Derby,這個資料庫用於自己調試是可以的,但是要面對大量資料就有些力不從心了,所以接下來我要將Derby換為Postgresql,我會具體說一下在更換過程中需要注意的地方。
首先,下載Hive,我們直接下載穩定的apache-hive-0.14.0-bin.tar.gz,,
http://apache.fayea.com/hive/stable/
下載完成後,安裝,將Hive添加到環境變數中,編輯bashrc檔案
vim ~/.bashrc
將下行添加進去
export PG_HOME=/opt/pgsql/postgresql
同時將bin目錄添加到PATH中
export PATH=$PG_HOME/bin:$PATH
配置完成後,執行下面的命令,讓修改的環境變數馬上生效
source ~/.bashrc
好了,到這裡Hive就安裝完了,切換到系統管理員的身份,執行hive,看看效果
如果執行完成後沒有報錯,應該來到這個介面
執行
show tables;
如果返回OK,就說明你的Hive安裝成功了。
接下來修改預設資料庫:
首先,下載postgresql的jdbc驅動包,
http://jdbc.postgresql.org/download.html
仔細查看頁面說明,選擇符合自己系統內容的驅動包,我這裡下載的是
postgresql-9.3-1102.jdbc41.jar
好了,將這個驅動包上傳到Hive的lib目錄下面,在Hive的conf目錄下面添加
hive-site.xml
檔案,對於0.14版本而言這個檔案預設是沒有的,在檔案中添加以下內容
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><configuration> <!-- WARNING!!! This file is auto generated for documentation purposes ONLY! --> <!-- WARNING!!! Any changes you make to this file will be ignored by Hive. --> <!-- WARNING!!! You must make your changes in hive-site.xml instead. --> <!-- Hive Execution Parameters --> <property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:postgresql://db_ip:db_port/db_name</value><description>JDBC connect string for a JDBC metastore</description></property><property><name>javax.jdo.option.ConnectionDriverName</name><value>org.postgresql.Driver</value><description>Driver class name for a JDBC metastore</description></property><property><name>javax.jdo.option.ConnectionUserName</name><value>db_user</value><description>username to use against metastore database</description></property><property><name>javax.jdo.option.ConnectionPassword</name><value>db_pwd</value><description>password to use against metastore database</description></property></configuration>
這個檔案中說明了,具體的資料庫連接的相關資訊,到這裡應該就部署完成了,但是還有一些細節需要操作,
將
$JAVA_HOME/lib/tools.jar
這個jar包拷貝到Hive的lib目錄下。
為了防止Postgresql發生死結需要匯入一個sql,在上面的下載的Hive的包中進入到以下目錄
apache-hive-0.14.0-bin.tar.gz\apache-hive-0.14.0-bin\scripts\metastore\upgrade\postgres
找到檔案
hive-schema-0.14.0.postgres.sql
在linux中執行以下命令進行匯入
psql -U db_user -d db_name -f hive-schema-0.14.0.postgres.sql
匯入完成後,所以的修改就完成了,趕快去驗證一下
create table text_test(str string);show tables;
如果一切顯示正常,那麼恭喜你,修改成功!
將Hive的預設資料庫Derby改為Postgresql