본문 바로가기
kubernetes

[kubernetes] Hive metastore 설치 및 설정 (hive-s3 connector for trino)

by Blue____ 2024. 2. 4.

이번 글에서는 VM 기반의 kubernetes 클러스터에서 hive-s3 connector를 사용하기 위해 설치되어야 할 Hive Metastore 설치를 진행 할 예정입니다. 이전 Trino - S3 연결 및 데이터(schema, table) 생성/조회 설정 글에서, Trino를 통해 hive-s3 catalog를 생성 해 S3에 올라온 CSV 데이터를 읽어오는 내용을 진행 했었습니다. 해당 글은 hive-s3 catalog를 생성하기 위한 table-schema인 Hive Metastore를 설치하는 과정과 내용을 설명할 예정입니다. 


 

현재 구축되어 있는 클러스터는 Hadoop(HDFS)를 Storage로 사용하지 않기 때문에 hdfs는 설치되어 있지 않으며, Storage는 S3(Object storage)를 사용합니다. 또한, Trino를 데이터의 query 용도로 사용할 예정이라 Hive 컴포넌트 중, Table-schema 역할을 할 Hivemetastore만 설치를 진행합니다. 

 

우선, 이번 글에서는 helm을 통해 Hivemetastore standalone을 설치 할 예정입니다. 먼저 helm repo 추가 및 업데이트를 진행합니다. 

 

$ helm repo add bigdata-gradiant https://gradiant.github.io/bigdata-charts/
$ helm repo update

$ helm search repo bigdata-gradiant

NAME CHART VERSION APP VERSION DESCRIPTION
bigdata-gradiant/hbase 0.1.6 2.0.1 HBase is an open-source non-relational distribu...
bigdata-gradiant/hdfs 0.1.10 2.7.7 The Apache Hadoop software library is a framewo...
bigdata-gradiant/hive 0.1.6 2.3.6 The Apache Hive ™ data warehouse software facil...
bigdata-gradiant/hive-metastore 0.1.3 2.3.6 The Apache Hive ™ data warehouse software facil...
bigdata-gradiant/jupyter 0.1.11 6.0.3 Helm for jupyter single server with pyspark sup...
bigdata-gradiant/kafka-connect-ui 0.1.0 0.9.7 Helm for Landoop/kafka-connect-ui
bigdata-gradiant/opentsdb 0.1.7 2.4.0 Store and serve massive amounts of time series ...
bigdata-gradiant/spark-standalone 0.1.0 2.4.4 Apache Spark™ is a unified analytics engine for...

 

이후, hive-metastore 차트의 values.yaml 파일을 저장/수정 진행합니다.

 

$helm show values bigdata-gradiant/hive-metastore > my-hms-values.yaml

## my-hms-values.yaml 수정

global:
 imageRegistry: {private registry를 사용한다면, 해당 주소를 입력해줍니다.}
 
 
postgresql: #hive-metastore의 DB는 postgresql로 설치됩니다.
 postgresqlUsername: hive  #postgresql username 설정 
 postgresqlPassword: hive  #postgresql p/w 설정
 postgresqlDatabase: metastore #postgresql DB 설정
 initdbScriptsConfigMap: hive-metastore-postgresql-init
 
image:
 repository: {registry}/jboothomas/hive-metastore-s3 #S3 connector를 포함하고 있는 image 필요 
 tag: v6
 pullPolicy: IfNotPresent
 
resources: {}
conf:
 hiveSite:
 hive_metastore_uris: thrift://hive-metastore:9083

 
persistence: #postgresql의 PV 설정을 위해 true로 설정
 enabled: true
 existingClaim: data-my-hms-postgresql-0 #아래에서 설정할 pv, pvc를 위한 claim 설정
 storageClass: ""
 accessModes:
 - ReadWriteOnce
 ..
 mountPath: /bitnami/hivemetastore
 podSecurityContext:
  enabled: true
  fsGroup: 1001
  runAsUser: 1001
 ..

 

위와 같이 values.yaml 파일 수정을 마무리 했으면 이제, namespaces 생성 및 helm install을 진행합니다. 

 

#hivemetastore namespace 생성
$ kubectl create namespace hivemetastore

# helm install
$ helm install my-hms -f my-hms-values.yaml bigdata-gradiant/hive-metastore -n hivemetastore

 

helm install을 하면, 설치는 진행이 되나, postgresql 팟이 running 상태로 진행이 되지 않을 것입니다. 그 이유는 위에서 설명했듯이 postgresql의 데이터를 저장할 pv를 설정해주지 않았기 때문입니다. 따라서, 아래와 같이 pv, pvc 설정을 진행해 줍니다. 

 

