機器mac book,virtualbox4.3.6,virtualbox安裝ubunt13.10,在多點分布環境中,配置好一個機器後,clone出另外2個,一共三台機器。
1. Configure the Environment
Bash語言: sudo apt-get install -y openjdk-7-jdk openssh-server
sudo addgroup hadoop
sudo adduser —ingroup hadoop hadoop # create password
sudo visudo
hadoop ALL=(ALL) ALL # hadoop user can use sudo
su - hadoop # need password
ssh-keygen -t rsa -P "" # Enter file (/home/hadoop/.ssh/id_rsa)
cat /home/hadoop/.ssh/id_rsa.pub >> /home/hadoop/.ssh/authorized_keys
wget http://apache.fayea.com/apache-mirror/hadoop/common/hadoop-2.3.0/hadoop-2.3.0.tar.gz
tar zxvf hadoop-2.3.0.tar.gz
sudo cp -r hadoop-2.3.0/ /opt
cd /opt
sudo ln -s hadoop-2.3.0 hadoop
sudo chown -R hadoop:hadoop hadoop-2.3.0
sed -i '$a \\nexport JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64' hadoop/etc/hadoop/hadoop-env.sh
2. Configure hadoop single Node environment
cp mapred-site.xml.template mapred-site.xml
vi mapred-site.xml
<property>
<name>mapreduce.cluster.temp.dir</name>
<value></value>
<description>No description</description>
<final>true</final>
</property>
<property>
<name>mapreduce.cluster.local.dir</name>
<value></value>
<description>No description</description>
<final>true</final>
</property>
vi yarn-site.xml
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>127.0.0.1:8021</value>
<description>host is the hostname of the resource manager and port is the port on which the NodeManagers contact the Resource Manager.
</description>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>127.0.0.1:8022</value>
<description>host is the hostname of the resourcemanager and port is the port on which the Applications in the cluster talk to the Resource Manager.
</description>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
<description>In case you do not want to use the default scheduler</description>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>127.0.0.1:8023</value>
<description>the host is the hostname of the ResourceManager and the port is the port on which the clients can talk to the Resource Manager. </description>
</property>
<property>
<name>yarn.nodemanager.local-dirs</name>
<value></value>
<description>the local directories used by the nodemanager</description>
</property>
<property>
<name>yarn.nodemanager.address</name>
<value>0.0.0.0:8041</value>
<description>the nodemanagers bind to this port</description>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>10240</value>
<description>the amount of memory on the NodeManager in GB</description>
</property>
<property>
<name>yarn.nodemanager.remote-app-log-dir</name>
<value>/app-logs</value>
<description>directory on hdfs where the application logs are moved to </description>
</property>
<property>
<name>yarn.nodemanager.log-dirs</name>
<value></value>
<description>the directories used by Nodemanagers as log directories</description>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
<description>shuffle service that needs to be set for Map Reduce to run </description>
</property>
補充配置:
mapred-site.xml
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
core-site.xml
<property>
<name>fs.defaultFS</name>
<value>hdfs://127.0.0.1:9000</value>
</property>
hdfs-site.xml
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
Bash語言: cd /opt/hadoop
bin/hdfs namenode -format
sbin/hadoop-daemon.sh start namenode
sbin/hadoop-daemon.sh start datanode
sbin/yarn-daemon.sh start resourcemanager
sbin/yarn-daemon.sh start nodemanager
jps
# Run a job on this node
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.3.0.jar pi 5 10
3. Running Problem
14/01/04 05:38:22 INFO ipc.Client: Retrying connect to server: localhost/127.0.0.1:8023. Already tried 9 time(s); retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1 SECONDS)
netstat -atnp # found tcp6
Solve:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6 # 0 means ipv6 is on, 1 means off
cat /proc/sys/net/ipv6/conf/lo/disable_ipv6
cat /proc/sys/net/ipv6/conf/default/disable_ipv6
ip a | grep inet6 # have means ipv6 is on
vi /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1
sudo sysctl -p # have the same effect with reboot
sudo /etc/init.d/networking restart
4. Cluster setup
Config /opt/hadoop/etc/hadoop/{hadoop-env.sh, yarn-env.sh}
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
cd /opt/hadoop
mkdir -p tmp/{data,name} # on every node. name on namenode, data on datanode
vi /etc/hosts # hostname also changed on each node
192.168.1.110 cloud1
192.168.1.112 cloud2
192.168.1.114 cloud3
vi /opt/hadoop/etc/hadoop/slaves
cloud2
cloud3
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://cloud1:9000</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop/tmp</value>
<description>A base for other temporary directories.</description>
</property>
</configuration>
據說dfs.datanode.data.dir 需要清空,不然datanode不能啟動
hdfs-site.xml
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/hadoop/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/opt/hadoop/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
yarn-site.xml
<property>
<name>yarn.resourcemanager.address</name>
<value>cloud1:8032</value>
<description>ResourceManager host:port for clients to submit jobs. </description>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>cloud1:8030</value>
<description>ResourceManager host:port for ApplicationMasters to talk to Scheduler to obtain resources. </description>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>cloud1:8031</value>
<description>ResourceManager host:port for NodeManagers. </description>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>cloud1:8033</value>
<description>ResourceManager host:port for administrative commands. </description>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>cloud1:8088</value>
<description>ResourceManager web-ui host:port. </description>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
<description>In case you do not want to use the default scheduler</description>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>10240</value>
<description>the amount of memory on the NodeManager in MB</description>
</property>
<property>
<name>yarn.nodemanager.local-dirs</name>
<value></value>
<description>the local directories used by the nodemanager</description>
</property>
<property>
<name>yarn.nodemanager.log-dirs</name>
<value></value>
<description>the directories used by Nodemanagers as log directories</description>
</property>
<property>
<name>yarn.nodemanager.remote-app-log-dir</name>
<value>/app-logs</value>
<description>directory on hdfs where the application logs are moved to </description>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
<description>shuffle service that needs to be set for Map Reduce to run </description>
</property>
<!--
<property>
<name>yarn.nodemanager.aux-services.mapreduce_shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
-->
mapred-site.xml
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>cloud1:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>cloud1:19888</value>
</property>
cd /opt/hadoop/
bin/hdfs namenode -format
sbin/start-dfs.sh
# cloud1 NameNode SecondaryNameNode, cloud2 and cloud3 DataNode
sbin/start-yarn.sh
# cloud1 ResourceManager, cloud2 and cloud3 NodeManager
jps
查看叢集狀態 bin/hdfs dfsadmin -report
查看檔案塊組成 bin/hdfs fsck / -files -blocks
NameNode查看hdfs http://192.168.1.110:50070
查看RM http://192.168.1.110:8088
bin/hdfs dfs -mkdir /input
bin/hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.3.0.jar randomwriter input
5. Questions:
Q: 14/01/05 23:59:05 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
A: /opt/hadoop/lib/native/ 下面的動態連結程式庫是32bit的,要替換成64位的
Q: ssh 登入出現Are you sure you want to continue connecting (yes/no)?解決方案
A: 修改/etc/ssh/ssh_config 將其中的# StrictHostKeyChecking ask 改成 StrictHostKeyChecking no
Q: 兩個slaves的DataNode無法加入cluster系統,
A: 把/etc/hosts 裡面127.0.1.1或localhost 的內容行刪除