Hadoop Streaming 实战: 文件分发与打包
来源:互联网 发布:java添加购物车代码 编辑:程序博客网 时间:2024/05/24 05:02
如果程序运行所需要的可执行文件、脚本或者配置文件在Hadoop集群的计算节点上不存在,则首先需要将这些文件分发到集群上才能成功进行计算。
Hadoop提供了自动分发文件和压缩包的机制,只需要在启动Streaming作业时配置相应的参数。
1. –file 将本地文件分发到计算结点
2. –cacheFile 文件已经存放在HDFS中,希望计算时在每个计算节点上将文件当作本地文件处理
3. –cacheArchive 将存放在HDFS中的压缩包分发并解压
-file实战: 使用-file分发本地可执行文件和其他文件
a. 待计算的数据放入hdfs
$ hadoop fs -put localfile /user/hadoop/hadoopfile
b. 编写map、reduce脚本,记得给脚本加可执行权限。
mapper.sh
reducer.sh
hello.txt文件内容:
hello
world
c. 运行:
$ hadoop streaming –input /user/hadoop/hadoopfile -output /user/hadoop/result -mapper ./mapper.sh -reducer ./reducer.sh-file mapper.sh -file reducer.sh -file hello.txt -jobconf mapred.reduce.tasks=1 -jobconf mapre.job.name="sum_test"
d. 查看结果:
$ hadoop fs –cat /user/hadoop/result/part-00000
-cacheFile实战
a. 待计算的数据和文件放入hdfs
$ hadoop fs -put hello.txt /user/hadoop/
b.运行命令(mapper.sh和reducer.sh脚本内容同上):
$ hadoop streaming –input /user/hadoop/hadoopfile -output /user/hadoop/result -mapper ./mapper.sh -reducer ./reducer.sh-file mapper.sh -file reducer.sh -cacheFilehdfs://host:port/user/hadoop/hello.txt#./hello.txt -jobconf mapred.reduce.tasks=1 -jobconf mapre.job.name="sum_test"
可以通过配置文件hadoop-site.xml中的fs.default.name配置参数的值得到文件所在的host和port。
c. 查看结果:
$ hadoop fs –cat /user/hadoop/result/part-00000
-cacheArchive 实战
a. 创建一个目录test,目录中包含文件mapper.txt,reducer,hello.txt
修改mapper.sh:
b.压缩文件夹并将压缩文件放入hdfs:
$ cd test
$ tar –zcvf test.tar.gz *
$ hadoop fs –put test.tar.gz /user/hadoop/test/
c.运行命令:
$ hadoop streaming –input /user/hadoop/hadoopfile -output /user/hadoop/result -mapper “./test/mapper.sh ./test/hello.txt” -reducer ./test/reducer.sh-cacheArchive hdfs://host:port/user/hadoop/test/test.tar.gz#test -jobconf mapred.reduce.tasks=1 -jobconf mapre.job.name="sum_test"
d. 查看结果:
$ hadoop fs –cat /user/hadoop/result/part-00000
首先将本地test目录中的所有文件和目录打包压缩,然后上传到HDFS中。启动streaming任务时使用-cacheArchive选项将test.tar.gz分发到计算节点并解压到test目录,然后在当前工作目录创建到test目录的链接,-mapper选项指定为mapper程序及其运行参数,-reducer选项指定reducer程序。本地打包时要进入目录test而不是在test的上层目录打包,否则要通过test/test/mapper.sh才能访问到mapper.shl文件。
- Hadoop Streaming 实战: 文件分发与打包
- Hadoop Streaming 实战: 文件分发与打包
- Hadoop Streaming 实战: 文件分发与打包
- 【hadoop】streaming 文件分发与打包
- Hadoop Streaming 实战: 输出文件分割
- Hadoop Streaming 实战: 输出文件分割
- Hadoop Streaming 实战: 输出文件分割
- Hadoop Streaming 实战: 输出文件分割
- Hadoop Streaming 实战: grep
- Hadoop Streaming 实战: grep
- Hadoop Streaming 实战: aggregate
- Hadoop Streaming 实战: aggregate
- Hadoop Streaming 实战: bash脚本
- Hadoop Streaming 实战: 传递环境变量
- Hadoop Streaming 实战: bash脚本
- Hadoop Streaming 实战: 传递环境变量
- Hadoop Streaming 实战: 二次排序
- Hadoop Streaming 实战: 传递环境变量
- 休闲游戏的兴起
- 又碰到问题了...附spring事务的xml配置
- 函数指针数组
- 正向最大匹配中文分词算法
- 函数指针的使用
- Hadoop Streaming 实战: 文件分发与打包
- 从Oracle、SQLServer中取得注释-PLSQL
- 函数指针数组的指针
- 虚拟内存
- Android 编程:calledfromWrongThreadException 的原因
- C#基础之反射(Reflection)
- 常用的代码
- c++与c#类型的对应
- 心复杂