我使用 Java 编写了一个 Map reduce 作业。 设置配置
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:“在删除所有配置后使用 Java -jar.set()”:
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 命令)。
最佳答案
在我看来,没有hadoop命令就很难运行hadoop应用程序。你最好使用 hadoop jar 而不是 java -jar。
我想你的机器上没有hadoop环境。首先,您必须确保 hadoop 在您的机器上运行良好。
就个人而言,我更喜欢在 mapred-site.xml、core-site.xml、yarn-site.xml、hdfs-site.xml 中设置配置。我知道在 here 中安装 hadoop 集群的清晰教程。
这一步,你可以在50070端口监控hdfs,在8088端口监控yarn cluster,在19888端口监控mapreduce job history。
然后,你应该证明你的hdfs环境和yarn环境运行良好。对于 hdfs 环境,您可以尝试使用简单的 hdfs 命令,如 mkdir、copyToLocal、copyFromLocal 等,对于 yarn 环境,您可以尝试示例 wordcount 项目。
拥有hadoop环境后,您可以创建自己的mapreduce应用程序(您可以使用任何IDE)。可能你需要 this教程。将其编译并放入 jar 中。
打开你的终端,然后运行这个命令
hadoop jar <path to jar> <arg1> <arg2> ... <arg n>
希望这对您有所帮助。
关于eclipse - 如何使用 Java -jar 命令运行 map reduce 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25301545/