hadoop分布式集群部署以及过程中遇到的一些坑

发布时间:2020-07-18 09:21:08 作者:zfno11
来源:网络 阅读:691

在hadoop学习过程中,首先第一步是部署伪分布以及分布式集群。
在集群的部署过程中http://www.powerxing.com/install-hadoop-cluster/
使用这篇博客作为参考。

在部署过程中。 遇到一些问题。
比如:用PYTHON 跑一个简单的MAPREDUCE 任务,首先需要现在streamingJAR包,简单的说这个包封装了一些常用的接口,PYTHON 通过标准输入输出来调用这个包。最终完成在内部用JAVA实现的功能。
下载地址为:http://www.java2s.com/Code/JarDownload/hadoop-streaming/

python 程序为 mapper.py

#!/usr/bin/env python
import sys
for line in sys.stdin:
line = line.strip()
words = line.split()
for word in words:
print "%s\t%s" % (word, 1)

以及reducer.py

**#!/usr/bin/env python
from operator import itemgetter
import sys

current_word = None
current_count = 0
word = None

for line in sys.stdin:
line = line.strip()
word, count = line.split('\t', 1)
try:
count = int(count)
except ValueError: #count如果不是数字的话,直接忽略掉
continue
if current_word == word:
current_count += count
else:
if current_word:
print "%s\t%s" % (current_word, current_count)
current_count = count
current_word = word

if word == current_word: #不要忘记最后的输出
print "%s\t%s" % (current_word, current_count)**

    运行方式:
hadoop jar ./hadoop-streaming-2.6.0.jar -file ./mappper.py -file ./reducer.py  -input /input -output /output

这里需要注意的是  /input 必须放在hadoop文件系统上
hadoop fs -put input /input 
/output 不能存在,如果存在请先删除

另外在python中首行必须写   #!/usr/bin/env python
否则可能会报错。具体原因可以看http://andylue2008.iteye.com/blog/1622260  这篇博客

另外如果使用hadoop fs -ls 这样的命令报错: 找不到ls目录。是因为没有创建家目录
hadoop fs -mkdir -p /user/hadoop
推荐阅读:
  1. Oracle遇到的一些坑
  2. Hadoop 集群部署

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

hadoop 过程中 doop

上一篇:python对csv里的数据排序的代码详解

下一篇:数据结构-----堆的基本操作和应用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》