본문 바로가기

Study/class note

하둡 / 하이브 설치

42 하이브 설치

하이브는 페이스북(현 메타)에서 만든 NoSQL입니다.

NoSQL은 자바를 몰라도 SQL과 같은 언어로 하둡의 데이터를 검색하게 해주는 프로그램입니다.

 

"자바를 몰라도 rdbms 에 익숙한 데이터 분석가들을 위해서 SQL을 이용해서 하둡의 멥리듀싱을 지원하는 프로그래밍 "

 

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

(모바텀 root로 접속해 시스템을 올렸습니다.)

[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

 

 

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

[root@centos ~]# chmod 777 hive-0.12.0.tar.gz
[root@centos ~]# chown -R oracle:oracle hive-0.12.0.tar.gz
[root@centos ~]# ls -l hive-0.12.0.tar.gz
-rwxrwxrwx. 1 oracle oracle 81288181  3월 23 14:14 hive-0.12.0.tar.gz

 


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

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

mv해도 상관없음.

 


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



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

(base) [oracle@centos ~]$ cd hive-0.12.0/
(base) [oracle@centos hive-0.12.0]$ pwd
/home/oracle/hive-0.12.0
(base) [oracle@centos hive-0.12.0]$ ls
LICENSE  README.txt         bin   docs      hcatalog  scripts
NOTICE   RELEASE_NOTES.txt  conf  examples  lib       src

bin디렉토리에 하이브 실행파일이 들어있음.

 

다시 홈디렉토리로 돌아가서 .bash_profile을 여세요.

(base) [oracle@centos ~]$ cd ~
(base) [oracle@centos ~]$ pwd
/home/oracle
(base) [oracle@centos ~]$ ls -al .bash_profile
-rw-r--r--. 1 oracle oracle 473  3월 22 16:31 .bash_profile
(base) [oracle@centos ~]$ vi .bash_profile


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

#==================================
export  HIVE_HOME=/home/oracle/hive-0.12.0
export PATH=$HIVE_HOME/bin:$PATH
#==================================

 


7.   .bash_profile 을 수행합니다.       

(base) [oracle@centos ~]$ source .bash_profile
(base) [oracle@centos ~]$ echo $HIVE_HOME
/home/oracle/hive-0.12.0

echo $HIVE_HOME 했을 때 아무것도 나오지 않으면 . .bash_profile 로 해보세요. 그래도 안되면 제대로 수행되지 않은 것입니다.

 


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>

 


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

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 ;

데이터타입만 지정해주고 크기는 지정해주지 않아도 됩니다.

hive> 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 ;
OK
Time taken: 2.799 seconds

 

 

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 /user/oracle
-rw-r--r--   3 oracle supergroup      11703 2022-03-23 14:01 /user/oracle/Case.csv
-rw-r--r--   3 oracle supergroup        102 2022-03-23 14:59 /user/oracle/dept2.csv
-rw-r--r--   3 oracle supergroup        679 2022-03-23 12:12 /user/oracle/emp.csv
-rw-r--r--   3 oracle supergroup        633 2022-03-23 13:49 /user/oracle/emp100.csv
-rw-r--r--   3 oracle supergroup        633 2022-03-23 14:59 /user/oracle/emp2.csv



11. 테이블 만든 터미널 창으로 돌아와서 하둡 파일 시스템의 emp2.csv 를  하이브 테이블 emp 에 입력합니다

hive> load  data  inpath  '/user/oracle/emp2.csv'  overwrite   into   table  emp ;
Loading data to table default.emp
Table default.emp stats: [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 633, raw_data_size: 0]
OK
Time taken: 0.195 seconds

hive> select * from emp;
OK
7839    KING    PRESIDENT       NULL    1981-11-17      5000    NULL    10
7698    BLAKE   MANAGER 7839    1981-05-01      2850    NULL    30
7782    CLARK   MANAGER 7839    1981-05-09      2450    NULL    10
7566    JONES   MANAGER 7839    1981-04-01      2975    NULL    20
7654    MARTIN  SALESMAN        7698    1981-09-10      1250    1400    30
7499    ALLEN   SALESMAN        7698    1981-02-11      1600    300     30
7844    TURNER  SALESMAN        7698    1981-08-21      1500    0       30
7900    JAMES   CLERK   7698    1981-12-11      950     NULL    30
7521    WARD    SALESMAN        7698    1981-02-23      1250    500     30
7902    FORD    ANALYST 7566    1981-12-11      3000    NULL    20
7369    SMITH   CLERK   7902    1980-12-09      800     NULL    20
7788    SCOTT   ANALYST 7566    1982-12-22      3000    NULL    20
7876    ADAMS   CLERK   7788    1983-01-15      1100    NULL    20
7934    MILLER  CLERK   7782    1982-01-11      1300    NULL    10
Time taken: 0.054 seconds, Fetched: 14 row(s)

 

 

+) kill 시킬때 -9옵션은 강제 종료입니다.

$ kill -9 프로세서번호

 

 

 

반응형