SparkR 1.4.0 的安裝及使用


1、./sparkR打開R shell之後,使用不了SparkR的函數

裝在了   /usr/local/spark-1.4.0/

[root@master sparkR]#./bin/sparkR

能進入R,和沒裝SparkR的一樣,無報錯

> library(SparkR)

報錯:
Error in library.dynam(lib, package, package.lib) : 
  shared object ?.parkR.so?.not found
Error: package or namespace load failed for ?.parkR?


解決辦法:重新編譯sparkR之後,運行以下命令:

[root@master sparkR]# ./install-dev.sh

然後運行   

[root@elcndc2bdwd01t spark-1.4.0]# ./bin/sparkR

R version 3.2.0 (2015-04-16) -- "Full of Ingredients"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

下面是啓動SparkR那些,包括加載SparkR的庫,自動生成 Sparkcontext和sqlContext。
Launching java with spark-submit command /usr/local/spark-1.4.0/bin/spark-submit  "sparkr-shell" /tmp/RtmpAN5LID/backend_port7d49547c6f51
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
15/06/25 13:33:13 INFO SparkContext: Running Spark version 1.4.0
.........................................
15/06/25 13:33:16 INFO BlockManagerMaster: Registered BlockManager

 Welcome to SparkR!
 Spark context is available as sc, SQL context is available as sqlContext

2、修改log4j的日誌控制檯打印級別

在Spark的conf目錄下,把log4j.properties.template修改爲log4j.properties

[appadmin@elcndc2bdwd01t bin]$ cd /usr/local/spark-1.4.0/

$ sudo mv log4j.properties.template  log4j.properties

把log4j.rootCategory=INFO, console改爲log4j.rootCategory=ERROR, console即可抑制Spark把INFO級別的日誌打到控制檯上。

如果要顯示全面的信息,則把INFO改爲DEBUG。

3、在Rstudio 下使用sparkR的設置

(1)建立sparkR包的位置與rstudio包位置的軟鏈接,用 ln -s 命令

[root@elcndc2bdwd01t /]#  ln -s /usr/local/spark-1.4.0/R/lib/SparkR    /home/enn_james/R/x86_64-unknown-linux-gnu-library/3.2 

(2)在R的環境設置文件(.Rprofile)中增加一行

Sys.setenv(SPARK_HOME=”/usr/local/spark-1.4.0”)  


兩個配置文件,.Renviron和.Rprofile。這兩個文件名看起來有點奇怪,怪在哪兒?它們只有擴展名,沒有主文件名
在操作系統中有一個默認的規則,凡是以點開頭的文件都是隱藏文件,而且通常都是配置文件。前面那句list.files()代碼你要是運行過,可能就會發現很多以點開頭的文件和文件夾。
R啓動的時候會在系統的若干位置尋找配置文件,如果文件存在就會使用這些配置。
其中.Renviron文件用來設置一些R要用的環境變量,而.Rprofile文件則是一個R代碼文件,在R啓動時,如果這個文件存在,它會被首先執行。因此,如果我們有一些任務要在R啓動時運行,或有一些個人選項要配置,都可以寫在這個文件裏。

3、4040端口看Spark的任務執行情況

http://10.37.148.39:4040/jobs/



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章