Bootstrap

docker配置hadoop+hive+sqoop+flume环境

一、docker配置ssh
在centos-ssh目录下新建Dockerfile如下:  
FROM centos 
MAINTAINER alexhsl
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:root" | 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-ssh目录下执行命令
docker build -t="centos-ssh" .

二、jdk和hadoop
下载jdk1.8和hadoop,放入新建的hadoop文件夹,在hadoop目录下新建Dockerfile如下: 
FROM centos-ssh
ADD [下载的jdk压缩包] /usr/local/
RUN mv [解压后的jdk文件夹路径] /usr/local/jdk1.8
ENV JAVA_HOME /usr/local/jdk1.8
ENV PATH $JAVA_HOME/bin:$PATH
ADD [下载的hadoop压缩包] /usr/local
RUN mv [解压后的hadoop文件夹路径] /usr/local/hadoop
ENV HADOOP_HOME /usr/local/hadoop
ENV PATH $HADOOP_HOME/bin:$PATH

在hadoop目录下执行命令
docker build -t="centos-hadoo" .

三、集群
集群设置(这里ip根据本机决定,保证同一网段,方便ping通):
主节点:hadoop0 ip:172.29.39.2 
从节点1:hadoop1 ip:172.29.39.3 
从节点2:hadoop2 ip:172.29.39.4

创建自定义网络,并且指定网段:172.29.39.0/24
docker network create --subnet=172.29.39.0/24 hadoopnet0

创建docker容器。启动三个容器,分别作为hadoop0 hadoop1 hadoop2
docker run --name hadoop0 --hostname hadoop0 --net hadoopnet0--ip 172.29.39.2 -d -P -p 8090:50070 -p 8088:8088  centos-hadoop
docker run --name hadoop1 --hostname hadoop1 --net hadoopnet0--ip 172.29.39.3  -d -P centos-hadoop
docker run --name hadoop2 --hostname hadoop2 --net hadoopnet0--ip 172.29.39.4  -d -P centos-hadoop

先连接到hadoop0上, 使用命令
docker exec -it hadoop0 /bin/bash

设置主机名与ip的映射,修改三台容器:vi /etc/hosts 
添加下面配置
172.18.0.2    hadoop0
172.18.0.3    hadoop1
172.18.0.4

;