0

我正在尝试按照NutchTutorial运行基本爬网:

bin/nutch crawl urls -dir crawl -depth 3 -topN 5

所以我用 Solr 安装和设置了 Nutch。我将我的 $JAVA_HOME 设置为我的.bashrcto /usr/lib/jvm/java-1.6.0-openjdk-amd64.

当我从 nutch 主目录运行时,我没有看到任何问题bin/nutch,但是当我尝试像上面那样运行爬网时,我收到以下错误:

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: /usr/share/nutch/logs/hadoop.log (Permission denied)
        at java.io.FileOutputStream.openAppend(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:207)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
        at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
        at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:164)
        at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:216)
        at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:257)
        at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:133)
        at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:97)
        at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:689)
        at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
        at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
        at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:270)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
        at org.apache.nutch.crawl.Crawl.<clinit>(Crawl.java:43)
log4j:ERROR Either File or DatePattern options are not set for appender [DRFA].
solrUrl is not set, indexing will be skipped...
crawl started in: crawl
rootUrlDir = urls
threads = 10
depth = 3
solrUrl=null
topN = 5
Injector: starting at 2013-06-28 16:24:53
Injector: crawlDb: crawl/crawldb
Injector: urlDir: urls
Injector: Converting injected urls to crawl db entries.
Injector: total number of urls rejected by filters: 0
Injector: total number of urls injected after normalization and filtering: 1
Injector: Merging injected urls into crawl db.
Exception in thread "main" java.io.IOException: Job failed!
        at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1357)
        at org.apache.nutch.crawl.Injector.inject(Injector.java:296)
        at org.apache.nutch.crawl.Crawl.run(Crawl.java:132)
        at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
        at org.apache.nutch.crawl.Crawl.main(Crawl.java:55)

我怀疑它可能与文件权限有关,因为我必须sudo在这台服务器上的几乎所有东西上运行,但是如果我运行相同的 crawl 命令,sudo我会得到:

Error: JAVA_HOME is not set.

所以我觉得我有一个catch-22 的情况。我应该能够使用 运行此命令sudo,还是我需要做一些其他事情,这样我就不必运行它sudo并且它会工作,或者这里是否还有其他完全在发生的事情?

4

2 回答 2

1

看来,作为普通用户,您没有写入权限/usr/share/nutch/logs/hadoop.log,这作为安全功能是有意义的。

为了解决这个问题,创建一个简单的 bash 脚本:

#!/bin/sh
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64
bin/nutch crawl urls -dir crawl -depth 3 -topN 5

将其另存为nutch.sh,然后运行它sudo

sudo sh nutch.sh
于 2013-06-28T21:54:01.317 回答
0

解决此问题的关键是将JAVA_HOME变量添加到您的sudo环境中。例如,键入envand sudo env,您会看到JAVA_HOME未设置为sudo. 要解决此问题,您需要添加路径。

  1. 运行sudo visudo以编辑您的/etc/sudoers文件。(不要使用标准文本编辑器。这个特殊的 vi 文本编辑器将在允许您保存之前验证语法。)
  2. 添加这一行:

    Defaults env_keep+="JAVA_HOME"
    

    在该Defaults env_keep部分的末尾。

  3. 重启
于 2015-03-31T21:02:26.613 回答