본문 바로가기

Linux 리눅스 & 하둡 & hive/Hive

Linux 내 하이브 설치

페이스 북에서 만든 NoSQL 
             ↓
		자바를 몰라도 SQL 같은 언어로 하둡의 데이터를 검색하게 해주는 프로그램 
		
예) Hive > select * from emp where job='SALESMAN';

하이브는 작은데이터 보다는 큰~ 데이터를 검색할 때 빛을 발합니다.!

하이브는 update, insert 안되고 오로지 조회만 가능합니다. 

 

설치 시작

1. 하이브 설치파일을 리눅스 시스템에 올립니다. 

하이브 설치 파일 다운로드 : https://drive.google.com/file/d/1m1KoO-l6DXq_iy4cE7fkgoFGisIyU9Eb/view

# 압축 풀지 말고 모바텀 (root 유저 로그인) 에 압축 파일 업로드 하기 


2.  하이브 설치파일의 권한을 777로 올리고 소유자로 oracle 유져로 변경합니다.

# 일단 파일 있는지 확인 
[root@centos ~]# ls -l hive-0.12.0.tar.gz
-rw-r--r--. 1 root root 81288181  3월 23 14:14 hive-0.12.0.tar.gz

[root@centos ~]# chmod 777 hive-0.12.0.tar.gz

[root@centos ~]# chown -R oracle:oracle hive-0.12.0.tar.gz



3. 하이브 설치파일을 /home/oracle 밑으로 복사합니다. 

[root@centos ~]# cp /root/hive-0.12.0.tar.gz /home/oracle/

또는 mv

[root@centos ~]# mv /root/hive-0.12.0.tar.gz  /home/oracle
[root@centos ~]# su - oracle
마지막 로그인: 수  3월 23 14:16:43 KST 2022 일시 pts/0
(base) [oracle@centos ~]$ ls -l hive-0.12.0.tar.gz
-rwxrwxrwx. 1 oracle oracle 81288181  3월 23 14:14 hive-0.12.0.tar.gz




4. oracle 유져로 로그인해서 하이브 설치 파일의 압축을 풉니다.

(base) [oracle@centos ~]$ tar xvzf hive-0.12.0.tar.gz



5. 하이브 홈 디렉토리가 생성되었는지 확인합니다. 

(base) [oracle@centos ~]$ ls  -ld   hive-0.12.0
drwxrwxr-x. 10 oracle oracle 182  3월 23 14:26 hive-0.12.0
# 여기서 소유자 oracle 인지 확인합니다~ 

# 하둡 파일 디렉토리 가보기 
(base) [oracle@centos ~]$ cd hive-0.12.0/
(base) [oracle@centos hive-0.12.0]$ pwd
/home/oracle/hive-0.12.0

# bin 디렉토리의 하둡 실행 파일들이 있습니다. 
(base) [oracle@centos hive-0.12.0]$ ls
LICENSE  README.txt         bin   docs      hcatalog  scripts
NOTICE   RELEASE_NOTES.txt  conf  examples  lib       src




6. oracle 유져의 환경 정보 파일인 .bash_profile 에 하둡 홈 디렉토리를 지정합니다.

(base) [oracle@centos ~]$ cd
(base) [oracle@centos ~]$ vi .bash_profile

맨 아래쪽에 아래의 명령어를 입력

#==================================
export  HIVE_HOME=/home/oracle/hive-0.12.0   # 하이브 홈디렉토리 위치 
export PATH=$HIVE_HOME/bin:$PATH             # 하이브 실행파일있는 bin 디렉토리 알려주기  
#==================================



7.   .bash_profile 을 수행합니다.

(base) [oracle@centos ~]$ source .bash_profile     
(base) [oracle@centos ~]$ echo $HIVE_HOME 
하이브 홈 디렉토리가 모여져야 합니다.
/home/oracle/hive-0.12.0



8. 하이브로 접속합니다.

(base) [oracle@centos ~]$ hive    

Logging initialized using configuration in jar:file:/home/oracle/hive-0.12.0/lib/hive-common-0.12.0.jar!/hive-log4j.properties
             
hive> show  tables ;

OK
Time taken: 7.914 seconds



9. hive 에 emp 테이블을 생성합니다.

# 마리아디비와 비슷하면서 다르다 (varchar 가 아닌 string , 숫자는 int) (대신 \r 없고 \n 만 있습니다) 
create table emp          
(empno int,  
ename string,
job string,
mgr int,
hiredate string,
sal int,
comm int,
deptno int)
row format delimited 
fields terminated by ','   
lines terminated by '\n'   
stored as textfile ;



# 지금 테이블 구조만 만든 상태 입니다. 
# 이제 데이터를 넣어주어야합니다~

10. 별도의 터미널 창을 열고 oracle 유져로 접속하여 하둡파일 시스템에 emp.csv 와 dept.csv 를 올립니다. 
-> 어디데이터? 하둡분산파일 시스템에 있는 데이터를 넣어주어야합니다. 

(base) [oracle@centos ~]$ hadoop fs -put emp.csv /user/oracle/emp2.csv
(base) [oracle@centos ~]$ hadoop fs -put dept.csv /user/oracle/dept2.csv
(base) [oracle@centos ~]$ hadoop  fs  -lsr



11. 테이블 만든 터미널 창으로 돌아와서 하둡 파일 시스템의 emp2.csv 를  하이브 테이블 emp 에 입력합니다
# 하둡은 마리와디비와는 다르게 공백은 널값으로 인식 해서 따로 바꾸어줄 필요는 없습니다. 

hive>  load  data  inpath  '/user/oracle/emp2.csv'  overwrite   into   table  emp ;

hive> select * from emp;



12. 이름과 월급을 조회합니다.

hive>  select ename, sal from emp;