관리 메뉴

A seeker after truth

beeline 연결법, 에러 해결법 본문

Data/hadoop ecosystem

beeline 연결법, 에러 해결법

dr.meteor 2022. 5. 16. 23:00

1. beeline 이 무엇이며, 왜 필요한가

일단 저는 beeline 이란 무엇인지, 어떤 역할을 하는 아이인지, 왜 등장한 것인지에 대해서 모릅니다.

현재 그걸 알아볼 여유가 없습니다.

 

다만 이게 꼭 필요하게 된 이유를 알게 된 계기가 있습니다.

저는 hive 에서 조회(show tables, select ~~~) 즉 dml 쿼리 말고 create 등의 ddl query 실행 작업이 필요했는데,

hive 에서 이걸 하려 하면 자꾸 다음과 같은 에러가 발생했습니다.

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: java.net.ConnectException Call From MacBookPro.local/127.0.0.1 to localhost:8020 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused)

 

그래서 다른 참고 자료들을 봤을때, 반드시 beeline 을 통해서만 hive  쿼리를 실행해야 하는 모양이더라고요. 이것 만큼은 확실했습니다.

 

hive 홈 경로에서 단순히 bin/beeline 을 실행하고 sql 문을 실행하면 계속 아래와 같은 결과가 나타납니다.

 No current connection

 

 

2. beeline 설정과 실행

간단합니다. 우선 hive 를 설치한 홈 경로에서 (3.1.3 버전의 경우) conf 폴더 아래의 hive-site.xml 파일을 vim 등의 텍스트 에디터로 엽니다. 저는 vim 을 기준으로 말씀드리겠습니다.

vim 의 단축키 를 이용하겠습니다.

들어가자마자 슬래시(/) 를 입력한 뒤 hive.server2.thrift.bind.host 를 입력하고 엔터칩니다.

그럼 해당 키워드를 지닌 부분으로 바로 이동합니다

아마 처음에는 <value/> 이렇게만 되어있고 아무 값도 없을 겁니다. 이 부분에 hive 가 서비스 되고 있는 서버의 ip 주소를 입력해줍니다. 저의 경우 로컬에서 실행하고 있으므로 위와 같이 기입한 뒤 저장했습니다.

 

또한 hadoop 의 설정 파일 중 하나인 core-site.xml 에 다음과 같은 설정을 추가해줍니다.

<property>
  <name>hadoop.proxyuser.[username].groups</name>
  <value>*</value>
</property>
<property>
  <name>hadoop.proxyuser.[username].hosts</name>
  <value>*</value>
</property>

 

다음으로 spark 홈 경로에서 sbin 폴더 밑의 start-thriftserver.sh 를 실행합니다 (이 부분은 실제로 꼭 필요한 단계인지 아닌지 잘 모르겠습니다)

 

그리고서 hive 홈에서 bin/beeline -u jdbc:hive2://127.0.0.1:10000 을 입력하면

시작도 제대로 되고 잘 실행됩니다.

 

만약 위와 같은 설정을 하지 않고 하면?

WARN jdbc.HiveConnection: Failed to connect to localhost:10000
Error: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: ~ is not allowed to impersonate hive (state=08S01,code=0)

와 같은 에러를 만나게 됩니다.

 

주의할 점이 한 가지 더있습니다. 다른 자료들을 찾아보면 종종 위와 같이 beeline을 실행하기 전에 hive server2 를 먼저 실행하라며 다음과 같은 명령을 먼저 입력하라는 내용이 있는 경우가 있습니다.

hive --service hiveserver2

근데 이 명령을 실행한 뒤 beeline -u jdbc:hive2://127.0.0.1:10000 명령을 입력해 실행하는 경우에도 위와 같은 에러를 만나게 되니 주의해야 합니다.

 

 

*참고자료

https://www.gooper.com/ss/bigdata/2963 

https://github.com/chuqbach/Big-Data-Installation/issues/2

https://thebook.io/006908/part02/ch05/03/03/02-01/

https://wikidocs.net/25252

 

*별개로 괜찮은 hiveserver2, beeline 관련 자료

https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-BeelineCommandOptions