티스토리 뷰

728x90
반응형

 

[hadoop] 1. ubuntu 18.04에 하둡(Hadoop) 설치하기
https://domdom.tistory.com/524
  
[hadoop] 2. 로컬에 있는 파일을 HDFS에 전송하기
https://domdom.tistory.com/525

[hadoop] 3. apache hadoop 위에 spark 설치하기
https://domdom.tistory.com/526

[hadoop] 4. apache hadoop hdfs와 상호작용하는 hive 설치하기
https://domdom.tistory.com/527

 

 

 

 

 

1. apache sqoop 다운로드 사이트에 들어가서 최신버전을 wget을 통해 다운받습니다

https://archive.apache.org/dist/sqoop/

 

Index of /dist/sqoop

 

archive.apache.org

 

현재 최신 버전은 1.4.7이네요.

bin 압축파일 링크를 복사하여 옵니다.

wget https://archive.apache.org/dist/sqoop/1.4.7/sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz

https://archive.apache.org/dist/sqoop/1.4.7/

 

Index of /dist/sqoop/1.4.7

 

archive.apache.org

 

 

2. 다운받은 압축파일을 압축해제시켜줍니다.

tar –xvf sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz

 

 

3. 심볼릭 링크를 설정해줍니다.

ln -s sqoop-1.4.7.bin__hadoop-2.6.0 sqoop

 

4. ~/.bashrc에 환경변수를 설정해줍니다.

vi ~/.bashrc
export SQOOP_HOME=/root/sqoop
export SQOOP_CONF_DIR=$SQOOP_HOME/conf

export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin:$SQOOP_HOME/bin

환경변수 설정을 적용합니다.

source ~/.bashrc

 

5. 스쿱 설정파일 sqoop-env.sh 파일에 hadoop 설정을 추가해야 합니다.

아래와 같이 파일을 복사하고, 복사한 파일을 수정합니다.

cp sqoop/conf/sqoop-env-template.sh sqoop/conf/sqoop-env.sh
vi sqoop/conf/sqoop-env.sh
export HADOOP_COMMON_HOME=/root/hadoop-3.3.4
export HADOOP_MAPRED_HOME=/root/hadoop-3.3.4
export HIVE_HOME=/root/apache-hive-3.1.3-bin

 

6. 이제 스쿱에 연동할 postgreSQL 드라이버를 다운로드 받습니다.

*sqoop의 디볼트 DBMS는 my-sql이나, 저는 postgreSQL로 변경하여 사용할 예정입니다

 

https://jdbc.postgresql.org/download/

 

Download | pgJDBC

Download Binary JAR file downloads of the JDBC driver are available here and the current version with Maven Repository. Because Java is platform neutral, it is a simple process of just downloading the appropriate JAR file and dropping it into your classpat

jdbc.postgresql.org

 

 

다운로드 받은 jar파일을 sqoop/lib에다 넣어준뒤, sqoop jar파일을 hadoop lib 디렉토리에 복사시켜줍니다.

cp sqoop-1.4.7.jar /root/hadoop-3.3.4/share/hadoop/tools/lib/

 

 

7. sqoop import 수행 시 NoClassDefFoundError가 생기지 않도록

아래링크에서 commons-lang3-3.12.0-bin.tar.gz 바이너리파일을 다운받습니다.

https://commons.apache.org/proper/commons-lang/download_lang.cgi

 

Lang – Download Apache Commons Lang

Download Apache Commons Lang Using a Mirror We recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hour

commons.apache.org

 

 

다운받은 압축파일을 압축해제하고, commons-lang jar파일을 sqoop/lib에 복사합니다.

그 후 겹치는 기존파일의 이름을 변경해주세요.

tar –xvf commons-lang3-3.12.0-bin.tar.gz
cp commons-lang3-3.12.0.jar /root/sqoop/lib
mv commons-lang3-3.4.jar commons-lang3-3.4.jar.backup

 

 

8. sqoop 명령어로 postgresql에 커넥트합니다.

먼저 sqoop이 정상적으로 설치되었는지 확인합니다.

아래 sqoop help 명령어를 입력했을 때, 에러가 나지 않으면 설치가 정상적으로 완료된 것입니다.

sqoop help

 

postgresql에 접속하여 명령어를 입력해봅니다.

에러없이 연결이 잘 되는 것을 확인합니다.

sqoop –import --connect jdbc:postgresql://ubuntu/postgres?schema=public --table tmp_table --m 1 --username postgres -- password 1234

 

sqoop에서 postgresql로 연동이 완료되었으니,

이제 hadoop to postgreSQL로 데이터를 가져올 수 있습니다.

이 내용은 다음 게시물에 작성하도록 하겠습니다

 

728x90
반응형
댓글