#hive metastore pv, pvc 설정

## hivemetastore-persistent-volume.yaml 파일 생성

apiVersion: v1
kind: PersistentVolume
metadata:
 namespace: hivemetastore
 name: hivemetastore-pv
 labels:
 name: hivemetastore
spec:
 storageClassName: hivemetastore
 capacity:
 storage: 4Gi
 volumeMode: Filesystem
 accessModes:
 - ReadWriteOnce
 claimRef:
 namespace: hivemetastore
 name: data-my-hms-postgresql-0 #위의 values.yaml에서 설정한 claim을 입력해줍니다.
 persistentVolumeReclaimPolicy: Delete
 hostPath:
 path: /data/hivemetastore/data  #서버의 mount path 입력해줍니다.
 type: DirectoryOrCreate

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: data-my-hms-postgresql-0 #위의 values.yaml에서 설정한 claim을 입력해줍니다.
 namespace: hivemetastore
spec:
 storageClassName: hivemetastore
 accessModes:
 - ReadWriteOnce
 resources:
 requests:
 storage: 2Gi

 

이제, 위처럼 작성한 pv, pvc 리소스 yaml 파일을 apply 진행해보겠습니다. 

 

$ kubectl apply -f hivemetastore-persistent-volume.yaml -n hivemetastore

$ kubectl get pv -n hivemetastore

NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
hivemetastore-pv 4Gi RWO Delete Bound hivemetastore/data-my-hms-postgresql-0 hivemetastore 26h

$ kubectl get pvc -n hivemetastore

NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-my-hms-postgresql-0 Bound hivemetastore-pv 4Gi RWO hivemetastore 26h

 

위처럼, 정상적으로 pv, pvc의 status가 Bound로 확인된다면 우선 pv, pvc 설정은 정상적으로 bound가 된것으로 확인이 된다고 보면 됩니다. 하지만 한가지 더 해주어야 할 것이 있습니다. 바로 mount가 될 서버의 디렉토리 권한 생성/변경을 해주어야 합니다. 그렇지 않으면 Permission error가 발생하게 됩니다. 

 

아래와 같이 mount가 될 서버(노드)에 접속해 mount path의 디렉토리 생성 및 권한을 변경해줍니다. 

[root@testwn001 /]# mkdir /data/hivemetastore/data
[root@testwn001 /]# chmod 747 /data/hivemetastore/data
[root@testwn001 /]# chown -R 1001:1001 /data/hivemetastore/data

 

이제 이전에 설치한 hivemetastore 팟들이 running으로 변경되는 것을 확인할 수 있을 겁니다. (변하지 않으면 helm uninstall 후, 다시 install 진행)

 

그러나, 몇 분후 다시 error가 발생하며 pod의 status가 error 상태에 빠지게 됩니다. 그 이유는 hivemetastore의 metastore.warehouse.dir 설정과 storage로 사용할 S3의 정보를 아직 입력해주지 않았기 때문입니다. 따라서, 아래와 같이 hivemetastore의 hive-metastore-0 에서 configmap을 수정으로 열어, 설정을 추가해줍니다. 

 

$kubectl -n hivemetastore edit configmap/my-hms-hive-metastore

## hive-site.xml .
data:
 hive-site.xml: |
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration>
 <configuration>
 <property>
 	<name>fs.defaultFS</name>
 	<value>s3a://{S3 경로}</value>
 </property>
 <property>
 	<name>fs.s3a.path.style.access</name>
 	<value>true</value>
 </property>
 <property>
 	<name>fs.s3a.access.key</name>
 	<value>{s3 access.key 입력}</value>
 </property>
 <property>
 	<name>fs.s3a.secret.key</name>
 	<value>{s3 secret.key 입력}</value>
 </property>
 <property>
	<name>fs.s3a.impl</name>
 	<value>org.apache.hadoop.fs.s3a.S3AFileSystem</value>
 </property>
 <property>
 	<name>fs.s3a.endpoint</name>
 	<value>http://{s3 endpoint 입력}</value>
 </property>
 <property>
 	<name>fs.s3a.fast.upload</name>
 	<value>true</value>
 </property>
 <property>
 	<name>datanucleus.autoCreateSchema</name>\n
 	<value>true</value>
 </property>
 <property>
 	<name>metastore.task.threads.always</name>
 	<value>org.apache.hadoop.hive.metastore.events.EventCleanerTask</value>
 </property>
 <property>
 	<name>metastore.expression.proxy</name>
 	<value>org.apache.hadoop.hive.metastore.DefaultPartitionExpressionProxy</value>
 </property>
 <property>
 	<name>javax.jdo.option.ConnectionDriverName</name>
 	<value>org.postgresql.Driver</value>
 </property>
 <property>
 	<name>javax.jdo.option.ConnectionURL</name>
 	<value>jdbc:postgresql://my-hms-postgresql/metastore</value> #이전의 postgresql의 주소와 DB 입력해줌
 </property>
 <property>
 	<name>javax.jdo.option.ConnectionUserName</name>
 	<value>hive</value> #username 입력해줌
 </property>
 <property>
 	<name>javax.jdo.option.ConnectionPassword</name>
 	<value>hive</value> #PW 입력해줌
 </property>
 <property>
 	<name>metastore.warehouse.dir</name>
 	<value>s3a://{S3 경로}/warehouse</value>
 </property>
 	</configuration>

 

