====================================

== hive 구성품


Hive CLI : bin/hive 를 통해 실행하는 clinet 툴 (대화형)

MetaStore : 테이블, 파티션 정보를 저장하는 서버로 derby, rdbms 등과 연동되어 사용

HiveServer2 : 클라이언트(ex. beeline) 에게 hive 쿼리 interface 제공 (thrift rpc)

Beeline : HiveServer2에 접속하여 명령을 내릴 수 있는 client (Hive CLI 리모트 버전)

HCatalog : metastore 서버를 대체하는 서버로 pig, hive, mapreduce 같은 서로 다른 서비스간에 메타데이터를 공유 할수 있도록 해줌

WebHCat :  rest api for HCatalog (이전 이름 templeton)

hcat : HCatalog cli 툴 (대화형 아님)


** MetaStore/HCatalog 와 HiveServer2는 각자 DB와 통신 함.

  MetaStore와 HCatalog는 기본 리스닝 포트 9083 가 겹치는 것으로 보아 하나만 택하면 되는 것 같음



  


====================================

== mysql 5.7 설치


# apt-get install mysql-server

  (설치도중 root 암호 입력 : root로 입력)

# service mysql start

  (listening port : 3306)

  

  

** 참고. mysql 삭제

  # apt-get purge mysql*

  # apt-get autoremove


** 참고. apt-get list 새로 생성

  # apt-get clean

  # mv /var/lib/apt/lists /tmp

  # mkdir -p /var/lib/apt/lists/partial

  # apt-get clean

  # apt-get update


  


  

====================================

== hive 설치 - mysql, matastore



** hadoop 용 클라이언트 머신이 있다면

ssh 및 hadoop 바이너리 복사후 별도 설치 가능



## 압축 해제

# tar xvfz apache-hive-2.1.1-bin.tar.gz

# mv apache-hive-2.1.1-bin hive



## 환경 변수 추가 (~/.bashrc 혹은 /etc/bash.bashrc)

# vi ~/.bashrc

export HIVE_HOME="/root/hive"

export HADOOP_HOME="/root/hadoop-2.7.3"

export PATH=$HIVE_HOME/bin:$HADOOP_HOME/bin:$PATH



## hadoop 구동 및 폴더 생성 (컴 성능이 안좋아 yarn 없이 띄움)

# $HADOOP_HOME/sbin/start-dfs.sh

# $HADOOP_HOME/bin/hadoop fs -mkdir /tmp

# $HADOOP_HOME/bin/hadoop fs -mkdir -p /user/hive/warehouse

# $HADOOP_HOME/bin/hadoop fs -chmod g+w /tmp

# $HADOOP_HOME/bin/hadoop fs -chmod g+w /user/hive/warehouse



## hive 용 계정 및 database 생성

# mysql -u root -p

> show databases;

> create database metastore;

> grant all privileges on *.* to 'hive'@'localhost' identified by 'hive' with grant option;

> grant all privileges on *.* to 'hive'@'%' identified by 'hive' with grant option;

> grant all privileges on metastore.* to 'hive'@'%' identified by 'hive';

> flush privileges;

> select host from mysql.user where user='hive';



## hive mysql 설정

# vi conf/hive-site.xml

<configuration>

  <property>

    <name>javax.jdo.option.ConnectionURL</name>

    <value>jdbc:mysql://localhost:3306/metastore?createDatabaseIfNotExist=true&amp;useSSL=false</value>

  </property>

  <property>

    <name>javax.jdo.option.ConnectionDriverName</name>

    <value>com.mysql.jdbc.Driver</value>

  </property>

  <property>

    <name>javax.jdo.option.ConnectionUserName</name>

    <value>hive</value>

  </property>

  <property>

    <name>javax.jdo.option.ConnectionPassword</name>

    <value>hive</value>

  </property>

