ubuntu docker搭建Hadoop集群环境的方法

spark要配合Hadoop的hdfs使用,然而Hadoop的特点就是分布式,在一台主机上搭建集群有点困难,百度后发现可以使用docker构建搭建,于是开搞:

github项目:https://github.com/kiwenlau/hadoop-cluster-docker

参考文章://www.laike.net/article/109698.htm

docker安装

文章中安装的是docker.io

但是我推荐安装docker-ce,docker.io版本太老了,步骤如下:

1、国际惯例更新下APT软件包的源 

sudo apt-get update

2、安装软件包以允许apt通过HTTPS使用存储库

sudo apt-get install 
apt-transport-https 
ca-certificates 
curl 
software-properties-common

3、因为被墙使用教育网镜像:

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、更新下我们的软件源 

sudo apt-get update

 6、安装docker 

sudo apt-get install docker-ce

 7、启动docker服务

sudo service docker start 

or 

sudo systemctl start docker

 8、觉得有必要可以设置开机自带启动 

sudo systemctl enable docker

 9、关闭自启动 

sudo systemctl disable docker

 10、国内访问docker会受限制,可以使用加速服务,阿里云、网易云、DaoCloud

11、运行 docker run hello-world 测试是否安装成功

12、想要安装其他image 可以到docker hub上找

https://hub.docker.com/

或是直接在github上搜索相应docker

搭建Hadoop集群

搭建过程很简单
https://github.com/kiwenlau/hadoop-cluster-docker

上步骤说明很详细:

1、pull镜像,速度慢的换国内镜像源 

sudo docker pull kiwenlau/hadoop:1.0

 200多m不算大,我下过jupyter官方pyspark的docker 5g…

2、克隆项目到本地 

git clone https://github.com/kiwenlau/hadoop-cluster-docker

 其实只用到里面的 start-container.sh 文件也可以单独下,复制粘贴啥的

3、start-container.sh 需要修改一下 cd 到文件目录

sudo gedit start-container.sh 修改如下

 

开放9000端口还有创建共享文件夹方便以后使用

4、保存之后,创建docker-Hadoop网络 

sudo docker network create --driver=bridge hadoop

5、开启容器 

sudo ./start-container.sh

 

6、开启Hadoop集群 

./start-hadoop.sh

 

7、测试一下Hadoop,在hdfs上创建 test/input 目录

hadoop fs -mkdir -p /test/input
hadoop fs -ls /test

8、运行word-count程序

./run-wordcount.sh 

结果如下

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持来客网。