成功在pseudo-distributed mode下运行wordcount 程序

来源:互联网 发布:win10的windows键 编辑:程序博客网 时间:2024/05/23 11:45

搭建pseudo-distributed 环境:

配置文件如下:

::::::::::::::
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>
       <description>The name of the default file system. A URI whose scheme and authority determine the FileSystem implementation </descripti
on>
</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.replication</name>
      <value>1</value>
       <description>The actual number of replications can be speci? ed when the  is created.</description>
    </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>localhost:9001</value>
       <description>The host and port that the MapReduce job tracker runs at.</description>
</property>
</configuration>
::::::::::::::
masters
::::::::::::::
localhost
::::::::::::::
slaves
::::::::::::::
localhost

单独运行:

bin/stop-all.sh
bin/hadoop namenode - format
bin/start-all.sh
运行jps 检查



首先 重新编译wordcount程序

生成.calss文件

javac -classpath hadoop-core-0.20.203.0.jar -d playground/classes playground/src/WordCount.java

生成 .jar 文件
jar -cvf playground/wordcount.jar -C playground/classes/ .


将需要的输入文件放入hdfs系统:

hadoop fs -mkdir /user/mjiang/input

hadoop fs -put input/test  hdfs://localhost:9000/user/mjiang/input


最后运行程序:

bin/hadoop jar playground/wordcount.jar org.apache.hadoop.examples.WordCount input output


error1:编译版本比运行版本高

Unsupported major.minor version 51.0

resolve: 运行 java -version 是1.7版本 下载1.6版本的tar.gz


error2:bin/hadoop jar playground/wordcount.jar org.apache.hadoop.examples.WordCount input output

不知道是什么意思,写多了也不行少了也不行。

mjiang@venus ~/program/program/hadoop/install/hadoop-0.20.203.0 $bin/hadoop jar playground/wordcount.jar apache.hadoop.examples.WordCount input output
Exception in thread "main" java.lang.ClassNotFoundException: apache.hadoop.examples.WordCount

mjiang@venus ~/program/program/hadoop/install/hadoop-0.20.203.0 $ bin/hadoop jar playground/wordcount.jar playground.classes.org.apache.hadoop.examples.WordCount input output
Exception in thread "main" java.lang.NoClassDefFoundError: playground/classes/org/apache/hadoop/examples/WordCount (wrong name: org/apache/hadoop/examples/WordCount)