Hadoop框架的核心设计就是:HDFS(Hadoop distribution file system)和MapReduce。适合有着超大数据集的程序。HDFS为海量数据提供了存储具有高容错性的特点并且设计用来部署在低廉的硬件上。MapReduce则为海量数据提供了计算。
利用WINDOWS连上Hadoop集群需要通过2个步骤。1.通过PUTTY等SSH软件连上远程服务器,将数据集及脚本程序上传至服务器(由于使用Windows系统,本地上传至服务器无法使用LINUX的SCP命令。在这里可以使用FileZilla软件上传)。2.通过服务器再将数据及脚本上传至集群。
Hadoop使用方法:1.通过hadoop fs -mkdir命令创建输入文件夹(es: hadoop fs -mkdir xxx/input/example); 2.放入输入文件(在服务器example文件夹下通过hadoop fs -put text* /xxx/input/example将包含text文件名的文件(*为正则表达)放入集群输入文件;3.查看文件是否放好:hadoop fs -ls /xxx/input/example; 4.本地测试手写的map及reduce程序(由于集群资源宝贵,或者会涉及到多部门使用服务器排队的情况,所以建议先在本地测试程序)
head -20 text1.txt | python count_mapper.py | sort | python count_reducer.py; 5.集群上跑任务:
hadoop jar /usr/lib/hadoop-current/share/hadoop/tools/lib/hadoop-streaming-2.7.2.jar \
-file count_mapper.py \
-mapper count_mapper.py \
-file count_reducer.py \
-reducer count_reducer.py \
-input /xxx/input/example \
-output /xxx/output/example
hadoop jar /usr/lib/hadoop-current/share/hadoop/tools/lib/hadoop-streaming-2.7.2.jar \
-file count_mapper.py \
-mapper count_mapper.py \
-file count_reducer.py \
-reducer count_reducer.py \
-input /xxx/input/example \
-output /xxx/output/example