獲取鏡像 ~~~bash 本機內 docker pull ubuntu:16.04 ~~~ 編排鏡像 1. 啟動一個容器 ~~~bash 本機內 docker run i t name master ubuntu:16.04 ~~~ 2. 在容器內進行安裝配置 ~~~bash 容器內 apt upd ...
獲取鏡像
#本機內
docker pull ubuntu:16.04
編排鏡像
啟動一個容器
#本機內 docker run -i -t --name master ubuntu:16.04
在容器內進行安裝配置
#容器內 apt update apt install openjdk8-jdk, ssh, net-tools,iputils-ping echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/' >> ~/.bashrc echo '/usr/sbin/sshd' >> ~/.bashrc mkdir /var/run/sshd
配置ssh
#在本地 docker cp ~/.ssh/id_rsa.pub master:/root/
#在master容器內 ssh-keygen -t rsa cd ~/.ssh cp id_rsa.pub authorized_keys echo ~/id_rsa.pub >> authorized_keys chmod root:root authorized_keys chown 600 authorized_keys
安裝hadoop
#新開一個終端 docker cp ./hadoop-2.7.5.tar.gz master:/root
#在容器內 tar -zxvf ~/hadoop-2.7.5.tar.gz -C ~/Program/ rm ~/hadoop-2.7.5.tar.gz echo 'export HADOOP_HOME=/root/Program/hadoop-2.7.5' >> ~/.bashrc echo 'export HADOOP_CONFIG_HOME=$HADOOP_HOME/etc/hadoop' >>~/.bashrc echo 'export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin' >> ~/.bashrc
修改hadoop配置文件
#hadoop-env.sh export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
#core-site.xml <configuration> <property> <name>hadoop.tmp.dir</name> <value>/root/Program/hadoop-2.7.5/tmp</value> </property> <property> <name>fs.defaultFS</name> <value>hdfs://master:9000</value> </property> </configuration>
#hdfs-site.xml <configuration> <property> <name>dfs.replication</name> <value>2</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/root/Program/hadoop-2.7.5/tmp/dfs/namenode</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/root/Program/hadoop-2.7.5/tmp/dfs/datanode</value> </property> </configuration>
#mapred-site.xml <configuration> <property> <name>mapred.job.tracker</name> <value>master:9001</value> </property> </configuration>
生成鏡像
docker commit -m "install environment" master ubuntu:hadoop docker rm master
配置網路
生成網段並給容器設置ip
docker network create --subnet=10.0.0.0/16 hadoopnetwork docker run -i -t --name master -h master --network hadoopnetwork --ip 10.0.0.2 ubuntu:hadoop docker run -i -t --name slave1 -h slave1 --network hadoopnetwork --ip 10.0.0.3 ubuntu:hadoop docker run -i -t --name slave2 -h slave2 --network hadoopnetwork --ip 10.0.0.4 ubuntu:hadoop docker start master docker start slave1 docker start slave2
測試ip是否可訪問
ping 10.0.0.2 ssh [email protected]
修改各個節點上的hosts文件
#hosts 10.0.0.2 master 10.0.0.3 slave1 10.0.0.4 slave2
確認master節點能連接slave節點
#在master節點上 ssh root@slave1 ssh root@slave2
修改master節點配置文件
#slaves localhost slave1 slave2
啟動hadoop集群
#在master節點上 hadoop namenode -format start-all.sh
查看是否運行成功
#在master節點上 jps 963 Jps 469 SecondaryNameNode 758 NodeManager 295 DataNode 634 ResourceManager 157 NameNode #在slave1節點上 292 Jps 41 DataNode 155 NodeManager