Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的sql查询功能,可以将sql语句转换为MapReduce任务进行运行。
先在node001上安装mysql关系型数据库:Docker安装mysql数据库
为hive创建数据库和用户
mysql> create database hive DEFAULT CHARACTER SET utf8;
mysql> grant all on hive.* TO 'hive'@'%' IDENTIFIED BY 'hive';
mysql> flush privileges;
hive搭建-单用户
hive搭建-多用户Remote分开
在node002上安装hive,配置环境变量
[root@node002 ~]# tar -zxvf apache-hive-1.2.1-bin.tar.gz
[root@node002 ~]# mv apache-hive-1.2.1-bin.tar.gz /opt
export HIVE_HOME=/opt/apache-hive-1.2.1-bin
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$HIVE_HOME/bin
source /etc/profile
在conf目录修改配置:hive-site.xml
[root@node002 conf]# cp hive-default.xml.template hive-site.xml
vim删到最后1行::.,$-1d
hive.metastore.warehouse.dir
/user/hive/warehouse
javax.jdo.option.ConnectionURL
jdbc:mysql://node001:3306/hive?createDatabaseIfNotExist=true
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName
hive
javax.jdo.option.ConnectionPassword
hive
hive中数据上传到hdfs中的存储目录(即数据仓库的目录)
元数据保存到mysql里面,要建库再建表
设置连接mysql信息
Hive 的体系结构
连接hive服务端程序
mysql部署在远端并且hive.metastore.local=false,需要先启动hive服务端程序
[root@node002 ~]# hive --service metastore
卡住是正常的,可重开连接,使用hive命令
[root@node002 ~]# hive
Logging initialized using configuration in jar:file:/opt/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive> show databases;
OK
default
Time taken: 1.194 seconds, Fetched: 1 row(s)
hive> create database test_db;
hive> use test_db;
hive> show tables;
hive> create table test_t(id int, name string);
观察:#hadoop fs -ls /user/hive/warehouse
参数:hive.metastore.warehouse.dir
分号结束立即执行。
以上,hive服务端和客户端是配置在一起的,也可以把他们分开
For direct MetaStore DB connections, we don’t support retries at the client level.
hive> create table test_t(id int, name string);
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:For di
rect MetaStore DB connections, we don't support retries at the client level.)
当在Hive中创建表的时候报错:
这是由于字符集的问题,需要配置MySQL的字符集:
mysql> alter database hive character set latin1;
查看数据库的字符集
mysql> show variables like 'character_set_%';
客户端启动的时候要注意:
[ERROR] Terminal initialization failed; falling back to unsupported java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
at jline.TerminalFactory.create(TerminalFactory.java:101)
cp $HIVE_HOME/lib/jline-*.jar $HADOOP_HOME/share/hadoop/yarn/lib
mv jline-0.9.94.jar jline-0.9.94.jar.bak
当启动Hive客户端时候出现如下错误:
WARN conf.HiveConf: HiveConf of name hive.metastore.local does not exist
这是由于在0.10以后的HIVE版本 hive.metastore.local 属性不再使用。将该参数从hive-site.xml删除即可。
启动Hive服务,报9083端口被占用
# jps
2201 RunJar
Kill -9 2201 即可
Hadoop集群基础配置