Hive

[Hive] Hive 3.1.2 설치 (CentOS7, metastore - PostgreSQL)

heed159 2022. 3. 16. 11:05

Hive 3.1.2

 

CenOS7에 Hive를 설치해보려고 한다. metastore는 PostgreSQL.

 

Local metastore는 Hive와 같은 JVM에서 동작한다. 메타 데이터는 외부의 RDBMS에 저장되며 여러 사용자가 동시에 접근 가능하다.

Embedded metastore(derby)는 한번에 한 명의 유저만 접근이 가능하기 때문에 주로 테스트 용도로 쓰인다.

이 글에서는 여러 사용자가 사용할 수 있는 Local metastore(PostgreSQL)를 사용하여 Hive를 설치하려고 한다.

 

 

 

<PostgreSQL>

 

설치파일 다운로드 후 압축 풀기

[hadoop@node3 ~]$ sudo yum install -y postgresql11-server postgresql11-contrib

 

 

PostgreSQL 초기화

[hadoop@node3 ~]$ sudo /usr/pgsql-11/bin/postgresql-11-setup initdb

 

 

PostgreSQL 구동

[hadoop@node3 ~]$ sudo systemctl start postgresql-11

 

 

서버가 다시 시작될 때마다 PostgreSQL 서비스를 자동으로 시작해주기 위한 설정을 해준다.

[hadoop@node3 ~]$ sudo systemctl enable postgresql-11

 

 

PostgreSQL에 접속하여 hive유저와 비밀번호를 설정해준다.

[hadoop@node3 ~]$ sudo -u postgres psql
[sudo] hadoop의 암호:
could not change directory to "/home/hadoop": 허가 거부
psql (11.15)
Type "help" for help.

postgres=# CREATE USER hive SUPERUSER;
CREATE ROLE
postgres=# ALTER USER hive WITH PASSWORD 'postgres';  // PASSOWORD는 임의로 설정
ALTER ROLE

 

 

'metastore'라는 database 생성 및 hive 유저에게 권한을 부여하고 'UTF-8' 타입을 지정한다.

postgres=# CREATE DATABASE 'metastore' WITH OWNER hive ENCODING WITH 'UTF8' template template0;
CREATE DATABASE
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 metastore | hive     | UTF8     | ko_KR.UTF-8 | ko_KR.UTF-8 |
 postgres  | postgres | UTF8     | ko_KR.UTF-8 | ko_KR.UTF-8 |
 template0 | postgres | UTF8     | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

 

 

외부에서 접근이 가능할 수 있도록 postgres.conf 수정해준다.

[hadoop@node3 pgsql-11]$ sudo vi /var/lib/pgsql/11/data/postgresql.conf


#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp'  # comma-separated list of directories
                                        # (change requires restart)

 

 

pg_hba.conf  수정

[hadoop@node3 pgsql-11]$ sudo vi /var/lib/pgsql/11/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident
host    all             all             0.0.0.0/0               trust

 

 

PostgreSQL을 재시작해준다.

[hadoop@node3 ~]$ sudo systemctl restart postgresql-11

 

 

 

<HIVE>

 

 

Hive 설치파일 다운로드 및 압축해제

[hadoop@node1 ~]$ wget 'https://mirror.navercorp.com/apache/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz'
[hadoop@node1 ~]$ tar zxvf apache-hive-3.1.2-bin.tar.gz

 

 

Hive 구동을 위한 HIVE_HOME 환경변수 설정 및 PATH를 잡아준다.

[hadoop@node1 ~]$ vi /etc/profile


export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64
export ZOOKEEPER_HOME=/home/zookeeper/apache-zookeeper-3.6.3-bin
export HADOOP_HOME=/home/hadoop/hadoop-3.2.1
export HIVE_HOME=/home/hadoop/apache-hive-3.1.2-bin
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HIVE_HOME/bin
export CLASS_PATH="."
export GCC_PATH='/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include'

[hadoop@node1 ~]$ source /etc/profile //변경된 설정 적용

 

 

PostgreSQL JDBC 드라이버 다운로드 후 Hive 라이브러리 경로로 추가한다.

[hadoop@node1 ~]$ wget 'https://jdbc.postgresql.org/download/postgresql-42.2.18.jre6.jar'
[hadoop@node1 ~]$ mv postgresql-42.2.18.jre6.jar /$HIVE_HOME/lib

 

 

<hive-site.xml>

본인은 hive가 구동되는 서버와 postgreSQL이 구동되는 서버가 다르기 때문에 postgreSQL의 IP를 적어주었다. 이후 hive의 계정 및 패스워드를 적어준다. (메타스토어 관련 등록 정보 추가)

[hadoop@node1 conf]$ vi hive-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
        <property>
                <name>hive.metastore.local</name>
                <value>false</value>
        </property>
        <property>
                <name>javax.jdo.option.ConnectionURL</name>
                <value>jdbc:postgresql://IP_ADDRESS:5432/metastore</value>
        </property>
        <property>
                <name>javax.jdo.option.ConnectionDriverName</name>
                <value>org.postgresql.Driver</value>
        </property>
        <property>
                <name>javax.jdo.option.ConnectionUserName</name>
                <value>hive</value>
        </property>
        <property>
                <name>javax.jdo.option.ConnectionPassword</name>
                <value>postgres</value>
        </property>
        <property>
                <name>hive.metastore.warehouse.dir</name>
                <value>/user/hive/warehouse</value>
        </property>
        <property>
                <name>hive.server2.enable.doAs</name>
                <value>true</value>
        </property>
        <property>
                <name>hive.server2.authentication</name>
                <value>NONE</value>
        </property>
</configuration>

 

 

Hive 디렉터리 생성 및 쓰기 권한 부여

[hadoop@node1 conf]$ hdfs dfs mkdir -p /user/hive/warehouse
[hadoop@node1 conf]$ hdfs dfs -ls /user/hive
Found 1 items
drwxr-xr-x   - hadoop supergroup          0 2022-03-15 10:11 /user/hive/warehouse

[hadoop@node1 conf]$ hdfs dfs -chmod g+w /user/hive/warehouse
[hadoop@node1 conf]$ hdfs dfs -ls /user/hive
Found 1 items
drwxrwxr-x   - hadoop supergroup          0 2022-03-15 10:57 /user/hive/warehouse

 

 

메타스토어 초기화

[hadoop@node1 apache-hive-3.1.2-bin]$ bin/schematool -initSchema -dbType postgres

 

 

Hive 실행하여 정상적으로 구동되면 성공이다. 현재는 테스트를 위한 database를 만들어준 상태이다. (기본 default)

[hadoop@node1 apache-hive-3.1.2-bin]$ hive
which: no hbase in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.el7_9.x86_64/bin:/home/zookeeper/apache-zookeeper-3.6.3-bin/bin:/home/hadoop/hadoop-3.2.1/bin:/home/hadoop/hadoop-3.2.1/sbin:/home/hadoop/apache-hive-3.1.2-bin/bin:/home/hadoop/hadoop-3.2.1/bin:/home/hadoop/.local/bin:/home/hadoop/bin)
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]
Hive Session ID = adec0466-9767-46d0-aad5-3577790fefa6

Logging initialized using configuration in jar:file:/home/hadoop/apache-hive-3.1.2-bin/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true
Hive Session ID = b3f5b36f-8762-4f45-b2bf-6277526c1504
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
l0
st
Time taken: 1.441 seconds, Fetched: 3 row(s)