Hive

[Hive]HiveServer2 와 Beeline

heed159 2022. 3. 16. 13:38

HiveServer2는 Hiveserver1의 후속으로 클라이언트가 하이브에 대해 쿼리를 실행할 수 있게 해주는 서비스이다.

 

 

 

<HiveServer2의 특징>

  • HiveServer2는 다중 클라이언트 동시성 및 인증을 지원한다.
  • JDBC 및 ODBC와 같은 공개 API 클라이언트를 지원한다
  • Thrfit 기반 하이브 서비스 (TCP 또는 HTTP)와 웹 UI용 Jetty 웹 서버를 포함하는 복합 서비스로 실행되는 단일 프로세스

Thrift 기반 하이브 서비스는 HS2의 핵심이며 하이브 쿼리 서비스를 담당한다. Thrift는 플랫폼 간 서비스를 구축하기 위한 RPC 프레임워크이다.

 

 

 

HiveServer2는 HTTP 전송을 위해 Thrift RPC 메시지 전송을 지원한다. 이는 클라이언트와 서버 간의 프록시 중개자를 지원하는 데 특히 유용하다. 현재 HiveServer2는 TCP 또는 HTTP 모드에서 실행할 수 있지만 둘 다에서는 실행할 수 없다.

 

 

<실행 방법>

[hadoop@node1 ~]$ $HIVE_HOME/bin/hiveserver2

또는

[hadoop@node1 ~]$ $HIVE_HOME/bin/hive --service hiveserver2

또는

[hadoop@node1 ~]$ nohup hiveserver2 &
[1] 11980
nohup: ignoring input and appending output to `nohup.out'

포그라운드에서 실행할 수도 있지만 실질적으로는 데몬으로 백그라운드 실행을 한다. (서버가 끊어져도 영향이 없다)

 

 

 

<Beeline>

 

Beeline은 HiveServer2에 접속하여 Command Shell을 수행할 수 있도록 도와주는 Client이며 SQLLine CLI를 기반으로 하는 JDBC 클라이언트이기도 하다. 

 

Beeline shell은 두 가지 방식으로 수행된다.

  • Embedded mode : Hive CLI와 유사하게 embedded hive를 수행
  • Remote mode : Thrift 통신을 통해 원격지에 있는 HiveServer2에 접속하여 수행 (단, Thrift 통신만 허용)

 

Beeline에서 HiveServer2에 접속하는 방법은 Beeline CLI를 실행한 후에 접속하는 방법과  Beeline CLI를 실행하면서 옵션을 사용하는 방식이 있다.

Beeline 커맨드는 $HIVE_HOME/bin 디렉터리에 있다.


 

<Beeline CLI를 실행한 후 접속>

[hadoop@node2 bin]$ beeline
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apache-hive-3.1.2-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-3.2.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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 3.1.2 by Apache Hive

beeline> !connect jdbc:hive2://hadoop01:10000 hive postgres
Connecting to jdbc:hive2://hadoop01:10000
Connected to: Apache Hive (version 3.1.2)
Driver: Hive JDBC (version 3.1.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ

 

 

<커맨드라인 옵션을 사용한 접속>

 

[hadoop@node2 bin]$ beeline -u jdbc:hive2://hadoop01:10000 -n hive -p postgres
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hadoop/apache-hive-3.1.2-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-3.2.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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://hadoop01:10000
Connected to: Apache Hive (version 3.1.2)
Driver: Hive JDBC (version 3.1.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 3.1.2 by Apache Hive

 

위와 같이 HiveServer2가 올라와 있는 서버의 IP와 포트 번호로 원격으로 접속이 가능하다.

beeline 커맨드를 사용하기 위해 hive를 설치해주었는데 단순히 beeline 커맨드만 패키지 설치 등으로 사용할 수 있는 방법이 있는지 찾아봐야 할 것 같다.

 

 

 

참고 : https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2