Spark 0.8 集群(CentOS6.4)-簡單統(tǒng)計測試
環(huán)境:CentOS 6.4, hadoop-2.0.0-cdh4.2.0, JDK 1.6, spark-0.8.0-incubating-bin-cdh4.tar.gz,Scala 2.9.3
1. 安裝、部署集群環(huán)境
參考前章《安裝Spark 0.8集群(CentOS6.4) - 大數(shù)據(jù)之內(nèi)存計算》
2. 測試描述
使用在線測試數(shù)據(jù)生工具,動態(tài)生成如下json數(shù)據(jù)(名稱DATA[1-9].json):
{"id":10,"first_name":"Ralph","last_name":"Kennedy","country":"Colombia","ip_address":"12.211.41.162","email":"rkennedy@oyonder.net"},
{"id":11,"first_name":"Gary","last_name":"Cole","country":"Nepal","ip_address":"242.67.150.18","email":"gcole@browsebug.info"},
…
可以數(shù)據(jù)可以先生成100M左右,然后通過linux cp / cat工具進行數(shù)據(jù)復(fù)制、合并,產(chǎn)生不同大小數(shù)據(jù),方便測試。
測試任務(wù):
對所有*.json數(shù)據(jù)的ip地址進行簡單統(tǒng)計,包括:ip地址總數(shù)統(tǒng)計,“241.*”ip地址段總數(shù)統(tǒng)計。將其上傳到HDFS集群上
2.1啟動 Spark 集群
在master上執(zhí)行
$>cd ~/spark-0.8.0 $>bin/start-all.sh |
檢測進程是否啟動
$> jps 11055 Jps 2313 SecondaryNameNode 2409 JobTracker 2152 NameNode 4822 Master |
瀏覽master的web UI(默認(rèn)http://localhost:8080). 這是你應(yīng)該可以看到所有的word節(jié)點,以及他們的CPU個數(shù)和內(nèi)存等信息。
2.2運行spark-shell從HDFS讀取文件并統(tǒng)計IP地址
// set the master node of spark cluster and runspark-shell $> MASTER=spark://centos01:7077./spark-shell // read the json data $>val file = sc.textFile("hdfs://sdc/user/hadoop/In/DATA*.json") // filter the json data $>val ips = file.filter(line => line.contains("ip_address")) // Count all the IP $>ips.count() // Count all the“241.*”IP $>ips.filter(line => line.contains("241.")).count() $>ips.filter(line => line.contains("241.")).collect() |
2.3 運行結(jié)果
posted on 2014-01-27 10:46 順其自然EVO 閱讀(424) 評論(0) 編輯 收藏 所屬分類: linux