HiveServer2是一個能使客戶端針對hive執行查詢的一種服務,與HiverServer1比較,它能夠支持多個客戶端的並發請求和授權的;HiveCLI 和 hive –e的方式比較單一,HS2允許遠程客戶端使用多種語言諸如Java,Python等向Hive提交請求,然后取回結果.
$HIVE_HOME/bin目錄下面的hiveserver2
由於配置了環境變量因此可以直接使用
nohup hiveserver2 1>/hiveserver2log/log.txt 2>/hiveserver2log/log.err &
命令中的 1 和 2 的意義分別是:
1:表示標准日志輸出
2:表示錯誤日志輸出 如果我沒有配置日志的輸出路徑,日志會生成在當前工作目錄,默認的日志名稱叫做: nohup.xxx
作為數據倉庫的工具,hive提供了兩種ETL運行方式,分別是通過Hive 命令行和beeline客戶端;
命令行方式即通過hive進入命令模式后通過執行不同的HQL命令得到對應的結果;相當於胖客戶端模式,即客戶機中需要安裝JRE環境和Hive程序。
beeline客戶端方式相當於瘦客戶端模式,采用JDBC方式借助於Hive Thrift服務訪問Hive數據倉庫。
$HIVE_HOME/bin目錄下面的beeline
由於配置了環境變量因此可以直接使用,使用過程中要指定hive的鏈接信息,用戶名,密碼
測試環境無密碼
[root@host ~]# beeline
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/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.1.1 by Apache Hive
beeline> !connect jdbc:hive2://192.168.53.122:10000/default
Connecting to jdbc:hive2://192.168.53.122:10000/default
Enter username for jdbc:hive2://192.168.53.122:10000/default: root
Enter password for jdbc:hive2://192.168.53.122:10000/default:
Connected to: Apache Hive (version 2.1.1)
Driver: Hive JDBC (version 2.1.1)
18/09/06 16:08:26 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false.
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://192.168.53.122:10000/default> show databases;
+----------------+--+
| database_name |
+----------------+--+
| default |
| gamedw |
| hive_hbase |
| sqoopdb |
| testdb |
| userdb |
+----------------+--+
6 rows selected (0.335 seconds)
0: jdbc:hive2://192.168.53.122:10000/default>
也可以用下面方式:
[root@host ~]# beeline -u jdbc:hive2://192.168.53.122:10000/default -n root
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/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]
Connecting to jdbc:hive2://192.168.53.122:10000/default
Connected to: Apache Hive (version 2.1.1)
Driver: Hive JDBC (version 2.1.1)
18/09/06 16:16:38 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false.
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 2.1.1 by Apache Hive
0: jdbc:hive2://192.168.53.122:10000/default> show databases;
+----------------+--+
| database_name |
+----------------+--+
| default |
| gamedw |
| hive_hbase |
| sqoopdb |
| testdb |
| userdb |
+----------------+--+
6 rows selected (0.178 seconds)
0: jdbc:hive2://192.168.53.122:10000/default>
可以直接通過-u -n-p -e等參數讓其執行我們的操作,參數選項:
-u<database URL> 要連接的數據庫的URL
-n<username> 指定要連接數據庫的用戶名
-p<password> 指定要連接數據庫的密碼
-d<driver class> 使用的驅動名字
-i<init file> 初始化的腳本文件
-e<query> 要執行的查詢
-f<exec file> 要執行的腳本文件
-w/--password-file<password file> 從文件讀取密碼
--hiveconf<key=value> 指定hive配置文件
--hivevarname=value 設置hive變量
--showHeader=[true/false]控制是否在查詢結果顯示列名
--autoCommit=[true/false]是否自動提交事務
--force=[true/false]運行腳本出錯是否繼續
--outputformat=[table/vertical/csv2/tsv2/dsv] 指定結果展示的格式