标签:
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;
如果一切显示正常,那么恭喜你,修改成功!
标签:
原文地址:http://my.oschina.net/sucre/blog/365351