简体   繁体   English

Apache Nutch 没有暴露其 API

[英]Apache Nutch doesn't expose its API

I'm trying to use Apache Nutch 1.x Rest API.我正在尝试使用 Apache Nutch 1.x Rest API。 I use docker images to set up Nutch and Solr.我使用 docker 图像来设置 Nutch 和 Solr。 You can see the demo repo in here你可以在这里看到演示 repo

Apache Nutch uses Solr as its dependents. Apache Nutch 使用 Solr 作为其依赖项。 Solr works great, I'm able to reach its GUI at localhost:8983 . Solr 效果很好,我可以在localhost:8983访问它的 GUI。

However, I cannot reach Apache Nutch's API at localhost:8081 .但是,我无法在localhost:8081到达 Apache Nutch 的 API 。 The problem starts here.问题从这里开始。 The Apache Nutch 1.X RESTAPI doc indicates that I can start the server like this 2. :~$ bin/nutch startserver -port <port_number> [If the port option is not mentioned then by default the server starts on port 8081] Apache Nutch 1.X RESTAPI 文档表明我可以像这样启动服务器2. :~$ bin/nutch startserver -port <port_number> [If the port option is not mentioned then by default the server starts on port 8081]

Which I am doing in docker-compose.yml file.我在docker-compose.yml文件中做的。 I'm also exposing the ports to the outside.我还将端口暴露在外面。

    ports:
       - "8080:8080"
       - "8081:8081"

But I wasn't able to successfully call the API from my computer.但是我无法从我的计算机上成功调用 API。

The rest API documentation says that if I send a get request to /admin endpoint, I would get a response. rest API 文档说,如果我向/admin端点发送获取请求,我会得到响应。

GET /admin

When I try this with Postman or from the browser, it cannot reach out to the server and gives me back a 500 error.当我使用 Postman 或从浏览器尝试此操作时,它无法访问服务器并返回 500 错误。

However, when I get inside of the container with docker exec -it and try to curl localhost:8081/admin , I get the correct response.但是,当我使用docker exec -it进入容器并尝试 curl localhost:8081/admin时,我得到了正确的响应。 So within the container the API is up and running, but it is not exposed to outside.因此,在容器内 API 已启动并运行,但并未暴露在外部。

In one of my tryouts, I have added a frontend application in another container and send rest requests to Solr and Nutch containers.在我的一次试用中,我在另一个容器中添加了一个前端应用程序,并将 rest 请求发送到 Solr 和 Nutch 容器。 Solr worked, Nutch failed with 500. This tells me that Nutch container is not only unreachable to the outside world, it is also unreachable to the containers within the same network. Solr 工作,Nutch 以 500 失败。这告诉我,Nutch 容器不仅外部无法访问,而且同一网络内的容器也无法访问。

Any idea how to workaround this problem?知道如何解决这个问题吗?

nutch by default only reply to requests from localhost : nutch默认只回复来自localhost的请求:

bash-5.1# /root/nutch/bin/nutch startserver -help
usage: NutchServer [-help] [-host <host>] [-port <port>]
 -help          Show this help
 -host <host>   The host to bind the Nutch Server to. Default is
                localhost.

So you need to start it with -host 0.0.0.0 to be able to reach it from the host machine or another container:因此,您需要使用-host 0.0.0.0启动它,以便能够从主机或其他容器访问它:

services:
  nutch:
    image: 'apache/nutch:latest'
    command: '/root/nutch/bin/nutch startserver -port 8081 -host 0.0.0.0'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM