celina의 이것저것

[Hadoop] wordcount 본문

대학생활/빅데이터

[Hadoop] wordcount

celinayk 2024. 4. 4. 15:08
반응형

namenode, datanode, secondarynamenode를 다 켜고

start-yarn.sh로 yarn을 켠다

그러면 jps눌렀을때 리소스매니저랑 노드매니저까지 총 6개 뜨면 성공

 

그리고 192.168.0.100:8088으로 들어가면 hadoop사이트 들어가짐

https://hadoop.apache.org/docs/r2.10.2/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html

 

Apache Hadoop 2.10.2 – MapReduce Tutorial

<!--- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or a

hadoop.apache.org

 

vi ~/.bashrc창 열어서 자바 경로 설정을 해준다

export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar

 

그리고 source ~/.bashrc 실행한다

 

WordCount.java파일을 hadoop밑에 생성한다

 

[root@localhost hadoop] 경로에서

hadoop com.sun.tools.javac.Main WordCount.java
jar cf wc.jar WordCount*.class

하면 wc.jar파일이 뜬다

 

아무데나 simpletest.txt파일을 만들고 (이건 local에 생성한거임)

이제 이걸 hdfs에 업로드를 해야하는데

디렉터리가 없어서 하나만들고 hdfs dfs -mkdir /test2

로컬에서 hdfs로 파일을 올린다

hdfs dfs -copyFromLocal SimpleTest.txt /test2/

 

그리고 /root/hadoop/share/hadoop/mapreduce경로로 가서

hadoop jar hadoop-mapreduce-examples-2.10.2.jar wordcount /test2 /output2

이렇게 실행 명령어를 입력한다

test2는 input경로이고 output2는 output할 경로를 지정하면 된다

그러면 그 192.168.0.100:50070에 들어가면 output2라는게 생성이되어있고

 

hdfs dfs -cat /output2/part-r-00000

이걸 입력하면

Class 1
Hadoop 3
Welcome 1
bad 1
good 1
is 2
to 1

이렇게 wordcount가 된

 

+

hadoop jar wc.jar WordCount /user/joe/wordcount/input /user/joe/wordcount/output
                                                  input path                       output path

 

wc.jar WordCount 이건 뭐지?

wc.jar는 자바파일 실행할때 그 이름이고

WordCount는 그 파일에 존재하는 클래스이름

'대학생활 > 빅데이터' 카테고리의 다른 글

[Spark]  (0) 2024.05.09
[HBase]  (0) 2024.04.16
[Hadoop]  (0) 2024.04.02
[Hadoop]  (0) 2024.03.28
[Kafka] 영화 데이터 전달  (0) 2024.03.19
Comments