그럼 이제, hivemetastore의 Pod 들의 상태를 다시 확인해보겠습니다. 

 

$ kubectl get pods -n hivemetastore

NAME READY STATUS RESTARTS AGE
my-hms-hive-metastore-0 1/1 Running 0 69m
my-hms-postgresql-0 1/1 Running 0 69m

 

모두, 정상적으로 Running 상태가 확인되며, hivemetastore의 log도 확인해보겠습니다. 

 

$ kubectl logs my-hms-hive-metastore-0

2023-11-10 07:02:03: Starting Hive Metastore Server
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.
class]
SLF4J: Found binding in [jar:file:/opt/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]
2023-11-10T07:02:05,070 INFO [main] org.apache.hadoop.hive.conf.HiveConf - Found configuration file file:/opt
/hive/conf/hive-site.xml
2023-11-10T07:02:06,474 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting HiveMetaStore
STARTUP_MSG: host = my-hms-hive-metastore-0.my-hms-hive-metastore.hivemetastore.svc.cluster.local/10.
244.4.130
STARTUP_MSG: args = []
STARTUP_MSG: version = 2.3.2
STARTUP_MSG: classpath = /opt/hive/conf:/opt/hive/lib/HikariCP-2.5.1.jar:/opt/hive/lib/RoaringBitmap-0.5.18.
jar:/opt/hive/lib/ST4-4.0.4.jar:/opt/hive/lib/accumulo-core-1.6.0.jar:/opt/h
...
************************************************************/
2023-11-10T07:02:06,493 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Starting hive metastore on
port
9083
2023-11-10T07:02:06,616 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - 0: Opening raw store with
implementation class:org.apache.hadoop.hive.metastore.ObjectStore
2023-11-10T07:04:15,574 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Added admin role in
metastore
2023-11-10T07:04:15,576 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Added public role in
metastore
2023-11-10T07:04:15,589 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - No user is added in admin
role,
since config is empty
2023-11-10T07:04:15,710 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Starting DB backed
MetaStore Server with SetUGI enabled
2023-11-10T07:04:15,716 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Started the new metaserver
on port [9083]...
2023-11-10T07:04:15,716 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Options.minWorkerThreads =
200
2023-11-10T07:04:15,716 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Options.maxWorkerThreads =
1000
2023-11-10T07:04:15,716 INFO [main] org.apache.hadoop.hive.metastore.HiveMetaStore - TCP keepalive = true

 

이제, 마지막으로 Hivemetastore Pod에 접속해 hive 접속이 정상적으로 이루어지는 확인을 해보며 이번 글을 마치겠습니다. 

 

root@my-hms-hive-metastore-0:/opt# hive

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.
class]
SLF4J: Found binding in [jar:file:/opt/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]
Logging initialized using configuration in jar:file:/opt/hive/lib/hive-common-2.3.2.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>

 

 

ref

- https://docs.starburst.io/latest/k8s/hms-configuration

 

Configuring the Hive Metastore Service in Kubernetes — Starburst Enterprise

Is the information on this page helpful? Yes No

docs.starburst.io

- https://blog.purestorage.com/purely-informational/hive-metastore-on-kubernetes-with-s3-external-table/

 

Hive-metastore on Kubernetes with S3 External Table

In this article, our experts will teahc you how to set up Hive-metastore on Kubernetes and then leverage external S3 data sets.

blog.purestorage.com

- https://jboothomas.medium.com/hive-metastore-on-k8s-with-s3-external-table-607102a11e56

 

Hive-metastore on K8S with S3 external table

In this blog I will cover how to setup Hive metastore on K8S and then leverage external S3 datasets.

jboothomas.medium.com