用于个人学习构建,镜像地址如下:
quanueilun/hadoop:single
dockerfile,用来构建hadoop单节点镜像。
FROM dragonwell-registry.cn-hangzhou.cr.aliyuncs.com/dragonwell/dragonwell:8
RUN yum makecache
RUN yum update -y
RUN yum install -y openssh-server vim openssh-clients hostname
RUN ssh-keygen -A
ADD ./hadoop-3.3.6-aarch64.tar.gz /opt
RUN sed -i '$a\export JAVA_HOME=/opt/java/openjdk' /opt/hadoop-3.3.6/etc/hadoop/hadoop-env.sh
#RUN source /etc/profile
ENV HADOOP_HOME=/opt/hadoop-3.3.6
ENV PATH $PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
ENV HDFS_NAMENODE_USER root
ENV HDFS_DATANODE_USER root
ENV HDFS_SECONDARYNAMENODE_USER root
ENV YARN_RESOURCEMANAGER_USER root
ENV YARN_NODEMANAGER_USER root
ENV JAVA_HOME /opt/java/openjdk
RUN hdfs namenode -format
RUN ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
RUN cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
WORKDIR /opt
CMD start-all.sh & /usr/sbin/sshd -D
docker-compose.yaml,用于启动容器。
version: "3"
services:
master:
image: terminal-hadoop:single
volumes:
- ./core-site.xml:/opt/hadoop-3.3.6/etc/hadoop/core-site.xml
- ./hdfs-site.xml:/opt/hadoop-3.3.6/etc/hadoop/hdfs-site.xml
hostname: master
container_name: hadoop
ports:
- 9870:9870
- 9864:9864
- 9000:9000
- 9868:9868
- 9866:9866
- 9867:9867
core-site.xml,用于指定namenode地址
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 指定NameNode的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://0.0.0.0:9000</value>
</property>
</configuration>
hdfs-site.xml,用于指定副本数
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--副本数-->
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<!--是否启用hdfs权限,当值为false时,代表关闭-->
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
- 启动方式
将docker-compose.yaml、core-site.xml和hdfs-site.xml放在统一目录并执行一下指令
docker-compose up -d
- 访问namenode地址
http://localhost:9870