【问题标题】:How to run a map reduce job using Java -jar command如何使用 Java -jar 命令运行 map reduce 作业
【发布时间】:2014-10-07 17:18:07
【问题描述】:

我使用 Java 编写了一个 Map reduce Job。 设置配置

                    Configuration configuration = new Configuration();

        configuration.set("fs.defaultFS", "hdfs://127.0.0.1:9000");
        configuration.set("mapreduce.job.tracker", "localhost:54311");

        configuration.set("mapreduce.framework.name", "yarn");
        configuration.set("yarn.resourcemanager.address", "localhost:8032");

使用不同的大小写运行

案例 1:“使用 Hadoop 和 Yarn 命令”:成功精细工作

案例 2:“使用 Eclipse”:成功的精细工作

案例 3:“删除所有 configuration.set() 后使用 Java -jar”:

                    Configuration configuration = new Configuration();

        Run successful but not display Job status on Yarn (default port number 8088)

案例 4:“使用 Java -jar”:错误

     Find stack trace:Exception in thread "main" java.io.IOException: Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name and the correspond server addresses.
at org.apache.hadoop.mapreduce.Cluster.initialize(Cluster.java:120)
at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:82)
at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:75)
at org.apache.hadoop.mapreduce.Job$9.run(Job.java:1255)
at org.apache.hadoop.mapreduce.Job$9.run(Job.java:1251)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1556)
at org.apache.hadoop.mapreduce.Job.connect(Job.java:1250)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:1279)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1303)
at com.my.cache.run.MyTool.run(MyTool.java:38)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at com.my.main.Main.main(Main.java:45)

我请求您告诉我如何使用“Java -jar”命令运行 map-reduce 作业,并且还能够检查状态并登录 Yarn(默认端口 8088)。

为什么需要:想要创建一个 Web 服务并提交一个 map-reduce 作业。(不使用 Java 运行时库来执行 Yarn 或 Hadoop 命令)。

【问题讨论】:

  • 检查 mapred-site.xml 是否定义为 yarn
  • 它使用 hadoop 、yarn 和 eclipse 运行良好
  • 所以mapred-site.xml中没有错误

标签: eclipse hadoop mapreduce hadoop-yarn hadoop2


【解决方案1】:

在我看来,在没有 hadoop 命令的情况下运行 hadoop 应用程序是相当困难的。你最好使用 hadoop jar 而不是 java -jar。

我认为您的机器中没有 hadoop 环境。首先,您必须确保 hadoop 在您的机器上运行良好。

就个人而言,我更喜欢在 mapred-site.xml、core-site.xml、yarn-site.xml、hdfs-site.xml 中设置配置。我知道herehere安装hadoop集群的清晰教程

这一步,你可以在50070端口监控hdfs,8088端口监控yarn cluster,19888端口监控mapreduce作业历史。

然后,你应该证明你的 hdfs 环境和 yarn 环境运行良好。对于 hdfs 环境,您可以尝试使用简单的 hdfs 命令,如 mkdir、copyToLocal、copyFromLocal 等,对于 yarn 环境,您可以尝试示例 wordcount 项目。

拥有hadoop环境后,您可以创建自己的mapreduce应用程序(您可以使用任何IDE)。可能你需要this 来获取教程。编译并放入jar中。

打开你的终端,然后运行这个命令

hadoop jar <path to jar> <arg1> <arg2> ... <arg n>

希望对您有所帮助。

【讨论】:

  • 这一切都很好,而且设置也很好。问题是我想使用 Web 服务运行 map-reduce。使用 java 运行时库。感谢您的帖子
猜你喜欢
  • 1970-01-01
  • 2014-09-30
  • 2015-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-02
  • 1970-01-01
相关资源
最近更新 更多