• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
导航菜单
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx
您的位置:首页 > 服务器 >云计算 > 用Bash Script编写Hadoop MapReduce Streaming,hadoopmapreduce

用Bash Script编写Hadoop MapReduce Streaming,hadoopmapreduce

作者:网友 字体:[增加 减小] 来源:互联网

本文主要包含bash script,mapreduce streaming,bash,git bash,git bash下载等服务器相关知识,网友希望可以进行参考

用Bash Script编写Hadoop MapReduce Streaming,hadoopmapreduce


用Bash Script编写Hadoop MapReduce Streaming

标签(空格分隔): hadoop mapreduce bash


MapReduce对外提供一个多语言编写MR的功能,就是Hadoop Streaming。我们可以通过自己喜欢的语言来编写Mapper和Reducer函数,运行MapReduce job。

根据Hadoop Streaming的定义,只要我们能够从标准输入(standard input)读入数据,然后从标准输出(standard output)读出数据就OK了。但是有一点需要记住,就是如果你要使用自己喜欢的的语言,如Python,就必须要事先在集群上安装该语言对应的版本和对应的lib等等。这里给出Shell Script的示例

输入事文本文件,功能是从特定的字符开始统计单词的平均长度。你可以在程序里实现做些检查来忽略一些字符,也可以少用Pipes和一些command来提升性能等。

#!/bin/bash
#This reducer script will take-in output from the mapper and emit starting letter of each word and average length
#Remember that the framework will sort the output from the mappers based on the Key
#Note that the input to a reducer will be of a form(Key,Value)and not (Key,
#This is unlike the input i.e.; usually passed to a reducer written in Java.
lastkey="";
count=0;
total=0;
iteration=1
while read line
 do
  newkey=`echo $line | awk '{print $1}'`
  value=`echo $line | awk '{print $2}'`
   if [ "$iteration" == "1" ] then
    lastkey=$newkey;c
    iteration=`expr $iteration + 1`;
   fi
   if [[ "$lastkey" != "$newkey" ]] then
    average=`echo "scale=5;$total / $count" | bc`;
    echo -e "$lastkey\t$average"
    count=0;
    lastkey=$newkey;
    total=0;
    average=0;
   fi
   total=`expr $total + $value`;
   lastkey=$newkey;
   count=`expr $count + 1`;
done
#The output would be Key,Value pairs(letter,average length of the words starting with this letter)

3 . run command

hadoop jar /usr/lib/hadoop-0.20-mapreduce/contrib/streaming/hadoop-streaming*.jar 
-input /input -output /avgwl 
-mapper mapper.sh 
-reducer reducer.sh 
-file /home/user/mr_streaming_bash/mapper.sh 
-file /home/user/mr_streaming_bash/reducer.sh 

还可以用其他语言鞋mapreduce来对比一下性能

翻译:Hadoop MapReduce Streaming Using Bash Script

Google 大牛的Github Project
mapreduce in bash

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 用Bash Script编写Hadoop MapReduce Streaming,hadoopmapreduce

相关文章

  • Linux IRQ Affinity,linuxirqaffinity
  • Cloud Foundry service broker开发部署实例解析(上),foundrybroker
  • Hadoop之——Flume笔记,hadoopflume
  • Docker 使用方法总结之:容器的基本操作,docker基本操作
  • hadoop集群搭建-笔记,hadoop集群搭建
  • hive:Access denied for user 'root'@'%',hivedenied
  • R720 disable hyperthreading,r720hyperthreading
  • Hbase Client Test Case,hbasecase
  • 基于 ssh + Xpra 构建 Docker 桌面系统,xpradocker
  • 《转》Ubuntu14.04 openstack juno配置之 ceilometer遥测模块安装配置,《转》ubuntu14.04

文章分类

  • windows
  • 服务器硬件
  • 服务器运维
  • 云计算
  • 虚拟化
  • IIS教程
  • Linux
  • Apache
  • Ftp
  • DNS
  • Nginx

最近更新的内容

    • Andrew Ng机器学习课程9-补充,andrew9-
    • 剖析Docker文件系统:Aufs与Devicemapper,dockeraufs
    • <转>云主机配置OpenStack使用spice的方法,openstackspice
    • HIVE的数据存储,HIVE数据存储
    • 【解决】hive动态增加partitions不能超过100的问题,hivepartitions
    • 整套spark视频教程免费下载,还有Hadoop,sparkhadoop
    • hbase,hbase安装
    • RabbitMQ(python实现)学习之二:Producer发送消息至多个消息队列queue(广播消息),rabbitmqqueue
    • 修改 openstack 中 nova boot 创建实例只能在10个以内的限制,openstacknova
    • 胡振亮:原来这就是很多网站百度权重做不上去的原因,胡振亮重做

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有