重復(fù)造輪子,這里使用重新打包生成一個(gè)基于Docker的Hadoop鏡像;
Hadoop集群依賴(lài)的軟件分別為:jdk、ssh等,所以只要這兩項(xiàng)還有Hadoop相關(guān)打包進(jìn)鏡像中去即可;
配置文件準(zhǔn)備
1、Hadoop相關(guān)配置文件:core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml、slaves、hadoop-env.sh
2、ssh配置文件:ssh_config
3、Hadoop集群?jiǎn)?dòng)文件:start-hadoop.sh
制作鏡像
1、安裝依賴(lài)
RUN apt-get update && \
apt-get install -y openssh-server openjdk-8-jdk wget
2、下載Hadoop包
RUN wget http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.10.0/hadoop-2.10.0.tar.gz && \
tar -xzvf hadoop-2.10.0.tar.gz && \
mv hadoop-2.10.0 /usr/local/hadoop && \
rm hadoop-2.10.0.tar.gz && \
rm /usr/local/hadoop/share/doc -rf
3、配置環(huán)境變量
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
ENV HADOOP_HOME=/usr/local/hadoop
ENV PATH=$PATH:/usr/local/hadoop/bin:/usr/local/hadoop/sbin
4、生成SSH key,用于節(jié)點(diǎn)免密登錄
RUN ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' && \
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
5、創(chuàng)建Hadoop相關(guān)目錄、復(fù)制相關(guān)配置文件、相關(guān)文件添加執(zhí)行權(quán)限,最后格式化namenode節(jié)點(diǎn),各個(gè)節(jié)點(diǎn)啟動(dòng)時(shí),啟動(dòng)ssh服務(wù);
RUN mkdir -p ~/hdfs/namenode && \
mkdir -p ~/hdfs/datanode && \
mkdir $HADOOP_HOME/logs
COPY config/* /tmp/
#復(fù)制ssh、hadoop配置相關(guān)
RUN mv /tmp/ssh_config ~/.ssh/config && \
mv /tmp/hadoop-env.sh /usr/local/hadoop/etc/hadoop/hadoop-env.sh && \
mv /tmp/hdfs-site.xml $HADOOP_HOME/etc/hadoop/hdfs-site.xml && \
mv /tmp/core-site.xml $HADOOP_HOME/etc/hadoop/core-site.xml && \
mv /tmp/mapred-site.xml $HADOOP_HOME/etc/hadoop/mapred-site.xml && \
mv /tmp/yarn-site.xml $HADOOP_HOME/etc/hadoop/yarn-site.xml && \
mv /tmp/slaves $HADOOP_HOME/etc/hadoop/slaves && \
mv /tmp/start-hadoop.sh ~/start-hadoop.sh && \
mv /tmp/run-wordcount.sh ~/run-wordcount.sh
#添加執(zhí)行權(quán)限
RUN chmod +x ~/start-hadoop.sh && \
chmod +x ~/run-wordcount.sh && \
chmod +x $HADOOP_HOME/sbin/start-dfs.sh && \
chmod +x $HADOOP_HOME/sbin/start-yarn.sh
# format namenode
RUN /usr/local/hadoop/bin/hdfs namenode -format
在Docker中跑Hadoop集群
通過(guò)上面的Dockerfile生成了鏡像后,這里即可使用上面所生成的鏡像搭建Hadoop集群;這里啟動(dòng)一個(gè)master、兩個(gè)slave節(jié)點(diǎn);
添加橋接網(wǎng)絡(luò):
docker network create --driver=bridge solinx-hadoop
啟動(dòng)Master節(jié)點(diǎn):
docker run -itd --net=solinx-hadoop -p 10070:50070 -p 8088:8088 --name solinx-hadoop-master --hostname solinx-hadoop-master solinx/hadoop:0.1
啟動(dòng)Slave1節(jié)點(diǎn):
docker run -itd --net=solinx-hadoop --name solinx-hadoop-slave1 --hostname solinx-hadoop-slave1 solinx/hadoop:0.1
啟動(dòng)Slave2節(jié)點(diǎn):
docker run -itd --net=solinx-hadoop --name solinx-hadoop-slave2 --hostname solinx-hadoop-slave1 solinx/hadoop:0.1
進(jìn)入Master節(jié)點(diǎn),執(zhí)行啟動(dòng)Hadoop集群腳本即可:
總結(jié)
以上所述是小編給大家介紹的在Docker中跑Hadoop與鏡像制作,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!