在CentOS上安裝並運行SparkR

來源:互聯網
上載者:User

標籤:

環境配置——

  • 作業系統:CentOS 6.5
  • JDK版本:1.7.0_67
  • Hadoop叢集版本:CDH 5.3.0

 

安裝過程——

1、安裝R

yum install -y R

 

2、安裝curl-devel(非常重要!否則無法進行RCurl包的安裝,進而無法安裝devtools)

yum install -y curl-devel

 

3、設定必要的環境變數(非常重要!這裡必須設定成Hadoop環境對應的版本和Yarn對應的版本,否則用Spark與Hadoop HDFS資料通訊會報Hadoop 連接器版本不匹配)

vi + /etc/profile...export USE_YARN=1export SPARK_VERSION=1.1.0export SPARK_YARN_VERSION=2.5.0-cdh5.3.0export SPARK_HADOOP_VERSION=2.5.0-cdh5.3.0

 

4、進入R命令列,安裝R包(最後一步安裝SparkR時,需要安裝很多依賴包,過程很漫長,可能需要重試多次才能成功)

install.packages("RCurl")install.packages("devtools")library(devtools)install_github("amplab-extras/SparkR-pkg", subdir="pkg")

5、大功告成,安裝完畢!現在用SparkR讀取HDFS中的檔案:

library(SparkR)sc <- sparkR.init(master = "local", "RwordCount")lines <- textFile(sc, "hdfs://quickstart.cloudera:8020/test/test.txt")words <- flatMap(lines, function(line) {    strsplit(line, " ")[[1]]})wordCount <- lapply(words, function(word) {    list(word, 1L)})counts <- reduceByKey(wordCount, "+", 2L)output <- collect(counts)for (count in output) {    cat(count[[1]], ": ", count[[2]], "\n")}

 

 

參考資料:

  • SparkR的官方文檔
  • SparkR安裝步驟

 

在CentOS上安裝並運行SparkR

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.