原文参考: https://kiwenlau.com/2016/06/12/160612-hadoop-cluster-docker-update/
注:本机docker环境,不需要加sudo命令提权限,如果你发现你机器需要,请加上!或者设置免sudo命令。
摘要: kiwenlau/hadoop-cluster-docker是去年参加Docker巨好玩比赛开发的,得了二等奖并赢了一块苹果手表,目前这个项目已经在GitHub上获得了236个Star,DockerHub的镜像下载次数2000+。总之,项目还算很受欢迎吧,这篇博客将介绍项目的升级版。
将Hadoop打包到Docker镜像中,就可以快速地在单个机器上搭建Hadoop集群,这样可以方便新手测试和学习。
如下图所示,Hadoop的master和slave分别运行在不同的Docker容器中,其中hadoop-master容器中运行NameNode和ResourceManager,hadoop-slave容器中运行DataNode和NodeManager。NameNode和DataNode是Hadoop分布式文件系统HDFS的组件,负责储存输入以及输出数据,而ResourceManager和NodeManager是Hadoop集群资源管理系统YARN的组件,负责CPU和内存资源的调度。
之前的版本使用serf/dnsmasq为Hadoop集群提供DNS服务,由于Docker网络功能更新,现在并不需要了。更新的版本中,使用以下命令为Hadoop集群创建单独的网络:
1、建立docker内部网关:bridge 桥接:独立的网络 ,host 共享docker网络 ...
docker network create --driver=bridge hadoop 或者 sudo docker network create --driver=bridge hadoop
然后在运行Hadoop容器时,使用”–net=hadoop”选项,这时所有容器将运行在hadoop网络中,它们可以通过容器名称进行通信。
1. 下载Docker镜像
sudo docker pull kiwenlau/hadoop:1.0 |
2. 下载GitHub仓库
git clone https://github.com/kiwenlau/hadoop-cluster-docker |
3. 创建Hadoop网络
sudo docker network create --driver=bridge hadoop |
4. 运行Docker容器
cd hadoop-cluster-docker |
运行结果
start hadoop-master container... |
5. 启动hadoop
./start-hadoop.sh |
6. 运行wordcount
./run-wordcount.sh |
运行结果
input file1.txt: |
Hadoop网页管理地址:
192.168.99.100为docker主机的IP。
1. 准备
2. 重新构建Docker镜像
./resize-cluster.sh 5 |
3. 启动Docker容器
./start-container.sh 5 |
4. 运行Hadoop
错误如下:
14/11/17 21:55:07 INFO mapreduce.Job: Job job_1413439879095_0006 failed with state FAILED due to: Application application_1413439879095_0006 failed 2 times due to AM Container for appattempt_1413439879095_0006_000002 exited with exitCode: 1 due to: Exception from container-launch.
Container id: container_1413439879095_0006_02_000001
Exit code: 1
Stack trace: ExitCodeException exitCode=1:
at org.apache.hadoop.util.Shell.runCommand(Shell.java:538)
at org.apache.hadoop.util.Shell.run(Shell.java:455)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:702)
at org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor.launchContainer(DefaultContainerExecutor.java:196)
at org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:299)
at org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.call(ContainerLaunch.java:81)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Container exited with a non-zero exit code 1
.Failing this attempt.. Failing the application.
14/11/17 21:55:07 INFO mapreduce.Job: Counters: 0
解决方案:虚拟机内存不可少于2G,可以先将虚拟机关闭,然后通过虚拟机工具调节内存大小。我提到了3G左右,运行成功。
查看本机内存 (M为单位) :free -m |grep "Mem" | awk '{print $2}'
解决:在./start-container.sh 设置端口映射!映射9000。
错误如下: Connection timed out: no further information
2019-05-15 13:08:26,209 WARN [LocalJobRunner Map Task Executor #0] hdfs.DFSClient (DFSInputStream.java:blockSeekTo(654)) - Failed to connect to /172.18.0.3:50010 for block, add to deadNodes and continue. java.net.ConnectException: Connection timed out: no further information
java.net.ConnectException: Connection timed out: no further information
解决:
1))、设置本地机器 /windows/system32/driver/etc/hosts 文件。域名反向代理。
配置如下:
192.168.99.100 hadoop-master
192.168.99.100 hadoop-slave1
192.168.99.100 hadoop-slave2
#192.168.99.100 是docker机器的ip
Configuration conf = new Configuration();
//设置域名访问!!不是ip访问
conf.set("dfs.client.use.datanode.hostname", "true");
5))、并在config/hdfs-site.xml中 设置域名访问