【问题标题】:Authentication and Connection refused error while crawling using nutch使用 nutch 进行爬网时出现身份验证和连接被拒绝错误
【发布时间】:2014-04-16 11:51:13
【问题描述】:

我正在尝试使用 Nutch 1.7 抓取一些 url,但我面临

  1. 身份验证问题和

  2. 连接被拒绝异常。

  3. 根据日志,我可以看到它正在尝试使用 NTLM 进行身份验证,但之后它显示“需要重定向”并最终释放连接...(可以在 logpart-1 中看到)

根据

中的 Nutch 教程

http://wiki.apache.org/nutch/HttpAuthenticationSchemes#A_note_on_NTLM_domains

  1. 我已经在httpclient-auth.xml 文件中设置了身份验证配置:

  2. nutch-site.xmlnutch-default.xml 中定义httpclient 属性

    插件.includes 协议-(httpclient|http)|urlfilter-
    regex|parse-(text|html|tika)|index-(more|basic|anchor)|indexer-solr|scoring-
    opic|urlnormalizer-(pass|regex|basic)

  3. 还在nutch-site.xml中定义了auth配置文件。

    http.auth.file httpclient-auth.xml 'protocol-httpclient' 插件的身份验证配置文件。

但我没有成功!

是我没有以正确的方式配置身份验证还是遗漏了什么?

谁能帮我在 Nutch 中正确配置所需的身份验证?


附加完成hadoop.log:

logpart-1:authentication

2014-04-16 05:11:23,712 DEBUG httpclient.HttpMethodDirector - Authorization required
2014-04-16 05:11:23,712 DEBUG auth.AuthChallengeProcessor - Using authentication scheme: ntlm
2014-04-16 05:11:23,731 DEBUG auth.AuthChallengeProcessor - Authorization challenge processed
2014-04-16 05:11:23,733 DEBUG httpclient.HttpMethodDirector - Authentication scope: NTLM <any realm>@sp.zzz.com:80
2014-04-16 05:11:23,732 DEBUG fetcher.Fetcher - FetcherThread spin-waiting ...
2014-04-16 05:11:23,733 DEBUG fetcher.Fetcher - FetcherThread spin-waiting ...
2014-04-16 05:11:23,733 DEBUG httpclient.HttpMethodDirector - Retry authentication
2014-04-16 05:11:23,733 DEBUG fetcher.Fetcher - FetcherThread spin-waiting ...
2014-04-16 05:11:23,734 DEBUG httpclient.HttpMethodBase - Resorting to protocol version default close connection policy
2014-04-16 05:11:23,733 DEBUG cookie.CookieSpec - Unrecognized cookie attribute: name=HttpOnly, value=null
2014-04-16 05:11:23,734 DEBUG httpclient.HttpMethodBase - Should NOT close connection, using HTTP/1.1
2014-04-16 05:11:23,735 DEBUG httpclient.HttpMethodBase - Cookie accepted: "PHPSESSID=9f9378mvh9e720f5o3l0ibc1o7"
2014-04-16 05:11:23,735 DEBUG httpclient.HttpMethodDirector - Authenticating with NTLM <any realm>@sp.zzz.com:80
2014-04-16 05:11:23,735 DEBUG httpclient.HttpMethodDirector - Redirect required
2014-04-16 05:11:23,735 DEBUG params.HttpMethodParams - Credential charset not configured, using HTTP element charset
2014-04-16 05:11:23,735 DEBUG httpclient.HttpMethodBase - Should close connection in response to directive: close
2014-04-16 05:11:23,735 DEBUG httpclient.HttpConnection - Releasing connection back to connection manager.
2014-04-16 05:11:23,736 DEBUG httpclient.MultiThreadedHttpConnectionManager - Freeing connection, hostConfig=HostConfiguration[host=www.xxxportal.com]
2014-04-16 05:11:23,736 DEBUG util.IdleConnectionHandler - Adding connection at: 1397643083736
2014-04-16 05:11:23,736 DEBUG httpclient.MultiThreadedHttpConnectionManager - Notifying no-one, there are no waiting threads
2014-04-16 05:11:23,737 DEBUG httpclient.HttpMethodBase - Adding Host request header
2014-04-16 05:11:23,744 DEBUG httpclient.HttpMethodDirector - Authorization required
2014-04-16 05:11:23,744 DEBUG auth.AuthChallengeProcessor - Using authentication scheme: ntlm
2014-04-16 05:11:23,744 DEBUG auth.AuthChallengeProcessor - Authorization challenge processed
2014-04-16 05:11:23,744 DEBUG httpclient.HttpMethodDirector - Authentication scope: NTLM <any realm>@sp.zzz.com:80
2014-04-16 05:11:23,745 INFO  regex.RegexURLNormalizer - can't find rules for scope 'fetcher', using default
2014-04-16 05:11:23,745 DEBUG httpclient.HttpMethodDirector - Credentials required
2014-04-16 05:11:23,745 DEBUG httpclient.HttpMethodDirector - Credentials provider not available
2014-04-16 05:11:23,745 INFO  httpclient.HttpMethodDirector - Failure authenticating with NTLM <any realm>@sp.zzz.com:80
2014-04-16 05:11:23,745 DEBUG httpclient.HttpMethodBase - Resorting to protocol version default close connection policy
2014-04-16 05:11:23,745 DEBUG httpclient.HttpMethodBase - Should NOT close connection, using HTTP/1.1
2014-04-16 05:11:23,746 DEBUG httpclient.HttpConnection - Releasing connection back to connection manager.
2014-04-16 05:11:23,746 DEBUG httpclient.MultiThreadedHttpConnectionManager - Freeing connection, hostConfig=HostConfiguration[host=sp.zzz.com]

