1、docker pull ubuntu // 系统镜像
2、docker java错误制作,下载jdk1.8.0, 上传到docker里面,
#docker run -it --name java ubuntu //创建容器 #docker cp jdk-8u131-linux-x64.tar.gz java:/usr/src //拷贝jdk到容器中 #docker exec -it java /bin/bash //进入容器 #cd /usr/local #tar -xzvf jdk-8u131-linux-x64.tar.gz -C /usr/local //解压jdk #vim /etc/profile //编译环境 //在文件最后添加环境变量 export JAVA_HOME=/usr/local/jdk1.8.0_131 export JRE_HOME=$JAVA_HOME/jre export PATH=$PATH:$JAVA_HOME/lib:$JAVA_HOME/sbin export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar //保存退出 #source /etc/profile #vim ~/.bashrc //在文件最后添加 source /etc/profile //这里主要是解决docker重启后环境变量未生效 #java -version //验证java是否配置成功 //退出 //保存修改后的容器为新的镜像文件 docker commit -m "java install" --author="adophper" $CONTAINER_ID hadoop:java //$CONTAINER_ID是刚刚的容器ID
3、ssh安装
4、hadoop安装
#docker start java /bin/bash //复制这一步是在容器外操作的哦。 #docker cp hadoop-2.8.0.tar.gz java:/usr/src //在容器内操作 #tar -xzvf /usr/src/hadoop-2.8.0.tar.gz -C /usr/local #cd /usr/local #mv hadoop-2.8.0 hadoop //编辑hadoop环境变量 #vim ~/.bashrc //在文件最后添加 export HADOOP_HOME=/usr/local/hadoop export HADOOP_CONFIG_HOME=$JAVA_HOME/etc/hadoop export PATH=$PATH:$PATH/bin:$PATH/sbin //保存退出 #source ~/.bashrc #hadoop version // 验证是否hadoop安装成功 //编辑core-site.xml #cd hadoop #vim ./etc/hadoop/core-site.xml //修改configuration hadoop.tmp.dir /usr/local/hadoop/tmp A base for other temporary directories. fs.default.name hdfs://Master:9000 true 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. //hdfs-site.xml配置 dfs.namenode.secondary.http-address Master:50090 dfs.replication 2 true 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. dfs.namenode.name.dir file:/usr/local/hadoop/tmp/dfs/name dfs.datanode.data.dir file:/usr/local/hadoop/tmp/dfs/data //mapred-site.xml配置(可能需要先重命名,默认文件名为 mapred-site.xml.template),然后配置修改如下: mapreduce.framework.name yarn mapred.job.tracker Master:9001 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. mapreduce.jobhistory.address Master:10020 mapreduce.jobhistory.webapp.address Master:19888 //这里只有一个配置项mapred.job.tracker,我们指向master节点机器。 //退出并保存为新的镜像文件hadoop:base
5、根据hadoop:base创建Master Slave1 Slave2
#docker run -it --name master -h Master hadoop:base #docker run -it --name slave1 -h Slave1 hadoop:base #docker run -it --name slave2 -h Slave2 hadoop:base //配置容器的hosts //查看容器的临时IP #docker inspect master | grep -i add //172.17.0.2 #docker inspect slave1 | grep -i add //172.17.0.3 #docker inspect slave2 | grep -i add //172.17.0.4 #vim /etc/hosts //在文件后添加,注意不要重复,因为前面创建容器的时候已经指定了hostname 会将临时IP与hostname对应在这个文件里面 //总体是这样的 172.17.0.2 Master 172.17.0.3 Slave1 172.17.0.4 Slave2 //保存退出 //现在设置ssh 免登录 #cd ~/.ssh //不存在则自己建个目录 #ssh-keygen -t rsa -p "" -f id_rsa #cat id_rsa.pub >> authorized_keys #service ssh restart //测试本地是否可以免登录了 #ssh localhost //复制is_rsa.pub到slave1与slave2 #scp id_rsa.pub root@Slave1:/home/id_rsa.pub #scp id_rsa.pub root@Slave2:/home/id_rsa.pub //进入Slave1与Slave2执行相同的操作 #cat /home/id_rsa.pub >> ~/.ssh/authorized_keys //可以在Master上进行ssh登录了 #ssh Slave1 //能免登录证明成功了
6、启动容器
#hadoop namenode -formate #start-all.sh //查看从节点是否启动成功 #hdfs dfsadmin -report
配置结束!
整合参考:
http://www.powerxing.com/install-hadoop-cluster/
http://tashan10.com/yong-dockerda-jian-hadoopwei-fen-bu-shi-ji-qun/