hadoop-namenode配置及问题处理方案
第一步:修改core-site.xml,配置如下内容:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
<final>true</final>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
第二步:修改hdfs-site.xml文件,配置如下内容:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.name.dir</name>
<value>/wen/hadoop/working/name</value>
<final>true</final>
</property>
<property>
<name>dfs.data.dir</name>
<value>/wen/hadoop/working/data</value>
<final>true</final>
</property>
<property>
<name>fs.checkpoint.dir</name>
<value>/wen/hadoop/working/checkpoint</value>
<final>true</final>
</property>
</configuration>
第三步:修改mapred-site.xml配置如下内容:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>hdfs://localhost:9001</value>
<final>true</final>
</property>
<property>
<name>mapred.local.dir</name>
<value>/wen/working/dir1,/wen/hadoop/working/dir2</value>
<final>true</final>
</property>
<property>
<name>mapred.system.dir</name>
<value>/wen/hadoop/working/system</value>
<final>true</final>
</property>
</configuration>
第4步,进入cygwin客户端,执行
$ cd /wen/hadoop 【其中/d/hadoop 为hadoop安装目录】
$ bin/hadoop namenode –format 【格式化namenode】
第5步,修改工作目录权限
$ bin/hadoop dfs chmod 777 /wen/hadoop/working 【/wen/hadoop/working 为工作目录,默认是tmp】
第6步,启动hadoop
$ bin/start-all.sh
$ ps –ef
通过ps查看进程,能看到5个java进程,即成功。
常见问题
(1)
执行 $ bin/hadoop start-all.sh之后,无法启动,在logs的namenode日志发现如下内容:
2011-08-03 08:43:08,068 ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: java.lang.NullPointerException
at org.apache.hadoop.net.NetUtils.createSocketAddr(NetUtils.java:136)
at org.apache.hadoop.hdfs.server.namenode.NameNode.getAddress(NameNode.java:176)
at org.apache.hadoop.hdfs.server.namenode.NameNode.getAddress(NameNode.java:206)
at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:240)
at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:434)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1153)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1162)
解决方法:此时是没有配置conf/mapred-site.xml的缘故. 配置core-site.xml文件
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
<final>true</final>
</property>
配置mapred-site.xml文件:
<property>
<name>mapred.job.tracker</name>
<value>hdfs://localhost:9001</value>
<final>true</final>
</property>
(2)执行 hadoop fs -ls
显示结果:ls: Cannot access .: No such file or directory.
这是这个目录为空所致。执行
hadoop fs -ls /
可以看到有一条结果。执行hadoop fs -mkdir hello 其中hello为文件夹名字,再执行ls命令,即可看到结果。
(3) TaskTracker无法启动,在logs中查看tasktracker日志,出现如下错误:
2011-08-03 08:46:45,750 ERROR org.apache.hadoop.mapred.TaskTracker: Can not start task tracker because java.io.IOException: Failed to set permissions of path: /wen/hadoop/working/dir1/ttprivate to 0700
at org.apache.hadoop.fs.RawLocalFileSystem.checkReturnValue(RawLocalFileSystem.java:525)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:499)
at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:318)
at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:183)
at org.apache.hadoop.mapred.TaskTracker.initialize(TaskTracker.java:635)
at org.apache.hadoop.mapred.TaskTracker.<init>(TaskTracker.java:1328)
at org.apache.hadoop.mapred.TaskTracker.main(TaskTracker.java:3430)
解决方式:1.确认hadoop的版本,在0.20.203版本上有这个bug,切换会0.20.2版本;2. 执行第5步,授权