Hive學習之路 (四)Hive的鏈接3種鏈接方式

 

正文web

1、CLI鏈接

進入到 bin 目錄下,直接輸入命令: 數據庫

複製代碼

[hadoop@hadoop3 ~]$ hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]apache

Logging initialized using configuration in jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/hive-common-2.3.3.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> show databases;
OK
default
myhive
Time taken: 6.569 seconds, Fetched: 2 row(s)
hive>瀏覽器

複製代碼

啓動成功的話如上圖所示,接下來即可以作 hive 相關操做app

補充:ide

  一、上面的 hive 命令至關於在啓動的時候執行:hive --service clioop

  二、使用 hive --help,能夠查看 hive 命令能夠啓動那些服務spa

  三、經過 hive --service serviceName --help 能夠查看某個具體命令的使用方式3d


2、HiveServer2/beeline

在如今使用的最新的 hive-2.3.3 版本中:都須要對 hadoop 集羣作以下改變,不然沒法使用

一、修改 hadoop 集羣的 hdfs-site.xml 配置文件

加入一條配置信息,表示啓用 webhdfs

<property>
 <name>dfs.webhdfs.enabled</name>
 <value>true</value>
</property>

二、修改 hadoop 集羣的 core-site.xml 配置文件

加入兩條配置信息:表示設置 hadoop 的代理用戶

複製代碼
<property>
 <name>hadoop.proxyuser.hadoop.hosts</name>
 <value>*</value>
</property>
<property>
 <name>hadoop.proxyuser.hadoop.groups</name>
 <value>*</value>
</property>
複製代碼

配置解析:

hadoop.proxyuser.hadoop.hosts 配置成*的意義,表示任意節點使用 hadoop 集羣的代理用戶 hadoop 都能訪問 hdfs 集羣,hadoop.proxyuser.hadoop.groups 表示代理用戶的組所屬

以上操做作好了以後(最好重啓一下HDFS集羣),請繼續作以下兩步:

第一步:先啓動 hiveserver2 服務

啓動方式,(假如是在 hadoop3 上):

啓動爲前臺:hiveserver2

複製代碼
[hadoop@hadoop3 ~]$ hiveserver2
2018-04-04 10:21:49: Starting HiveServer2
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
複製代碼

啓動會多一個進程

啓動爲後臺:

nohup hiveserver2 1>/home/hadoop/hiveserver.log 2>/home/hadoop/hiveserver.err &
或者:nohup hiveserver2 1>/dev/null 2>/dev/null &
或者:nohup hiveserver2 >/dev/null 2>&1 &

以上 3 個命令是等價的,第一個表示記錄日誌,第二個和第三個表示不記錄日誌

命令中的 1 和 2 的意義分別是:

1:表示標準日誌輸出

2:表示錯誤日誌輸出 若是我沒有配置日誌的輸出路徑,日誌會生成在當前工做目錄,默認的日誌名稱叫作: nohup.xxx

[hadoop@hadoop3 ~]$ nohup hiveserver2 1>/home/hadoop/log/hivelog/hiveserver.log 2>/home/hadoop/log/hivelog/hiveserver.err &
[1] 4352
[hadoop@hadoop3 ~]$ 

PS:nohup 命令:若是你正在運行一個進程,並且你以爲在退出賬戶時該進程還不會結束, 那麼可使用 nohup 命令。該命令能夠在你退出賬戶/關閉終端以後繼續運行相應的進程。 nohup 就是不掛起的意思(no hang up)。 該命令的通常形式爲:nohup command &

第二步:而後啓動 beeline 客戶端去鏈接:

執行命令:

複製代碼
[hadoop@hadoop3 ~]$ beeline -u jdbc:hive2//hadoop3:10000 -n hadoop
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
scan complete in 1ms
scan complete in 2374ms
No known driver to handle "jdbc:hive2//hadoop3:10000"
Beeline version 2.3.3 by Apache Hive
beeline> 
複製代碼

-u : 指定元數據庫的連接信息

-n : 指定用戶名和密碼

另外還有一種方式也能夠去鏈接:

先執行 beeline

而後按圖所示輸入:!connect jdbc:hive2://hadoop02:10000

按回車,而後輸入用戶名,這個 用戶名就是安裝 hadoop 集羣的用戶名

複製代碼
[hadoop@hadoop3 ~]$ beeline
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apps/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Beeline version 2.3.3 by Apache Hive
beeline> !connect jdbc:hive2://hadoop3:10000
Connecting to jdbc:hive2://hadoop3:10000
Enter username for jdbc:hive2://hadoop3:10000: hadoop
Enter password for jdbc:hive2://hadoop3:10000: ******
Connected to: Apache Hive (version 2.3.3)
Driver: Hive JDBC (version 2.3.3)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://hadoop3:10000> 
複製代碼

接下來即可以作 hive 操做


3、Web UI

 一、 下載對應版本的 src 包:apache-hive-2.3.2-src.tar.gz

二、 上傳,解壓

tar -zxvf apache-hive-2.3.2-src.tar.gz

三、 而後進入目錄${HIVE_SRC_HOME}/hwi/web,執行打包命令:

jar -cvf hive-hwi-2.3.2.war *

在當前目錄會生成一個 hive-hwi-2.3.2.war

四、 獲得 hive-hwi-2.3.2.war 文件,複製到 hive 下的 lib 目錄中

cp hive-hwi-2.3.2.war ${HIVE_HOME}/lib/

五、 修改配置文件 hive-site.xml

複製代碼
<property>
 <name>hive.hwi.listen.host</name>
 <value>0.0.0.0</value>
 <description>監聽的地址</description>
</property>
<property>
 <name>hive.hwi.listen.port</name>
 <value>9999</value>
 <description>監聽的端口號</description>
</property>
<property>
 <name>hive.hwi.war.file</name>
 <value>lib/hive-hwi-2.3.2.war</value>
 <description>war 包所在的地址</description>
</property>
複製代碼

六、 複製所需 jar 包

  一、cp ${JAVA_HOME}/lib/tools.jar ${HIVE_HOME}/lib

  二、再尋找三個 jar 包,都放入${HIVE_HOME}/lib 目錄:

    commons-el-1.0.jar

    jasper-compiler-5.5.23.jar

    jasper-runtime-5.5.23.jar

    否則啓動 hwi 服務的時候會報錯。

七、 安裝 ant

一、 上傳 ant 包:apache-ant-1.9.4-bin.tar.gz

二、 解壓 tar -zxvf apache-ant-1.9.4-bin.tar.gz -C ~/apps/

三、 配置環境變量 vi /etc/profile 在最後增長兩行: export ANT_HOME=/home/hadoop/apps/apache-ant-1.9.4 export PATH=$PATH:$ANT_HOME/bin 配置完環境變量別忘記執行:source /etc/profile

四、 驗證是否安裝成功

 

八、上面的步驟都配置完,基本就大功告成了。進入${HIVE_HOME}/bin 目錄:

   ${HIVE_HOME}/bin/hive --service hwi

  或者讓在後臺運行: nohup bin/hive --service hwi > /dev/null 2> /dev/null &

九、 前面配置了端口號爲 9999,因此這裏直接在瀏覽器中輸入: hadoop02:9999/hwi

十、至此大功告成

 

相關文章
相關標籤/搜索