Hadoop 환경변수 설정
~/.bashrc 수정
[root@localhost ~]# hadoop fs -mkdir /tmp
mkdir: `/tmp': File exists
앞으로 이렇게 'hadoop'으로 접근 가능
기본적인 HDFS의 파일을 조작하기 위해서 hadoop fs 또는 hdfs dfs 커맨드를 사용한다.
우리는 hadoop 경로 설정해 주었으니 hadoop fs 로 사용 가능
-mkdir
[root@localhost ~]# hadoop fs -mkdir -p /user/kimnayoung/hadoop_edu/test
-p : 존재하지 않는 중간의 디렉토리를 자동으로 생성
-ls
[root@localhost ~]# hadoop fs -ls -R /user
-R : /user 하위의 모든 폴더 보여주기
-put
[root@localhost hadoop-3.3.6]# hadoop fs -put LICENSE.txt /user/kimnayoung/hadoop_edu/test
[root@localhost hadoop-3.3.6]# hadoop fs -ls /user/kimnayoung/hadoop_edu/test
Found 1 items
-rw-r--r-- 1 root supergroup 15217 2024-03-06 14:28 /user/kimnayoung/hadoop_edu/test/LICENSE.txt
LICENSE.txt를 /user/kimnayoung/hadoop_edu/test 폴더에 넣기, 들어간 것 확인 가능
-copyFromLocal
[root@localhost ~]# hadoop fs -copyFromLocal ~/test1 /user/kimnayoung/hadoop_edu/test
[root@localhost ~]# hadoop fs -ls /user/kimnayoung/hadoop_edu/test
Found 2 items
-rw-r--r-- 1 root supergroup 15217 2024-03-06 14:28 /user/kimnayoung/hadoop_edu/test/LICENSE.txt
-rw-r--r-- 1 root supergroup 12 2024-03-06 14:35 /user/kimnayoung/hadoop_edu/test/test1
[root@localhost ~]# hadoop fs -cat /user/kimnayoung/hadoop_edu/test/test1
hello world
-copyFromLocal : 로컬에서 hdfs로 파일 복사
-copyToLocal : hdfs에서 로컬로 파일 복사
-get
[root@localhost ~]# hadoop fs -get /user/kimnayoung/hadoop_edu/test ~/
[root@localhost ~]# ls
anaconda-ks.cfg 'jdk-11.0 (1).21_linux-x64_bin' 다운로드 사진
hadoop-3.3.6 jdk-11.0.21 문서 서식
hadoop-3.3.6.tar.gz test 바탕화면 음악
hdfs 공개 비디오
[root@localhost ~]# ls test/
LICENSE.txt test1
-cp
[root@localhost ~]# hadoop fs -cp /user/root/input /user/kimnayoung/hadoop_edu/test
/user/root/input 폴더 /user/kimnayoung/hadoop_edu/test 에 복사
-count
[root@localhost ~]# hadoop fs -count -v /
DIR_COUNT FILE_COUNT CONTENT_SIZE PATHNAME
22 48 1362091 /
디렉터리, 파일 개수, 컨텐트 사이즈 세기
-getmerge
[root@localhost hadoop-3.3.6]# hadoop fs -getmerge /user/kimnayoung/hadoop_edu/test/input ~/merged_file.txt
[root@localhost hadoop-3.3.6]# tail ~/merged_file.txt
hadoop fs -getmerge [hdfs경로] [로컬디렉토리]
hdfs에 나누어 저장되어 있는 파일들을 합쳐서 로컬디렉토리 및 파일에 저장
'Data Engineering > Hadoop' 카테고리의 다른 글
[Hadoop] MapReduce 실행 중 Error: org.apache.hadoop.hdfs.BlockMissingException (0) | 2024.03.27 |
---|---|
[Hadoop] Hadoop Streaming (0) | 2024.03.07 |
[Hadoop] Python으로 MapReduce 구현하기 (0) | 2024.03.07 |
[Hadoop] Java로 MapReduce 구현하기 (1) | 2024.03.06 |
[Hadoop] Hadoop 다운로드 및 환경설정 (0) | 2024.03.05 |