CentOS 6.5安装Hadoop 2.6.0

[root@localhost ~]# cd /tmp

[root@localhost tmp]# wget http://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.6.0/hadoop-2.6.0.tar.gz

[root@localhost tmp]# tar -zxrf hadoop-2.6.0.tar.gz

[root@localhost tmp]# mv hadoop-2.6.0 /usr/local/hadoop

[root@localhost tmp]# cd /usr/local/hadoop/

[root@localhost hadoop]# yum install -y java-1.7.0-openjdk.x86_64

[root@localhost hadoop]# vi ~/.bash_profile

 1 # .bash_profile
 2 
 3 # Get the aliases and functions
 4 if [ -f ~/.bashrc ]; then
 5         . ~/.bashrc
 6 fi
 7 
 8 # User specific environment and startup programs
 9 
10 PATH=$PATH:$HOME/bin
11 export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91.x86_64/jre
12 export PATH

[root@localhost hadoop]# source ~/.bash_profile

[root@localhost hadoop]# mkdir input

[root@localhost hadoop]# cp etc/hadoop/*.xml input

[root@localhost hadoop]# bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar grep input output 'dfs[a-z.]+'

[root@localhost hadoop]# cat output/*

1 dfsadmin

[root@localhost hadoop]# vi etc/hadoop/core-site.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 3 <!--
 4   Licensed under the Apache License, Version 2.0 (the "License");
 5   you may not use this file except in compliance with the License.
 6   You may obtain a copy of the License at
 7 
 8     http://www.apache.org/licenses/LICENSE-2.0
 9 
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License. See accompanying LICENSE file.
15 -->
16 
17 <!-- Put site-specific property overrides in this file. -->
18 
19 <configuration>
20   <property>
21     <name>fs.defaultFS</name>
22     <value>hdfs://0.0.0.0:9000</value>
23   </property>
24 </configuration>

[root@localhost hadoop]# vi etc/hadoop/hdfs-site.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 3 <!--
 4   Licensed under the Apache License, Version 2.0 (the "License");
 5   you may not use this file except in compliance with the License.
 6   You may obtain a copy of the License at
 7 
 8     http://www.apache.org/licenses/LICENSE-2.0
 9 
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License. See accompanying LICENSE file.
15 -->
16 
17 <!-- Put site-specific property overrides in this file. -->
18 
19 <configuration>
20   <property>
21     <name>dfs.replication</name>
22     <value>1</value>
23   </property>
24 </configuration>

[tomcat@admin ~]$ ssh localhost

如果连不上执行下面的语句

[root@localhost hadoop]# ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

[root@localhost hadoop]# cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

[root@localhost hadoop]# bin/hdfs namenode -format

[root@localhost hadoop]# vi libexec/hadoop-config.sh

修改JAVA_HOME

[root@localhost hadoop]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9000 -j ACCEPT

[root@localhost hadoop]# iptables save

[root@localhost hadoop]# sbin/start-dfs.sh

 

错误解决:

从172.16.42.20上使用

bin/hadoop fs -put test.txt hdfs://172.16.42.20:9000/text.txt

能够成功,在其他服务器上使用,则报以下错误:

hdfs.DFSClient: DataStreamer Exception
org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /text.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1).  There are 1 datanode(s) running and 1 node(s) are excluded in this operation.
    at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:1549)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:3200)
    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:641)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:482)
    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:619)
    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:962)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2039)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2035)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:416)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2033)

    at org.apache.hadoop.ipc.Client.call(Client.java:1468)
    at org.apache.hadoop.ipc.Client.call(Client.java:1399)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:232)
    at com.sun.proxy.$Proxy9.addBlock(Unknown Source)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:399)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:187)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
    at com.sun.proxy.$Proxy10.addBlock(Unknown Source)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(DFSOutputStream.java:1532)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1349)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:588)
put: File /text.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1).  There are 1 datanode(s) running and 1 node(s) are excluded in this operation.

Eclipse连接上去,能够获取到目录和文件名,打开文件,报以下错误:

Could not obtain block: BP-718558213-127.0.0.1-1448981148802:blk_1073741829_1005 file=/test.txt

问题原因

core-site.xml

  <property>
    <name>fs.defaultFS</name>
    <value>hdfs://0.0.0.0:9000</value>
  </property>

改成

  <property>
    <name>fs.defaultFS</name>
    <value>hdfs://172.16.42.20:9000</value>
  </property>

本以为侦听0.0.0.0,所有其他服务器都能连上去,谁知道实际并非如此。此问题断断续续排查了4、5天。

posted @ 2015-11-26 15:44  martin__zhu  阅读(155)  评论(0)    收藏  举报