</configuration>


  ** 혹은 미리 생성 가능

    mysql --host=localhost --port=3306  -u root -proot metastore < scripts/metastore/upgrade/mysql/hive-schema-2.1.0.mysql

  ** &useSSL=false

    metastore 서비스 실행 시(# bin/hive --service metastore)

    아래 에러 메시지 방지용

    WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

  

## mysql connector/j jar 설치

  https://dev.mysql.com/downloads/connector/j/ 에서 mysql-connector-java-5.1.42.tar.gz 다운로드

# tar xvfz mysql-connector-java-5.1.42.tar.gz

# cp mysql-connector-java-5.1.42/mysql-connector-java-5.1.42-bin.jar hive/lib/



# bin/schematool -dbType mysql -info

  (설정된 mysql 정보 확인)

  

# bin/schematool -dbType mysql -initSchema --verbose

  (mysql 스키마 초기화)



## metastore 서버 시작 (9083 포트 리스닝)

# nohup bin/hive --service metastore 1>/dev/null 2>&1 &


## hiveserver2 실행 : 외부 클라이언트에서(ex. beeline) hive 쿼리 실행을 할 수 있도록 해주는 서버

# nohup bin/hive --service hiveserver2 1>/dev/null 2>&1 &



## beeline 실행하여 hiveserver2 접속

# bin/beeline -u jdbc:hive2://

  이후 bin/hive 처럼 명령 실행 가능. 

  

> show databases;

> show tables;

> !quit



  ** ip/port 사용시

  # bin/beeline -u jdbc:hive2://127.0.0.1:10000

  ip/port 지정하여 실행 가능하나 "User: root is not allowed to impersonate hive" 에러 발생 시 (root 계정으로 실행 했음)

  아래 설정 후 재시작 hiveserver2 재시작

  

  # vi conf/hive-site.xml 

    <configuration>

      <property>

        <name>hive.server2.enable.doAs</name>

        <value>false</value>

      </property>

    </configuration>


    true 면 OS 사용자를 사용자로 지정. (여러 사용자 권한 필요한 경우 사용)

    false 면 hive 시스템 사용자를 사용자로 지정


    

  


====================================

== hive 테스트


## 테이블 생성 테스트  

# bin/beeline -u jdbc:hive2://

> create table test (a varchar(100));

> show tables;

> describe test;

> !quit




  

====================================

== HCatalog

metastore 종료 후 시작 (기본 포트 겹침)

hive/hadoop 설정 감지하여 별도 설정 불필요 한 것으로 보임


## HCatalog 서버 시작

# cd hcatalog

# mkdir -p var/log

# sbin/hcat_server.sh start





====================================

== WebHCat (Templeton)

https://cwiki.apache.org/confluence/display/Hive/WebHCat


pass

 

 

 

 

 

====================================

== hive mapreduce 테스트


예제 파일 : cite75_99.txt (http://www.nber.org/patents/acite75_99.zip 다운로드 후 압축해제)


# bin/hive

> create table cite (citing int, cited int) row format delimited fields terminated by ',' stored as textfile;

> load data local inpath '/root/cite75_99.txt' overwrite into table cite;

> select count(*) from cite






====================================

## 정리


##서버 시작 및 종료 방법

hadoop 시작/종료


mysql 

  시작 : # service mysql start

  종료 : # service mysql stop


metastore

  시작 : # nohup bin/hive --service metastore 1>/dev/null 2>&1 &

  종료 : # pkill -9 -ef HiveMetaStore


hcatalog

  시작 : # hcatalog/sbin/hcat_server.sh start

  종료 : # hcatalog/sbin/hcat_server.sh stop


hiveserver2

  시작 : # nohup bin/hive --service hiveserver2 1>/dev/null 2>&1 &

  종료 : # pkill -9 -ef HiveServer2


beeline

  시작 : # bin/beeline -u jdbc:hive2://

    (# bin/beeline -u jdbc:hive2://127.0.0.1:10000)

  종료 : !quit


## port


mysql

  listen : 3306


hive cli

  established:

    3306 mysql 커넥션 4개

    쿼리 실행시 mapreduce 실행 시 client 처럼 hadoop port 접속

  

metastore/hcatalog

  listen :

    9083

  estalblished :

    3306 (mysql 커넥션 4개)

  

hiveserver2 

  listen :

    10000 (baseline 등 접속 용)

    10002 (웹)

  estalblished :

    3306 (mysql 커넥션 4개)

    9000 (hadoop NameNode 필요시만 접속)



webhcat

  listen : 

    50111