1.hive简介
起源自facebook由jeff hammerbacher领导的团队
构建在hadoop上的数据仓库框架
设计目的是让sql技能良好,但java技能较弱的分析师可以查询海量数据
2008年facebook把hive项目贡献给apache
hive的组件与体系架构
用户接口:shell, thrift, web等
thrift服务器
元数据库“derby, mysql等
解析器
hadoop
hive安装模式
内嵌模式:元数据保持在内嵌的derby模式,只允许一个会话连接(默认)
本地独立模式:在本地安装mysql,把元数据放到mysql内
远程模式:元数据放置在远程的mysql数据库
2.配置mysql
1:copy mysql-connector-java-5.1.6-bin.jar到$hive_home/lib
[jifeng@jifeng02 hadoop]$ ls7287os_code hadoop-1.2.1.tar.gz hive-0.12.0-bin tmphadoop-1.2.1 hadoop-2.4.1-src.tar.gz hive-0.12.0-bin.tar.gzhadoop-1.2.1-bin.tar.gz hadoop-2.4.1.tar.gz mysql-connector-java-5.1.6-bin.jar[jifeng@jifeng02 hadoop]$ cp mysql-connector-java-5.1.6-bin.jar hive-0.12.0-bin/lib
2:修改$hive_home/conf/hive-site.xmljavax.jdo.option.connectionurljdbc:mysql://jifengsql:3306/hive?createdatabaseifnotexist=truejdbc connect string for a jdbc metastorejavax.jdo.option.connectiondrivernamecom.mysql.jdbc.driverdriver class name for a jdbc metastorejavax.jdo.persistencemanagerfactoryclassorg.datanucleus.api.jdo.jdopersistencemanagerfactoryclass implementing the jdo persistencejavax.jdo.option.detachalloncommittruedetaches all objects from session so that they can be used after transaction is committeddescription>javax.jdo.option.nontransactionalreadtruereads outside of transactionsjavax.jdo.option.connectionusernamedssusername to use against metastore databasejavax.jdo.option.connectionpasswordjifengpassword to use against metastore database
3:启动hive
[jifeng@jifeng02 hive-0.12.0-bin]$ hivelogging initialized using configuration in jar:file:/home/jifeng/hadoop/hive-0.12.0-bin/lib/hive-common-0.12.0.jar!/hive-log4j.propertieshive> show tables;failed: execution error, return code 1 from org.apache.hadoop.hive.ql.exec.ddltask. java.lang.runtimeexception: unable to instantiate org.apache.hadoop.hive.metastore.hivemetastoreclienthive> quit;
报错,网上查询后说是没把 mysql的jar包mysql-connector-java-5.1.10-bin.jar,放在hive安装目录的lib下把 mysql-connector-java-5.1.6-bin.jar 替换成mysql-connector-java-5.1.10-bin.jar还是不行。
检查 mysql发现连接不上,换个虚拟机上mysql
[dss@localhost ~]$ mysql -u root -penter password: --root 登陆mysqlwelcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 70server version: 5.6.16 mysql community server (gpl)copyright (c) 2000, 2014, oracle and/or its affiliates. all rights reserved.oracle is a registered trademark of oracle corporation and/or itsaffiliates. other names may be trademarks of their respectiveowners.type 'help;' or '\h' for help. type '\c' to clear the current input statement.mysql> create database hive;query ok, 1 row affected (0.01 sec) --创建hive库mysql> grant all on hive.* to dss@'%' identified by 'abc123';query ok, 0 rows affected (0.03 sec)--给dss用户对hive库授权mysql> flush privileges;query ok, 0 rows affected (0.02 sec)--刷新系统权限表mysql> set globalbinlog_format='mixed'; error 1193 (hy000): unknown system variable 'globalbinlog_format'mysql> alter database hive character set latin1 ;query ok, 1 row affected (0.00 sec)--更新字符集
再次启动
[jifeng@jifeng02 hive-0.12.0-bin]$ hivelogging initialized using configuration in jar:file:/home/jifeng/hadoop/hive-0.12.0-bin/lib/hive-common-0.12.0.jar!/hive-log4j.propertieshive> show tables;oktime taken: 6.273 secondshive>
没有错误了。4.hive的运行模式即任务的执行环境
1启动hive 命令行模式:1:直接输入#hive的执行程序,
2:或者输入 #hive --service cli
l 分为本地与集群两种
我们可以通过mapred.job.tracker 来指明
设置方式:
hive >
set mapred.job.tracker=local
2.hive验证启动的方法l 1、hive web界面的(端口号9999) 启动方式
#hive --service hwi
[jifeng@jifeng02 hive-0.12.0-bin]$ hive --service clilogging initialized using configuration in jar:file:/home/jifeng/hadoop/hive-0.12.0-bin/lib/hive-common-0.12.0.jar!/hive-log4j.propertieshive> quit;[jifeng@jifeng02 hive-0.12.0-bin]$ hive --service hwi 15/08/17 15:17:10 info hwi.hwiserver: hwi is starting up15/08/17 15:17:10 info mortbay.log: logging to org.slf4j.impl.log4jloggeradapter(org.mortbay.log) via org.mortbay.log.slf4jlog15/08/17 15:17:10 info mortbay.log: jetty-6.1.2615/08/17 15:17:10 info mortbay.log: extract /home/jifeng/hadoop/hive-0.12.0-bin/lib/hive-hwi-0.12.0.war to /tmp/jetty_0_0_0_0_9999_hive.hwi.0.12.0.war__hwi__ow27i/webapp15/08/17 15:17:11 info mortbay.log: started socketconnector@0.0.0.0:9999
用于通过浏览器来访问hive
http://jifeng02:9999/hwi/
l 2、hive 远程服务(端口号10000) 启动方式
#hive --service hiveserver
