hdfs安裝
- 安裝虛擬機
- 創建hadoop用戶組和hadoop用戶,並給予root權限(此處我沒創建,直接用root)
- sudo apt-get update
- sudo apt-get install openssh-server openssh-client
- 建立互信(你使用的用戶)
- 安裝jdk:sudo apt-get install openjdk-8-jdk 配置JAVA_HOME
- 安裝hadoop: 解壓
- 配置
安裝目錄下的sbin用來啓動等操作,bin用來hdfs dfs 的各種命令(mkdir等等)
hdfs的命令就是一系列shell的分裝,即便是shell mkdir了一個目錄,也可以用hdfs的 put把文件拷貝到這個目錄中,也就是說不一定hdf創建的目錄,才能操作,可以進行任何操作,和shell一樣的 這裏只能用hadoop 不能用hdfs,不寫reduce,就會把map的結果寫入out
hdfs namenode存儲文件信息,各個datanode都會存儲文件
hadoop jar ./share/hadoop/tools/lib/hadoop-streaming-2.7.3.jar -mapper /hdfs_map.py -input /hadoop -output /hadoop_out 如果是zip文件,這樣,會把整個zip作爲輸入進行計算的
使用
**python腳本要給+x 和#!/usr/bin/env python **#!/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)
我新建三個文件內容分別是:
file1 hello
file2 hello
file3 hello
最後輸出了一個文件part-00000
當把代碼改成
#!/usr/bin/env python
import sys
for line in sys.stdin:
line = line.strip()
words = line.split()
for word in words:
print 'hello world'
輸出
增加reduce後
reduce.py
print ‘reduce’
這樣就只輸出一個reduce在part-00000
注意
map-reduce 會把內容按行隨機輸出並排序,所以需要在一個文件內分析的話,就不合適