运行 Hadoop 程序时,为了防止覆盖结果,程序指定的输出目录(如 output)不能存在,否则会提示错误,因此运行前需要先删除输出目录。在实际开发应用程序时,可考虑在程序中加上如下代码,能在每次运行时自动删除输出目录,避免繁琐的命令行操作:

  1. Configuration conf = new Configuration();
  2. Job job = new Job(conf);
  3. /* 删除输出目录 */
  4. Path outputPath = new Path(args[1]);
  5. outputPath.getFileSystem(conf).delete(outputPath, true);

若要关闭 Hadoop,则运行

  1. ./sbin/stop-dfs.sh

注意

下次启动 hadoop 时,无需进行 NameNode 的初始化,只需要运行 ./sbin/start-dfs.sh 就可以!






相关文章:

  • 2021-08-13
  • 2022-02-18
  • 2021-09-22
  • 2022-12-23
  • 2021-12-09
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2021-12-01
  • 2021-04-03
  • 2021-10-06
  • 2023-03-10
  • 2021-12-28
  • 2021-11-18
相关资源
相似解决方案