hadoop案例測試——pi值、wordcount函式,hadoop不支援本地庫問題
阿新 • • 發佈:2018-11-01
前言:本文案例測試所需環境都是在前面幾篇blog的基礎上進行的,具體內容請檢視:
http://blog.csdn.net/u012829611/article/details/77678609
http://blog.csdn.net/u012829611/article/details/77651855
1.使用hadoop估算pi的值
[hadoop@localhost hadoop-2.7.3]# yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar pi 5 10
注:命令中,“5”表示map進行5次,“10”表示每次map投擲10次(相當於扔飛鏢10次計算出pi的值)
最終計算結果:
2.使用mapreduce中wordcount函式計算/input目錄下test檔案中單詞出現的次數,結果輸出到/output目錄下
//hdfs上建立資料夾input
[hadoop@localhost hadoop-2.7.3]# hdfs dfs -mkdir /input
[hadoop@localhost hadoop-2.7.3]# hdfs dfs -ls /
//新建test檔案,輸入一些字串
[hadoop@localhost hadoop-2.7.3]# vim test
//將test檔案put到hdfs的input目錄下
[hadoop@localhost hadoop-2.7.3]# hdfs dfs -put test /input
//執行命令
[hadoop@localhost hadoop-2.7.3]# yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /input/test /output
//檢視output目錄下的檔案
[hadoop@localhost hadoop-2.7.3]# hdfs dfs -ls /output
//檢視統計結果
[hadoop@localhost hadoop-2.7.3]# hdfs dfs -cat /output/part-r-00000
附:
①hdfs dfs -rm -r /output //刪除hdfs上的output資料夾
關於hadoop不支援本地庫問題
問題描述:hadoop安裝完後,使用”hadoop checknative”命令檢視是否支援本地庫時,發現不支援hadoop、zlib、snappy等一些本地庫。
解決方法:執行以下命令
[hadoop@localhost bin]# export HADOOP_OPTS="-Djava.library.path=./../lib/native/"
參考文件:
http://blog.csdn.net/ligt0610/article/details/47757013
https://zhidao.baidu.com/question/1766673293716469500.html