Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1.

Biên dịch và chạy chương trình MapReduce


 Mở cửa sổ lệnh dưới quyền Administrator.
 Khởi động các tiến trình hadoop: chạy start-all.cmd
 Chuyển vào thư mục hiện hành
cd C:\hadoop\ShortestPath

 Khai báo biến môi trường chỉ đường dẫn


set HADOOP_LIB=c:\hadoop\hadoop-2.6.0\share\hadoop
set HADOOP_CLASSPATH=%HADOOP_LIB%\mapreduce\hadoop-
mapreduce-client-core-2.6.0.jar;%HADOOP_LIB%\common\hadoop-common-
2.6.0.jar;

 Biên dịch mã nguồn java thành các file classes\*.class


C:\hadoop\ShortestPath> md classes
C:\hadoop\ShortestPath> javac -classpath %HADOOP_CLASSPATH% -d
classes *.java
C:\hadoop\ShortestPath> dir classes

 Xóa file *.jar nếu đã có trước đó


C:\hadoop\ShortestPath> del ShortestPathXYZ.jar

 Đóng gói file *. jar


C:\hadoop\ShortestPath> jar -cvf ShortestPathXYZ.jar -C classes .

 Xóa thư mục /inputXYZ nếu đã có, tạo mới và chép dữ liệu vào
C:\hadoop\ShortestPath> hadoop fs -rm -r /inputXYZ
C:\hadoop\ShortestPath> hadoop fs -mkdir /inputXYZ
C:\hadoop\ShortestPath> hadoop fs -put input.txt /inputXYZ
C:\hadoop\ShortestPath> hadoop fs -ls /inputXYZ

 Xóa thư mục /outputXYZ nếu đã có


C:\hadoop\ShortestPath> hadoop fs -rm –r /output*

 Chạy chương trình Mapreduce với dữ liệu trong thư mục /inputXYZ, kết quả xuất
ra /outputXYZ
C:\hadoop\ShortestPath> hadoop jar ShortestPathXYZ.jar
ShortestPath /inputXYZ /outputXYZ

Quá trình Map/Reduce sẽ lặp đi lặp lại nhiều lần. Kết quả của Map sẽ là input cho
Reduce.
 Xem kết quả trong /outputXYZ
c:\hadoop\MapReduceShortestPath>hadoop fs -ls /
Found 10 items
drwxr-xr-x - Administrator supergroup 0 2020-06-20 09:41 /inputXYZ
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:15 /outputXYZ
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:12 /outputXYZ-0
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:12 /outputXYZ-1
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:13 /outputXYZ-2
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:13 /outputXYZ-3
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:14 /outputXYZ-4
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:14 /outputXYZ-5
drwxr-xr-x - Administrator supergroup 0 2020-06-20 10:15 /outputXYZ-6
drwx------ - Administrator supergroup 0 2020-05-30 20:45 /tmp

C:\hadoop\ShortestPath> hadoop fs -ls /outputXYZ


C:\hadoop\ShortestPath> hadoop fs -cat /outputXYZ/part-00000
Kết quả
hadoop fs -get /outputXYZ/part-00000 copyfromhdfs

You might also like