结果——分布式hadoop环境
环境依赖
Linux
docker
安装
下载安装包: https://pan.baidu.com/s/1S6ZlrI2BQKOmZOpHrmDKdA
内涵java、hadoop、hive、sqoop、spark
tar zxf app.tar.gz
docker pull lyndon1994/hadoop:master_1.0
docker network create --driver bridge --subnet 192.168.0.0/16 network_hadoop
docker run -itd --name master -h master -v /home/jie/app:/opt/bigdata/hadoop --net network_hadoop --ip 192.168.0.2 --add-host slave1:192.168.0.3 --add-host slave2:192.168.0.4 -d -P -p 50070:50070 -p 8088:8088 -p 8180:8180 lyndon1994/hadoop:master_1.0
docker run -itd --name slave1 -h slave1 -v /home/jie/app:/opt/bigdata/hadoop --net network_hadoop --ip 192.168.0.3 --add-host master:192.168.0.2 --add-host slave2:192.168.0.4 -d -P lyndon1994/hadoop:master_1.0
docker run -itd --name slave2 -h slave2 -v /home/jie/app:/opt/bigdata/hadoop --net network_hadoop --ip 192.168.0.4 --add-host slave1:192.168.0.3 --add-host master:192.168.0.2 -d -P lyndon1994/hadoop:master_1.0
#进入master容器,开启hadoop服务
start-all.sh
参考资料
https://www.jianshu.com/p/c070606d8b8e
https://www.jianshu.com/p/a3aa18d7b0f8
构造镜像步骤
拉取镜像
docker pull ubuntu:18.04
#实例化镜像,注意,使用了卷,映射到宿主机/home/emily/app目录,下面会有使用
docker run -t -i --name test-hadoop -v /home/emily/app:/opt/bigdata/hadoop ubuntu:18.04 /bin/bash
安装ssh
apt update
apt install -y ssh
启动ssh
mkdir -p /run/sshd
/usr/sbin/sshd
#检查ssh是否运行
ps -aux | grep ssh
#启动容器默认启动sshd
echo "ps -ef | grep -v grep | grep sshd || /usr/sbin/sshd " >> ~/.bashrc
ssh-key
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
hadoop@8cfa8109d131:~/.ssh$ echo "StrictHostKeyChecking no" >> config
hadoop@8cfa8109d131:~/.ssh$ echo "UserKnownHostsFile /dev/null" >> config
hadoop@8cfa8109d131:~/.ssh$ cat config
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
创建hadoop用户
groupadd hadoop
useradd -g hadoop hadoop
#授予权限
chown -R hadoop:hadoop /opt/bigdata
#切换用户
su hadoop
在宿主机中准备好安装包
配置hadoop
这里创建了三个目录,后续配置的时候会用到:
- tmp:作为Hadoop的临时目录
- namenode:作为NameNode的存放目录
- datanode:作为DataNode的存放目录
cd etc/hadoop
cp mapred-site.xml.template mapred-site.xml
core-site.xml配置
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/bigdata/hadoop/hadoop-2.7.3/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
<final>true</final>
<description>The name of the default file system. A URI whose
scheme and authority determine the FileSystem implementation. The
uri's scheme determines the config property (fs.SCHEME.impl) naming
the FileSystem implementation class. The uri's authority is used to
determine the host, port, etc. for a filesystem.</description>
</property>
</configuration>
注意:
- hadoop.tmp.dir配置项值即为此前命令中创建的临时目录路径。
- fs.default.name配置为hdfs://master:9000,指向的是一个Master节点的主机(后续我们做集群配置的时候,自然会配置这个节点,先写在这里)
hdfs-site.xml配置
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
<final>true</final>
<description>Default block replication.
The actual number of replications can be specified when the file is created.
The default is used if replication is not specified in create time.
</description>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/bigdata/hadoop/hadoop-2.7.3/namenode</value>
<final>true</final>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/opt/bigdata/hadoop/hadoop-2.7.3/datanode</value>
<final>true</final>
</property>
</configuration>
注意:
- 我们后续搭建集群环境时,将配置一个Master节点和两个Slave节点。所以dfs.replication配置为2。
- dfs.namenode.name.dir和dfs.datanode.data.dir分别配置为之前创建的NameNode和DataNode的目录路径
配置mapred-site.xml
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>master:9001</value>
<description>The host and port that the MapReduce job tracker runs
at. If "local", then jobs are run in-process as a single map
and reduce task.
</description>
</property>
</configuration>
这里只有一个配置项mapred.job.tracker,我们指向master节点机器。
配置slaves
slave1
slave2
修改hadoop用户默认sh,提前修改hadoop用户密码
chsh -s /bin/bash
修改bashrc
~/.bashrc文件:
export JAVA_HOME=/opt/bigdata/hadoop/jdk1.8.0_191
export HADOOP_HOME=/opt/bigdata/hadoop/hadoop-2.7.3
export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
格式化 namenode
这是很重要的一步,执行命令hadoop namenode -format
提交镜像
docker commit master lyndon1994/hadoop:master_1.0
docker push lyndon1994/hadoop:master_1.0
使用镜像
docker network create --driver bridge --subnet 192.168.0.0/16 network_hadoop
docker run -itd --name master -h master -v /home/jie/app:/opt/bigdata/hadoop --net network_hadoop --ip 192.168.0.2 --add-host slave1:192.168.0.3 --add-host slave2:192.168.0.4 -d -P -p 50070:50070 -p 8088:8088 -p 8180:8180 lyndon1994/hadoop:master_1.0
docker run -itd --name slave1 -h slave1 -v /home/jie/app:/opt/bigdata/hadoop --net network_hadoop --ip 192.168.0.3 --add-host master:192.168.0.2 --add-host slave2:192.168.0.4 -d -P lyndon1994/hadoop:master_1.0
docker run -itd --name slave2 -h slave2 -v /home/jie/app:/opt/bigdata/hadoop --net network_hadoop --ip 192.168.0.4 --add-host slave1:192.168.0.3 --add-host master:192.168.0.2 -d -P lyndon1994/hadoop:master_1.0
ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: java.io.IOException: Incomplete HDFS URI, no host:
这个问题是/etc/host里面的host不能带_(下划线)但是可以带-(中划线)