-
创建工作文件夹
mkdir -p ~/workspace/centos7-tools ~/workspace/hadoop2x-workspace
-
转到工作目录
cd ~/workspace/centos7-tools
-
编写centos7-tools dockerfile
vim Dockerfile
FROM centos MAINTAINER yiluoe 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"] RUN yum install -y which sudo RUN yum install -y java-1.8.0-openjdk-devel.x86_64
-
构建对应docker镜像 (该镜像包含 sudo、ssh、which、jpa等相应命令,并创建root用户且将其加入sudoers。)
docker build -t=“centos7-tools:1.0.0” .
-
复制准备对应资源
cp jdk-8u241-linux-x64.tar.gz hadoop-2.5.2.tar.gz zookeeper-3.4.6.tar.gz hbase-0.98.9-hadoop2-bin.tar.gz ~/hadoop2x-workspace
-
转到工作目录
cd ~/workspace/hadoop2x-workspace
-
编写centos7-hadoop2x dockerfile
vim Dockerfile
FROM centos7-tools:1.0.0 ADD jdk-8u241-linux-x64.tar.gz /usr/local/jdk-8u241-linux-x64.tar.gz RUN mv /usr/local/jdk-8u241-linux-x64.tar.gz /usr/local/jdk ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_241 ADD hadoop-2.5.2.tar.gz /usr/local/hadoop-2.5.2.tar.gz RUN mv /usr/local/hadoop-2.5.2.tar.gz /usr/local/hadoop ENV HADOOP_HOME /usr/local/hadoop/hadoop-2.5.2 ADD zookeeper-3.4.6.tar.gz /usr/local/zookeeper-3.4.6.tar.gz RUN mv /usr/local/zookeeper-3.4.6.tar.gz /usr/local/zookeeper ENV ZOOKEEPER_HOME /usr/local/zookeeper/zookeeper-3.4.6 ADD hbase-0.98.9-hadoop2-bin.tar.gz /usr/local/hbase-0.98.9-hadoop2-bin.tar.gz RUN mv /usr/local/hbase-0.98.9-hadoop2-bin.tar.gz /usr/local/hbase ENV HBASE_HOME /usr/local/hbase/hbase-0.98.9-hadoop2 ENV PATH $PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$HBASE_HOME/bin
-
构建对应docker镜像
docker build -t=“centos7-hadoop2x:1.0.0” .
-
创建hadoop2x专属docker网络栈
docker network create --subnet=172.32.0.0/24 net-centos7-hadoop2x
-
创建容器
docker run -d --name centos7-hadoop2x1 --hostname centos7-hadoop2x1 \ --network net-centos7-hadoop2x \ --network-alias centos7-hadoop2x1 \ -p 50070:50070 \ -p 50030:50030 \ -p 9000:9000 \ -p 9001:9001 \ -p 1021:22 \ centos7-hadoop2x:1.0.0 docker run -d --name centos7-hadoop2x101 -m 2048m \ --hostname centos7-hadoop2x1 \ --network net-centos7-hadoop2x \ --network-alias centos7-hadoop2x1 \ -p 50070:50070 \ -p 50030:50030 \ -p 9000:9000 \ -p 9001:9001 \ -p 8020:8020 \ -p 2888:2888 \ -p 3888:3888 \ -p 1021:22 \ centos7-hadoop2x:1.0.1
docker run -d --name centos7-hadoop2x2 --hostname centos7-hadoop2x2 \
--network net-centos7-hadoop2x \
--network-alias centos7-hadoop2x2 \
-p 1022:22 \
centos7-hadoop2x:1.0.0
docker run -d --name centos7-hadoop2x3 --hostname centos7-hadoop2x3 \
--network net-centos7-hadoop2x \
--network-alias centos7-hadoop2x3 \
-p 1023:22 \
centos7-hadoop2x:1.0.0
docker run -d --name centos7-hadoop2x4 --hostname centos7-hadoop2x4 \
--network net-centos7-hadoop2x \
--network-alias centos7-hadoop2x4 \
-p 1024:22 \
centos7-hadoop2x:1.0.0
-
四个容器之间免密登陆(笛卡尔积式 自己登自己也要免密)
-
在每个容器上都 生成ssh公私密钥对,输入命令:
ssh-keygen -t rsa
按三下回车 -
进入第一个服务器 centos7-hadoop2x1(方式有很多:直接点击容器图标、使用docker exec命令、ssh链接"ssh root@localhost -p 1021")
-
将公钥文件传给第二服务器
scp ~/.ssh/id_rsa.pub root@centos7-hadoop2x2:/root/.ssh/authorized_keys
-
进入第二个服务器且编辑刚刚传输的文件,将剩余三个服务器的ssh公钥追加到该文件
vim ~/.ssh/authorized_keys
-
编辑完成后将该文件传输到另外三台服务器
过程略…
-
测试是否免密登陆成功 输入命令 :
ssh centos7-hadoop2x1
ssh centos7-hadoop2x2
ssh centos7-hadoop2x3
ssh centos7-hadoop2x4
-
修改 hadoop配置文件
vi hadoop-env.sh
export JAVA_HOME=${JAVA_HOME} 改为 export JAVA_HOME=/usr/local/jdk/jdk1.8.0_241
-
修改 hdfs配置文件
vi hdfs-site.xml
<property> <name>dfs.nameservices</name> <value>yiluoe</value> </property> <property> <name>dfs.ha.namenodes.yiluoe</name> <value>nn1,nn2</value> </property> <property> <name>dfs.namenode.rpc-address.yiluoe.nn1</name> <value>centos7-hadoop2x1:8020</value> </property> <property> <name>dfs.namenode.rpc-address.yiluoe.nn2</name> <value>centos7-hadoop2x2:8020</value> </property> <property> <name>dfs.namenode.http-address.yiluoe.nn1</name> <value>centos7-hadoop2x1:50070</value> </property> <property> <name>dfs.namenode.http-address.yiluoe.nn2</name> <value>centos7-hadoop2x2:50070</value> </property>
配置命名服务后面有很多地方要用到,该服务下有两个namenode分别为nn1、nn2。
配置RPC协议的端口和主机:将这两个namenode节点分别安排到centos7-hadoop2x1、centos7-hadoop2x2服务器。
配置HTTP协议的端口和主机:对外访问时。
-
配置 JournaNode
<property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://centos7-hadoop2x2:8485;centos7-hadoop2x3:8485;centos7-hadoop2x4:8485/yiluoe</value> </property>
-
寻找 NameNode 活动状态配置类
<property> <name>dfs.client.failover.proxy.provider.yiluoe</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property>
-
配置 sshfence
<property> <name>dfs.ha.fencing.methods</name> <value>sshfence</value> </property> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/root/.ssh/id_rsa</value> </property>
把ssh的密钥文件交给hadoop。
-
配置 JournaNode 工作目录
<property> <name>dfs.journalnode.edits.dir</name> <value>/opt/jb/data</value> </property>
-
配置开启自动切换
<property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property>
当某个节点gua掉了则会自动切换。
-
配置文件总体
<configuration> <property> <name>dfs.nameservices</name> <value>yiluoe</value> </property> <property> <name>dfs.ha.namenodes.yiluoe</name> <value>nn1,nn2</value> </property> <property> <name>dfs.namenode.rpc-address.yiluoe.nn1</name> <value>centos7-hadoop2x1:8020</value> </property> <property> <name>dfs.namenode.rpc-address.yiluoe.nn2</name> <value>centos7-hadoop2x2:8020</value> </property> <property> <name>dfs.namenode.http-address.yiluoe.nn1</name> <value>centos7-hadoop2x1:50070</value> </property> <property> <name>dfs.namenode.http-address.yiluoe.nn2</name> <value>centos7-hadoop2x2:50070</value> </property> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://centos7-hadoop2x2:8485;centos7-hadoop2x3:8485;centos7-hadoop2x4:8485/yiluoe</value> </property> <property> <name>dfs.client.failover.proxy.provider.yiluoe</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> <property> <name>dfs.ha.fencing.methods</name> <value>sshfence</value> </property> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/root/.ssh/id_rsa</value> </property> <property> <name>dfs.journalnode.edits.dir</name> <value>/opt/jb/data</value> </property> <property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property> </configuration>
-
配置 NameNode 入口
vi core-site.xml
<property> <name>fs.defaultFS</name> <value>hdfs://yiluoe</value> </property>
这个是我们刚刚刚配置的命名服务。
-
配置 Zookeeper 集群(稍后搭建)
<property> <name>ha.zookeeper.quorum</name> <value>centos7-hadoop2x1:2181,centos7-hadoop2x2:2181,centos7-hadoop2x3:2181</value> </property>
-
修改 Hadoop 临时目录
<property> <name>hadoop.tmp.dir</name> <value>/opt/hadoop-2.5.2</value> </property>
-
配置 DataNode
vi slaves
centos7-hadoop2x2 centos7-hadoop2x3 centos7-hadoop2x4
-
配置 MapReduce
vi yarn-site.xml
<property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.nodemanager.aux-services.mapreduce_shuffle.class</name> <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property> <property> <name>yarn.resourcemanager.hostname</name> <value>centos7-hadoop2x1</value> </property>
设置yarn且将yarn放到服务器centos7-hadoop2x1中
-
配置
cp mapred-site.xml.template mapred-site.xml
vi mapred-site.xml
<property> <name>mapreduce.framework.name</name> <value>yarn</value> <final>true</final> </property>
将mapreduce交给yarn去处理,hadoop2x无须再大量的配置mapred-site.xml。
-
同步配置
2、3、4、执行
rm -rf /usr/local/hadoop/hadoop-2.5.2/etc/hadoop/
1、执行
scp -r /usr/local/hadoop/hadoop-2.5.2/etc/hadoop root@centos7-hadoop2x2:/usr/local/hadoop/hadoop-2.5.2/etc
scp -r /usr/local/hadoop/hadoop-2.5.2/etc/hadoop root@centos7-hadoop2x3:/usr/local/hadoop/hadoop-2.5.2/etc
scp -r /usr/local/hadoop/hadoop-2.5.2/etc/hadoop root@centos7-hadoop2x4:/usr/local/hadoop/hadoop-2.5.2/etc
-
配置zookeeper
cd /usr/local/zookeeper/zookeeper-3.4.6/conf/
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
-
修改数据文件夹
dataDir=/tmp/zookeeper 改为 dataDir=/opt/zookeeper
-
配置 zookeeper 数量
server.1=centos7-hadoop2x1:2888:3888 server.2=centos7-hadoop2x2:2888:3888 server.3=centos7-hadoop2x3:2888:3888
zookeeper节点所在服务器与对应编号。
-
设置 zookeeper的服务器编号
mkdir /opt/zookeeper
vi /opt/zookeeper/myid
写入对应数字(1 ~ 3)到文件即可(主要与刚刚设置的服务器编号对应)
1、2、3指定了zookeeper服务的节点都要设置。
-
同步zookeeper配置文件到 2、3(因为只有这三个节点设置了zookeeper)
rm -rf /usr/local/zookeeper/zookeeper-3.4.6/conf
scp -r /usr/local/zookeeper/zookeeper-3.4.6/conf root@centos7-hadoop2x2:/usr/local/zookeeper/zookeeper-3.4.6
scp -r /usr/local/zookeeper/zookeeper-3.4.6/conf root@centos7-hadoop2x3:/usr/local/zookeeper/zookeeper-3.4.6
-
分别在服务器1、2、3、上启动zookeeper
sh /usr/local/zookeeper/zookeeper-3.4.6/bin/zkServer.sh start
-
分别在服务器2、3、4上启动 journalnode
sh /usr/local/hadoop/hadoop-2.5.2/sbin/hadoop-daemon.sh start journalnode
-
格式化服务器(1)的namenode
sh /usr/local/hadoop/hadoop-2.5.2/bin/hdfs namenode -format
此操作若成功则会在 /opt 生成 hadoop-2.5.2数据文件
-
启动服务器(1)的namenode(单独启动)
sh /usr/local/hadoop/hadoop-2.5.2/sbin/hadoop-daemon.sh start namenode
-
在另一个 namenode节点(服务器2), 复制(服务器1)的初始化数据。
sh /usr/local/hadoop/hadoop-2.5.2/bin/hdfs namenode -bootstrapStandby
-
在已经启动的namenode节点服务器上(1),停止目前启动的所有服务。
sh /usr/local/hadoop/hadoop-2.5.2/sbin/stop-dfs.sh
-
在服务器(1)格式化 zookeeper
sh /usr/local/hadoop/hadoop-2.5.2/bin/hdfs zkfc -formatZK
-
启动所有节点
sh /usr/local/hadoop/hadoop-2.5.2/sbin/start-all.sh