我得到的其他链接很少

处理请求时捕获的 I/O 异常 (java.net.ConnectException):连接被拒绝:连接

我没有使用任何代理,并且我仍然关闭了系统中的所有防火墙设置。不知道为什么我得到连接被拒绝异常


在这里,我也无法找出连接被拒绝异常的确切原因。

请帮助我理解这个案例中的确切问题。

Attaching the complete hadoop.log!

logPart2-connection 拒绝。

2014-04-16 05:11:26,443 INFO  fetcher.Fetcher - * queue: www.xxxportal.com
2014-04-16 05:11:26,443 INFO  fetcher.Fetcher -   maxThreads    = 1
2014-04-16 05:11:26,444 INFO  fetcher.Fetcher -   inProgress    = 0
2014-04-16 05:11:26,444 INFO  fetcher.Fetcher -   crawlDelay    = 5000
2014-04-16 05:11:26,444 INFO  fetcher.Fetcher -   minCrawlDelay = 0
2014-04-16 05:11:26,444 INFO  fetcher.Fetcher -   nextFetchTime = 1397643088739
2014-04-16 05:11:26,444 INFO  fetcher.Fetcher -   now           = 1397643086444
2014-04-16 05:11:26,444 INFO  fetcher.Fetcher -   0. www.xxxportal.com/profiles/
2014-04-16 05:11:26,445 INFO  fetcher.Fetcher -   1. www.xxxportal.com/wiki/index.php
2014-04-16 05:11:26,445 INFO  fetcher.Fetcher -   2. www.xxxportal.com/sop/
2014-04-16 05:11:26,560 DEBUG httpclient.HttpMethodDirector - Closing the connection.
2014-04-16 05:11:26,560 INFO  httpclient.HttpMethodDirector - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2014-04-16 05:11:26,560 DEBUG httpclient.HttpMethodDirector - Connection refused: connect
java.net.ConnectException: Connection refused: connect
                at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
                at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
                at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
                at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
                at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
                at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
                at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
                at java.net.Socket.connect(Socket.java:579)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:606)
                at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
                at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
                at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
                at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
                at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
                at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
                at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
                at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
                at org.apache.nutch.protocol.httpclient.HttpResponse.<init>(HttpResponse.java:94)
                at org.apache.nutch.protocol.httpclient.Http.getResponse(Http.java:154)
                at org.apache.nutch.protocol.http.api.HttpRobotRulesParser.getRobotRulesSet(HttpRobotRulesParser.java:75)
                at org.apache.nutch.protocol.RobotRulesParser.getRobotRulesSet(RobotRulesParser.java:157)
                at org.apache.nutch.protocol.http.api.HttpBase.getRobotRules(HttpBase.java:391)
                at org.apache.nutch.fetcher.Fetcher$FetcherThread.run(Fetcher.java:676)
2014-04-16 05:11:26,564 INFO  httpclient.HttpMethodDirector - Retrying request
2014-04-16 05:11:26,565 DEBUG httpclient.HttpConnection - Open connection to www.zzzlearninglounge.com:80

【问题讨论】:

    标签: nutch


    【解决方案1】:

    1) 从日志中可以清楚地看到,您的特定站点上的 NTLM 身份验证失败。

    这里你必须先检查用户名/密码。

    然后是Auth Basic/NTLM/的方案 然后是你要认证的端口

    如果您验证这 3 点并使用正确的值,那么您的身份验证问题应该会得到解决...

    【讨论】:

    • 你能告诉我是否有任何方法让 apache nutch 在爬行时忽略 robots.txt。我正在使用 nutch 2.2.1。我发现“RobotRulesParser.java”(完整路径:-src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java)负责读取和解析机器人。文本文件。有什么办法可以修改它以忽略 robots.txt 并继续爬行?
    • 首先,如果您要抓取任何外部网站,我们应该尊重 robots.txt 文件。否则您将面临风险 - 您的 IP 被禁止或更糟可能是任何法律案件。 2) 如果您的站点是内部站点并且不暴露给外部世界,那么您应该更改 robots.txt 文件以允许您的爬虫。 3)您可以尝试以下选项:AFAIK;在 Fetcher.java 文件中 -> if (!rules.isAllowed(fit.u.toString())) { } 这是负责阻止 url 的块。所以你可以围绕这个代码块来解决你的问题。
    猜你喜欢
    • 1970-01-01
    • 2014-08-20
    • 2014-12-23
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多