반응형

Docker 를 통한 Hive 실습환경 구축 및 간단 예제

 

본 포스팅에서는 Hive 핵심정리 (다융 두 저, 에이콘 출판사) 의 3장 예제를 Docker 를 이용해 실습해 보았다. 

 

1. Docker 설치 

2. Apache Hive 2.3.2 docker container 다운로드 (https://github.com/big-data-europe/docker-hive)

3. "docker-compose.yml" 파일에서 코드 샘플 경로 마운팅 (C:\workspace\HiveBook\HiveEssentials-master\scripts 을 container 의 /HiveBook 폴더로 마운트) 샘플 코드는 Hive 핵심정리 (에이콘 출판사) 샘플코드 (https://github.com/willddy/HiveEssentials)를 활용하였음.

 

- 샘플코드를 container 에 mount 하기 위해서는 아래 hive-server 에서 volumes 으로 경로를지정하면됨

version: "3" 

services: 
  namenode: 
    image: bde2020/hadoop-namenode:2.0.0-hadoop2.7.4-java8 
    volumes: 
      - namenode:/hadoop/dfs/name 
    environment: 
      - CLUSTER_NAME=test 
    env_file: 
      - ./hadoop-hive.env 
    ports: 
      - "50070:50070" 
  datanode: 
    image: bde2020/hadoop-datanode:2.0.0-hadoop2.7.4-java8 
    volumes: 
      - datanode:/hadoop/dfs/data 
    env_file: 
      - ./hadoop-hive.env 
    environment: 
      SERVICE_PRECONDITION: "namenode:50070" 
    ports: 
      - "50075:50075" 
  hive-server: 
    image: bde2020/hive:2.3.2-postgresql-metastore 
    env_file: 
      - ./hadoop-hive.env 
    environment: 
      HIVE_CORE_CONF_javax_jdo_option_ConnectionURL: "jdbc:postgresql://hive-metastore/metastore" 
      SERVICE_PRECONDITION: "hive-metastore:9083" 
    ports: 
      - "10000:10000" 
    volumes: 
      - C:\workspace\HiveBook\HiveEssentials-master\scripts:/HiveBook 
  hive-metastore: 
    image: bde2020/hive:2.3.2-postgresql-metastore 
    env_file: 
      - ./hadoop-hive.env 
    command: /opt/hive/bin/hive --service metastore 
    environment: 
      SERVICE_PRECONDITION: "namenode:50070 datanode:50075 hive-metastore-postgresql:5432" 
    ports: 
      - "9083:9083" 
  hive-metastore-postgresql: 
    image: bde2020/hive-metastore-postgresql:2.3.0 
  presto-coordinator: 
    image: shawnzhu/prestodb:0.181 
    ports: 
      - "8080:8080" 

volumes: 
  namenode: 
  datanode:

 

4. hive-server 실행

docker-compose up -d
docker-compose exec hive-server bash

 

docker-compose up -d 는 각각의 docker-compose.yml 에 위치한 container 를 background 실행하는 명령어

 

The docker-compose up command aggregates the output of each container (essentially running docker-compose logs -f). When the command exits, all containers are stopped. Running docker-compose up -d starts the containers in the background and leaves them running.

 

Command Line Interface (cli) 에서 실행

 

1. beeline으로 실행하기

 

/opt/hive/bin/beeline -u jdbc:hive2://localhost:10000

 

2. hive 로 실행하기

hive

 

Hive cli 의 경우 하이브 클라이언트는 하이브가 설치된 동일한 장비여야한다. 하지만 비라인의 경우 하이브 서버를 JDBC 커넥션으로 연결하고 클라이언트와 동일 장비에 하이브 라이브러리를 설치할 필요가 없다. 따라서 비라인은 하둡 클러스터 바깥에서 원격으로 실행할 수 있다. 이외의 다양한 hive client 들에 대한 설명은 https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients에서 찾아볼 수 있다. 

 

예를 들어, beeline 으로 실행하면 아래와 같은 명령어와 함께 beeline 커맨드가 실행된다.

 

Connecting to jdbc:hive2://localhost:10000 
Connected to: Apache Hive (version 2.3.2) 
Driver: Hive JDBC (version 2.3.2) 
Transaction isolation: TRANSACTION_REPEATABLE_READ 
Beeline version 2.3.2 by Apache Hive 
0: jdbc:hive2://localhost:10000>

 

sample code 를 mounting 했기 때문에 아래 경로에서 파일을 확인할 수 있다.

 

/HiveBook/Chapter_03/employee.txt

더보기

Michael|Montreal,Toronto|Male,30|DB:80|Product:DeveloperLead
Will|Montreal|Male,35|Perl:85|Product:Lead,Test:Lead
Shelley|New York|Female,27|Python:80|Test:Lead,COE:Architect
Lucy|Vancouver|Female,57|Sales:89,HR:94|Sales:Lead

Table 생성 및 데이터 삽입

CREATE TABLE employee
(
  name string,
  work_place ARRAY<string>,
  sex_age STRUCT<sex:string,age:int>,
  skills_score MAP<string,int>,
  depart_title MAP<STRING,ARRAY<STRING>>
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':';

--Verify tables creations run in Beeline
!table employee

--Load data
LOAD DATA LOCAL INPATH '/HiveBook/Chapter_03/employee.txt' OVERWRITE INTO TABLE employee;

--Query the whole table
SELECT * FROM employee;

반응형
반응형