基于docker的大数据环境hadoop快速搭建。
1)下载镜像
$ docker pull kiwenlau/hadoop:1.0
2)下载脚本
git clone https://github.com/kiwenlau/hadoop-cluster-docker
3)创建hadoop 特有网络--方便通过域名访问
docker network create --driver=bridge hadoop
4) 启动容器
cd hadoop-cluster-docker
./start-container.sh //这个脚本里包含了docker启动命令,可做端口映射、路径映射等
5)启动服务
进入master
docker exec -it hadoop-master /bin/bash
./start-hadoop.sh 启动
./run-wordcount.sh 运行案例
6)web查看状态
看下start-container.sh 脚本内容:
#!/bin/bash
# the default node number is 3
N=${1:-3}
# start hadoop master container
sudo docker rm -f hadoop-master &> /dev/null
echo "start hadoop-master container..."
sudo docker run -itd \
--net=hadoop \
-p 15070:50070 \
-p 18088:8088 \
--name hadoop-master \
--hostname hadoop-master \
kiwenlau/hadoop:1.0 &> /dev/null
# start hadoop slave container
i=1
while [ $i -lt $N ]
do
sudo docker rm -f hadoop-slave$i &> /dev/null
echo "start hadoop-slave$i container..."
sudo docker run -itd \
--net=hadoop \
--name hadoop-slave$i \
--hostname hadoop-slave$i \
kiwenlau/hadoop:1.0 &> /dev/null
i=$(( $i + 1 ))
done
# get into hadoop master container
sudo docker exec -it hadoop-master bash
image.png
从脚本可以看出,启动了一个master,N个slave服务器。
运行结果:
image.png
image.png
网友评论