Hadoop 為 Apache 基金會的開源頂級專案,為軟體框架做為分散式儲存及運算,無論是增減加機器都能處理,另具備高可用性、數據副本等能力
0.基本需求
準備事項:
- Linux 作業系統
- Spark
- hadoop
- jupyter
範例相關應用程式版本:
1
2
3
4
5
6
|
1. openJDK: 1.8.0
2. hadoop: 3.2.1
3. spark: 2.4.5
4. Python: 3.6.9
5. R: 3.6.2
6. Jupyter: 1.0.0
|
建置步驟 - Spark on R:
1. 加入R的倉庫清單(管理者身份)
1
|
sudo nano /etc/apt/sources.list.d/rpackages.list
|

2. 取得金鑰(管理者身份)
1
|
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
|

Warning
請確認出現金鑰正常 imported,如未果請至官網使用 gpg 取得金鑰
金鑰如果有變更,請至新增倉庫清單鏡像站確認最新版金鑰
*
R-base官網請參閱
3. 簽屬金鑰(管理者身份)
1
|
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
|

Warning
請確認出現金鑰正常 imported,如未果請至官網使用 gpg 取得金鑰
金鑰如果有變更,請至新增倉庫清單鏡像站確認最新版金鑰
4. 更新倉庫清單(管理者身份)

5. 下載及安裝相關套件(管理者身份)
1
2
|
apt install r-base-dev
apt install r-base
|
6. 檢查下載R相關套件(管理者身份)
1
|
dpkg -l | grep 'r-base'
|

7. 啟動R(管理者身份)

8. 下載 irkernel 等套件 (管理者身份)
1
2
|
install.packages(c('repr', 'IRdisplay', 'IRkernel'), type = 'source')
IRkernel::installspec(user = FALSE) #全部使用者都能使用
|

9. 退出R後,切換hadoop帳號並啟動Jupyter互動式介面 (Hadoop身份)
1
|
jupyter notebook # jupyter lab
|

10. 至瀏覽器輸入IP及Ports埠號選擇 R 筆記本,並測試一下

11. 使用SparkR
1
2
3
4
5
|
if (nchar(Sys.getenv("SPARK_HOME")) < 1) {
Sys.setenv(SPARK_HOME = "/usr/local/spark/")
}
library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R", "lib")))
sparkR.session(master = "yarn", sparkConfig = list(spark.driver.memory = "2g"))
|

12. 至ResourceManager UI 查看 SparkR session

附錄: SparkR Standalone
- 啟動Spark (Hadoop身份)
1
|
bash /usr/local/spark/sbin/start-all.sh
|

- 啟動Jupyter互動式介面 (Hadoop身份)
1
|
jupyter notebook # jupyter lab
|

- 設定Spark Standalone

- 至Spark Master UI 查看 SparkR session
