Hadoop完全分布式安装基于Docker
(都在root用户下)
一、拉取Centos镜像
docker pull centos
docker images
二、通过build Dockfile生成带ssh功能的centos镜像
vi Dockerfile
在Dockfile文件中添加以下内容
FROM centos
MAINTAINER hadoop
RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum makecache
RUN yum update -y
RUN yum install -y openssh-server sudo
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN yum install -y openssh-clients
RUN echo "root:a123456" | chpasswd
RUN echo "root ALL=(ALL) ALL" >> /etc/sudoers
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN mkdir /var/run/sshd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
基于centos镜像,生成带有spenssh-server、openssh-clients的镜像,用户为root,密码为a123456,镜像维护者(作者)为hadoop
三、生成centos7-ssh镜像
建好Dockerfile文件后,生成镜像,在终端输入:
docker build -t="centos7-ssh" .
1、在主机下载ssh
yum -y install openssh-server
ps -e|grep ssh
2、把hadoop和jdk传到/root
3、解压hadoop和jdk
4、生成带有ssh、hadoop和jdk环境的centos镜像
更改Dockerfile里的内容
FROM centos7-ssh
COPY jdk1.8.0_212 /usr/local/jdk
ENV JAVA_HOME /usr/local/jdk
ENV PATH $JAVA_HOME/bin:$PATH
COPY hadoop-3.1.3 /usr/local/hadoop
ENV HADOOP_HOME /usr/local/hadoop
ENV PATH $HADOOP_HOME/bin:$PATH
docker build -t="hadoop" .
构建镜像
四、创建网桥,并启动docker容器
docker network create hadoop
docker network ls
启动三个容器并指定网桥
docker run -itd --network hadoop --name hadoop1 -p 50070:50070 -p 8088:8088 hadoop
docker run -itd --network hadoop --name hadoop2 hadoop
docker run -itd --network hadoop --name hadoop3 hadoop
查看网桥使用情况
docker network inspect hadoop
172.18.0.2 hadoop1
172.18.0.3 hadoop2
172.18.0.4 hadoop3
五、登录容器,配置ip地址映射和ssh免密登录
1、登录容器
docker exec -it hadoop1 bash
docker exec -it hadoop2 bash
docker exec -it hadoop3 bash
2、在每个容器中配置ip地址映射
vi /etc/hosts
每台配好后可以ping一下
3、在每台服务器配置ssh免密登录
在每台hadoop服务器终端输入:
ssh-keygen
然后一直回车即可,再在每台hadoop服务器终端中输入:
ssh-copy-id -i /root/.ssh/id_rsa -p 22 root@hadoop1
填yes后,输入第二(3)步时设置的密码,a123456
ssh-copy-id -i /root/.ssh/id_rsa -p 22 root@hadoop2
填yes后,输入第二(3)步时设置的密码,a123456
ssh-copy-id -i /root/.ssh/id_rsa -p 22 root@hadoop3
填yes后,输入第二(3)步时设置的密码,a123456
ssh-keygen
ssh-copy-id -i /root/.ssh/id_rsa -p 22 root@hadoop1
ssh-copy-id -i /root/.ssh/id_rsa -p 22 root@hadoop2
ssh-copy-id -i /root/.ssh/id_rsa -p 22 root@hadoop3
六、修改hadoop配置文件
在hadoop1中,进入Hadoop配置目录,我的是:/usr/local/hadoop/etc/hadoop,查看目录下的文件,不同版本的Hadoop可能文件数量和名字会不同,在终端输入:
ls
1、创建文件夹,配置时要用
mkdir /home/hadoop
mkdir /home/hadoop/tmp /home/hadoop/hdfs_name /home/hadoop/hdfs_data
2、编辑hadoop_env.sh,修改下面三个参数,按照你自己的改
vi hadoop-env.sh
3、编辑core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop1:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/home/hadoop/tmp</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131702</value>
</property>
</configuration>
4、编辑mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop1:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hadoop1:19888</value>
</property>
</configuration>
5、编辑hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/hadoop/hdfs_name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/hadoop/hdfs_data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.http-address</name>
<value>hadoop1:9001</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hadoop2:9002</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
6、编辑yarn-site.xml
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>hadoop1:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>hadoop1:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>hadoop1:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>hadoop1:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>hadoop1:8088</value>
</property>
</configuration>
7、编辑workers,把原先的默认值localhost删除
hadoop1
hadoop2
hadoop3
8、进入hadoop/sbin目录
1、修改start-dfs.sh
和stop-dfs.sh
(在头部加入)
HDFS_ZKFC_USER=root
HDFS_JOURNALNODE_USER=root
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root
HDFS_DATANODE_USER=root
HDFS_DATANODE_SECURE_USER=root
#HADOOP_SECURE_DN_USER=root
2、修改start-yarn.sh
和stop-yarn.sh
(在头部加入)
#HADOOP_SECURE_DN_USER=root
HDFS_DATANODE_SECURE_USER=root
YARN_NODEMANAGER_USER=root
YARN_RESOURCEMANAGER_USER=root
9、配置环境变量
vi /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export HADOOP_HOME=/usr/local/hadoop
export PATH=$HADOOP_HOME/bin:$PATH
export PATH=$HADOOP_HOME/sbin:$PATH
source /etc/profile
10、把文件拷贝到hadoop2和hadoop3上
scp -r hadoop/ root@hadoop2:/usr/local/
scp -r hadoop/ root@hadoop3:/usr/local/
scp -r /home root@hadoop2:/
scp -r /home root@hadoop3:/
scp -r /etc root@hadoop2:/
scp -r /etc root@hadoop3:/
11、给文件附权限(每台)
chmod -R 777 /usr/local/hadoop
chmod -R 777 /usr/local/jdk
七、启动hadoop集群
1、格式化
hdfs namenode -format
2、一键启动hadoop集群
start-all.sh
3、测试
jps
scp -r /home root@hadoop2:/
scp -r /home root@hadoop3:/
scp -r /etc root@hadoop2:/
scp -r /etc root@hadoop3:/文章来源:https://www.toymoban.com/news/detail-861832.html
### 11、给文件附权限(每台)
```shell
chmod -R 777 /usr/local/hadoop
chmod -R 777 /usr/local/jdk
七、启动hadoop集群
1、格式化
hdfs namenode -format
2、一键启动hadoop集群
start-all.sh
3、测试
jps
文章来源地址https://www.toymoban.com/news/detail-861832.html
到了这里,关于Hadoop完全分布式安装基于Docker的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!