Hadoop报错:Exception in thread "main" java.lang.NoClassDefFoundError: NameNode

刚刚在虚拟机上安装并配置了hadoop伪分布式集群,根据《hadoop实战》上的提示,启动Hadoop前需要格式化Hadoop的文件系统HDFS。命令如下:

[root@localhost hadoop-1.0.4]# bin/hadoop NameNode -format

执行命令后报错:

Exception in thread "main" java.lang.NoClassDefFoundError: NameNode

参考了网上的一些文章:

大部分给出的方案都是修改conf/hadoop-env.sh配置文件,增加

export HADOOP_COMMON_HOME=/root/hadoop-1.0.4 (hadoop的安装目录)

但是重新执行后还是报错

 

接下来又修改了环境变量,增加了HADOOP_HOME配置:

HADOOP_HOME=/root/hadoop-1.0.4
PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin
export CATALINA_HOME JAVA_HOME CLASSPATH PATH HADOOP_HOME

 执行后还是报错。

 

之后仔细看了一些解决方案之后发现网上给出的正确命令是:

bin/hadoop namenode -format

 其中namenode是小写,我把我的执行命令里NameNode修改为小写后再次执行,发现成功了

[root@localhost hadoop-1.0.4]# bin/hadoop namenode -format
13/03/07 08:28:20 INFO namenode.NameNode: STARTUP_MSG: 
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = localhost/127.0.0.1
STARTUP_MSG:   args = [-format]
STARTUP_MSG:   version = 1.0.4
STARTUP_MSG:   build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.0 -r 1393290; compiled by 'hortonfo' on Wed Oct  3 05:13:58 UTC 2012
************************************************************/
13/03/07 08:28:20 INFO util.GSet: VM type       = 32-bit
13/03/07 08:28:20 INFO util.GSet: 2% max memory = 19.84625 MB
13/03/07 08:28:20 INFO util.GSet: capacity      = 2^22 = 4194304 entries
13/03/07 08:28:20 INFO util.GSet: recommended=4194304, actual=4194304
13/03/07 08:28:21 INFO namenode.FSNamesystem: fsOwner=root
13/03/07 08:28:21 INFO namenode.FSNamesystem: supergroup=supergroup
13/03/07 08:28:21 INFO namenode.FSNamesystem: isPermissionEnabled=true
13/03/07 08:28:21 INFO namenode.FSNamesystem: dfs.block.invalidate.limit=100
13/03/07 08:28:21 INFO namenode.FSNamesystem: isAccessTokenEnabled=false accessKeyUpdateInterval=0 min(s), accessTokenLifetime=0 min(s)
13/03/07 08:28:21 INFO namenode.NameNode: Caching file names occuring more than 10 times 
13/03/07 08:28:21 INFO common.Storage: Image file of size 110 saved in 0 seconds.
13/03/07 08:28:21 INFO common.Storage: Storage directory /tmp/hadoop-root/dfs/name has been successfully formatted.
13/03/07 08:28:21 INFO namenode.NameNode: SHUTDOWN_MSG: 
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at localhost/127.0.0.1
************************************************************/

 格式化成功后启动Hadoop所有进程

[root@localhost hadoop-1.0.4]# bin/start-all.sh 
starting namenode, logging to /root/hadoop-1.0.4/libexec/../logs/hadoop-root-namenode-localhost.out
localhost: starting datanode, logging to /root/hadoop-1.0.4/libexec/../logs/hadoop-root-datanode-localhost.out
localhost: starting secondarynamenode, logging to /root/hadoop-1.0.4/libexec/../logs/hadoop-root-secondarynamenode-localhost.out
starting jobtracker, logging to /root/hadoop-1.0.4/libexec/../logs/hadoop-root-jobtracker-localhost.out
localhost: starting tasktracker, logging to /root/hadoop-1.0.4/libexec/../logs/hadoop-root-tasktracker-localhost.out

 启动后我们可以验证一下Hadoop是否安装成功,在浏览器中分别访问以下两个地址:

http://localhost:50030/  (MapReduce的web页面)

http://localhost:50070/  (HDFS的web页面)

如果都能访问,说明Hadoop已经安装成功。

 

附:参考资料

http://blog.csdn.net/zuoanlove/article/details/8255162

http://stackoverflow.com/questions/2004786/error-in-starting-namenode-in-hadoop 

你可能感兴趣的:(hadoop,namenode format)