hadoop的版本是2.6.0
根据hive的源数据不同分为三种模式
1、内嵌模式,使用自带的derby
2、本地独立模式,本地mysql库
3、远程模式,远程mysql库
这里主要将第三种模式
#假设hadoop2.6.0已经正常启动
首先下载hive-1.2.0版本,下载地址hive官方下载
然后登陆root修改环境变量,下面是我得
export HADOOP_HOME=/home/hadoop/hadoop-2.6.0 export HIVE_HOME=/home/hadoop/apache-hive-1.2.0-bin export PATH=$PATH:$HIVE_HOME/bin export CLASS_PATH=$CALSSPATH:$HIVE_HOME/lib
接着将下载的文件上传到服务器并解压到主目录
tar xvzf apache-hive-1.2.0-bin.tar.gz
为了一次性成功,在hive主目录下找到conf文件夹下的hive_env.sh,将其中得HADOOP_HOME和HIVE_CONF_DIR放开并怕配置
# Set HADOOP_HOME to point to a specific hadoop install directory export HADOOP_HOME=/home/hadoop/hadoop-2.6.0 # Hive Configuration Directory can be controlled by: export HIVE_CONF_DIR=/home/hadoop/apache-hive-1.2.0-bin/conf
配置完后将hive-default.xml.template复制并改名为hive-site.xml,清除里面得全部内容(因为hive会先加载default那个文件,再去加载site文件,如果两个文件里有相同得配置,那么以site为准,所以不必拷贝那么多,容易混淆)
将如下配置复制进去
<configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.1.102:3306/hive</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> <description>驱动名</description> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> <description>用户名</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> <description>密码</description> </property> <property> <name>hive.metastore.warehouse.dir</name> <value>/home/hadoop/hive/warehouse</value> <description>数据路径(相对hdfs)</description> </property> <property> <name>hive.metastore.uris</name> <value>thrift://192.168.1.55:9083</value> <description>运行hive得主机地址及端口</description> </property> </configuration>
至此,hive得配置完成,在远程主机上安装mysql,远程主机可以是任意操作系统,我这里用的是win7-x64,安装完成后新建数据库名为hive,字符集采用latin1,
回到centos7,找到hive主目录下得lib,放入mysql得连接jar,mysql-connector-java-5.1.27-bin.jar,然后找到一个叫jline-2.1.2.jar得文件,复制他,去hadoop主目录将hadoop下得三个同名但不同版本得jline替换成刚刚复制得。
剩下最后一步,检查防火墙,不需要得话就关了防火墙,需要得话就把端口放开,比如9083,9000,9001,50070等
然后测试,切换到hive主目录,输入一下命令
bin/hive --service metastore
界面如下:
[hadoop@h1 apache-hive-1.2.0-bin]$ bin/hive --service metastore Starting Hive Metastore Server
在hive目录新打开一个命令界面,输入以下命令
bin/hive
界面如下:
[hadoop@h1 apache-hive-1.2.0-bin]$ bin/hive Logging initialized using configuration in jar:file:/home/hadoop/apache-hive-1.2.0-bin/lib/hive-common-1.2.0.jar!/hive-log4j.properties hive>
注意启动元数据服务得那个命令行界面不能关也不能按Ctrl+C,否则相当于关闭服务。
另起得那个命令行界面(客户端)进入后输入命令以下命令退出。
quit;
下面我们用命令来新建表、添加数据、删除表来测试是否成功
hive> show tables; OK Time taken: 3.069 seconds hive> create table hive_test(name string); OK Time taken: 2.405 seconds hive> LOAD DATA LOCAL INPATH '/home/hadoop/input/test3.txt' overwrite INTO TABLE hive_test; Loading data to table default.hive_test Table default.hive_test stats: [numFiles=1, numRows=0, totalSize=11, rawDataSize=0] OK Time taken: 2.63 seconds hive> select * from hive_test; OK hello word Time taken: 0.5 seconds, Fetched: 2 row(s) hive> drop table hive_test; OK Time taken: 2.948 seconds hive> show tables; OK Time taken: 0.065 seconds
=============================================
以下是补充
=============================================
hive还有个web图形界面,这里补充一下配置
首先停掉matestore服务,然后在hive-site.xml加入如下配置
<property> <name>hive.hwi.war.file</name> <value>lib/hive-hwi-1.2.0.war</value> <description>hwi得war路径</description> </property>
这里就比较闹心了,hive1.2.0不提供hwi得war,试过下载hive2.1.0得源码,在eclipse里重新打包hwi成war,但部署后database功能报错,百度上也没找到有人打包好共享得。没辙去官方文档看看,在hive得hwi官方文档看到:
Default Value: lib/hive-hwi-<version>.war
Added In: Hive 0.3.0 with default lib/hive_hwi.war
, default changed to lib/hive-hwi-<version>.war
in Hive 0.5 (HIVE-978 and HIVE-1183)
This sets the path to the HWI war file, relative to ${HIVE_HOME
}.
Default Value: 0.0.0.0
Added In: Hive 0.3.0
This is the host address the Hive Web Interface will listen on.
Default Value: 9999
Added In: Hive 0.3.0
This is the port the Hive Web Interface will listen on.
那么下载一个hive-0.3.0,将其中lib下得hive-hwi-0.3.0.war拷贝到hive安装目录下得lib里,当然参照刚才得配置还要修改一下名字,回到主目录打开命令行,输入如下命令:
bin/hive --service matestore
输入后最小化,另起一个命令行输入如下命令
bin/hive --service hwi
同样最小化,打开浏览器输入http://192.168.1.55:9999/hwi (加入安装hive得主机ip地址是192.168.1.55)
下面是我得截图
若有人遇到下面这个错,请按如下方式解决
HTTP ERROR 500 Problem accessing /hwi/. Reason: Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "/usr/java/jdk1.7.0_79/jre" Caused by: Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "/usr/java/jdk1.7.0_79/jre" at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:129) at org.apache.tools.ant.taskdefs.Javac.findSupportedFileExtensions(Javac.java:979) at org.apache.tools.ant.taskdefs.Javac.scanDir(Javac.java:956) at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:927) at org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:220) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:298) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:277) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:265) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450) at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327) at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126) at org.mortbay.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:503) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
解决办法是将jdk下的lib文件夹中的tools.jar拷贝到hive的lib中,重启hwi即可