hadoop集羣配置之hive1.2.0安裝部署(遠程mysql)

hadoop的版本是2.6.0java

根據hive的源數據不一樣分爲三種模式mysql

    一、內嵌模式,使用自帶的derbyweb

    二、本地獨立模式,本地mysql庫sql

    三、遠程模式,遠程mysql庫數據庫

這裏主要將第三種模式apache

#假設hadoop2.6.0已經正常啓動centos

首先下載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

接着將下載的文件上傳到服務器並解壓到主目錄app

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>
 <property>
  <name>datanucleus.autoCreateSchema</name>
  <value>true</value>
</property>

<property>
  <name>datanucleus.autoCreateTables</name>
  <value>true</value>
</property>

<property>
  <name>datanucleus.autoCreateColumns</name>
  <value>true</value>
</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官方文檔看到:

Hive Web Interface (HWI)

hive.hwi.war.file

  • 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}.

hive.hwi.listen.host

  • Default Value: 0.0.0.0

  • Added In: Hive 0.3.0

This is the host address the Hive Web Interface will listen on.

hive.hwi.listen.port

  • 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便可

相關文章
相關標籤/搜索