Hive安装部署-实验环境架构
Hive安装部署-真实环境架构
Hive 环境的安装部署
Hive 安装依赖 Hadoop 的集群,它是运行在 Hadoop 的基础上。所以在安装 Hive 之前,保证 Hadoop 集群能够成功运行。Hive的安装详细流程如下所示。
1、下载Hive
Hive是Apache 的一个顶级开源项目,我们可以直接到官网下载需要的版本即可。使用的是apache-hive-1.0.0-bin.tar.gz版本,可以点击下载
2、把Hive安装包apache-hive-1.0.0-bin.tar.gz移动到/home/hadoop/app/目录下并解
压,然后将文件名称改为 hive。
[[email protected] app]$ tar ‐zxvf apache‐hive‐1.0.0‐bin.tar.gz [[email protected] app]$ mv apache‐hive‐1.0.0‐bin hive
3、添加hive环境变量
在/etc/profile文件中增加如下内容:
[[email protected] ~]$ vi /etc/profile HIVE_HOME=/home/hadoop/app/hive
PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HIVE_HOME/bin:$PATH export HIVE_HOME
保存退出后,通过source命令使配置文件生效
[[email protected] ~]$ source /etc/profile
4、启动 Hive
建议:一直用root安装,方便,不用管权限。
此时切换用户至 hadoop 用户,在命令行输入“hive”命令进行测试。
[[email protected]]$ hive hive>
1) 测试 Hive 是否安装成功。
hive> show tables;
OK
Time taken: 0.043 seconds
2) 创建表。
hive> create table test_table (id int ,name string,no int);
OK
Time taken: 0.5 seconds
3) 查询表。
hive> select * from test_table;
OK
Time taken: 0.953 seconds
如果创建表和查询表操作没有出错,就说明 Hive 安装成功。
Hive 将元数据存储在 RDBMS 中,一般常用 MySQL 和 Derby。默认情况下,Hive 元数据保存在内嵌的 Derby 数据库中,只能允许一个会话连接,只适合简单的测试。实际生产环境中不适用,为了支持多用户会话,则需要一个独立的元数据库,使用 MySQL 作为元数据库,Hive 内部对 MySQL 提供了很好的支持,配置一个独立的元数据库需要增加以下步骤。
用的是 centos 系统。
安装mysql
1) 在线安装 mysql 数据库。
[[email protected] app]# yum install mysql‐server Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.yun‐idc.com
* extras: mirrors.btte.net
* updates: mirrors.163.com
1) 启动 mysql 服务。
[[email protected] app]# service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy support‐files/mysql.server to the right place for your system
3) 设置 mysql 的 root 密码。
MySQL在刚刚被安装的时候,它的 root 用户是没有被设置密码的。首先来设置 MySQL 的
root 密码。
[[email protected] app]# mysql ‐u root ‐p Enter password: //默认密码为空,输入后回车即可
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. mysql>set password for [email protected]=password('root'); 密码设置为root
4)为 Hive 建立相应的 Mysql 账户,并赋予足够的权限。
[[email protected] app]# mysql ‐u root ‐proot
mysql>create user 'hive' identified by 'hive'; //创建一个账号:用户名为hive,密码为hive
mysql> grant all on *.* to 'hive'@'hadoop01' identified by 'hive'; //将权限授予host为hadoop01的hive用户 Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
如果 hive 账户无法登陆。为[email protected] 设置密码。
[[email protected] ~]#mysql ‐u root ‐proot
mysql>set password for [email protected]=password('hive');
5) 建立 Hive 专用的元数据库,记得用刚才创建的 “hive” 账号登录,命令如下。
[[email protected] ~]#mysql ‐u hive ‐p //用hive用户登录,密码hive Enter password:
mysql> create database hive; //创建数据库的名称为hive Query OK, 1 row affected (0.00 sec)
6) 找到Hive安装目录 conf/下的 hive-site.xml文件,修改以下几个属性。
[[email protected] conf]$ vi 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://hadoop01:3306/hive?characterEncoding=UTF‐8< /value>
< description>JDBC connect string for a JDBC metastore< /description>
< /property>
< property>
< name>javax.jdo.option.ConnectionUserName< /name>
< value>hive< /value>
< description>Username to use against metastore database< /description>
< /property>
< property>
< name>javax.jdo.option.ConnectionPassword< /name>
< value>hive< /value>
< description>password to use against metastore database< /description> < /property>
如果conf/目录下没有 hive-site.xml文件,则需要拷贝一个名为hive-site.xml的文件。
[[email protected] conf]$ cp hive‐default.xml.template hive‐site.xml
7)将mysql-connector-java-5.1.21.jar驱动包,拷贝到 $HIVE_HOME/lib 目录下。
可点击下载 (http://hadoop.f.hadoop01.com/extralib/mysql-connector-java-5.1.21.jar) mysql驱动包
[[email protected] lib]#rz //回车,选择已经下载好的mysql驱动包即可 [[email protected] lib]$ ls
mysql‐connector‐java‐5.1.21.jar
8) 启动 Hive Shell,测试运行。
[[email protected] hive]$ hive hive> show databases;
hive切换到mysql元数据库之后,hive启动时如果遇到以下错误:
Exception in thread "main"java.lang.RuntimeException:
java.lang.IllegalArgumentException:java.net.URISyntaxException:Relative path in
absolute URI:${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
解决方案:
在hive 安装目录下,创建一个临时的IO文件iotmp
[[email protected] hive]$ mkdir iotmp
[[email protected] hive]$ ls
bin derby.log hcatalog lib metastore_db README.txt scripts
conf examples iotmp LICENSE NOTICE RELEASE_NOTES.txt
然后将路径配置到hive-site.xml文件的以下参数中:
[[email protected] conf]$ vi hive‐site.xml
< property>
< name>hive.querylog.location< /name>
< value>/home/hadoop/app/hive/iotmp< /value>
< description>Location of Hive run time structured log file< /description>
< /property>
< property>
< name>hive.exec.local.scratchdir< /name>
< value>/home/hadoop/app/hive/iotmp< /value>
< description>Local scratch space for Hive jobs< /description>
< /property>
< property>
< name>hive.downloaded.resources.dir< /name>
< value>/home/hadoop/app/hive/iotmp< /value>
< description>Temporary local directory for added resources in the remote file system.< /descrip < /property>
保存,重启hive即可。
[[email protected] hive]$ hive hive> show databases;
OK default
Time taken: 3.684 seconds, Fetched: 1 row(s) hive>
OK,Hive 就可以使用!