spark要配合Hadoop的hdfs使用,然而Hadoop的特點(diǎn)就是分布式,在一臺(tái)主機(jī)上搭建集群有點(diǎn)困難,百度后發(fā)現(xiàn)可以使用docker構(gòu)建搭建,于是開搞:
github項(xiàng)目:https://github.com/kiwenlau/hadoop-cluster-docker
參考文章:https://www.jb51.net/article/109698.htm
docker安裝
文章中安裝的是docker.io
但是我推薦安裝docker-ce,docker.io版本太老了,步驟如下:
1、國(guó)際慣例更新下APT軟件包的源
2、安裝軟件包以允許apt通過HTTPS使用存儲(chǔ)庫(kù)
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
3、因?yàn)楸粔κ褂媒逃W(wǎng)鏡像:
復(fù)制代碼 代碼如下:
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add
4、同樣
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
5、更新下我們的軟件源
6、安裝docker
sudo apt-get install docker-ce
7、啟動(dòng)docker服務(wù)
sudo service docker start
or
sudo systemctl start docker
8、覺得有必要可以設(shè)置開機(jī)自帶啟動(dòng)
sudo systemctl enable docker
9、關(guān)閉自啟動(dòng)
sudo systemctl disable docker
10、國(guó)內(nèi)訪問docker會(huì)受限制,可以使用加速服務(wù),阿里云、網(wǎng)易云、DaoCloud
11、運(yùn)行 docker run hello-world
測(cè)試是否安裝成功
12、想要安裝其他image 可以到docker hub上找
https://hub.docker.com/
或是直接在github上搜索相應(yīng)docker
搭建Hadoop集群
搭建過程很簡(jiǎn)單
https://github.com/kiwenlau/hadoop-cluster-docker
上步驟說明很詳細(xì):
1、pull鏡像,速度慢的換國(guó)內(nèi)鏡像源
sudo docker pull kiwenlau/hadoop:1.0
200多m不算大,我下過jupyter官方pyspark的docker 5g…
2、克隆項(xiàng)目到本地
git clone https://github.com/kiwenlau/hadoop-cluster-docker
其實(shí)只用到里面的 start-container.sh 文件也可以單獨(dú)下,復(fù)制粘貼啥的
3、start-container.sh 需要修改一下 cd 到文件目錄
sudo gedit start-container.sh
修改如下
開放9000端口還有創(chuàng)建共享文件夾方便以后使用
4、保存之后,創(chuàng)建docker-Hadoop網(wǎng)絡(luò)
sudo docker network create --driver=bridge hadoop
5、開啟容器
sudo ./start-container.sh
6、開啟Hadoop集群
7、測(cè)試一下Hadoop,在hdfs上創(chuàng)建 test/input 目錄
hadoop fs -mkdir -p /test/input
hadoop fs -ls /test
![](/d/20211016/4f64da21682bfcb68faff2724803f152.gif)
8、運(yùn)行word-count程序
結(jié)果如下
![](/d/20211016/ca74da1e25e28222f7d1e4313ffffbdf.gif)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。