簡體   English   中英

Apache Nutch 沒有暴露其 API

[英]Apache Nutch doesn't expose its API

我正在嘗試使用 Apache Nutch 1.x Rest API。 我使用 docker 圖像來設置 Nutch 和 Solr。 你可以在這里看到演示 repo

Apache Nutch 使用 Solr 作為其依賴項。 Solr 效果很好,我可以在localhost:8983訪問它的 GUI。

但是,我無法在localhost:8081到達 Apache Nutch 的 API 。 問題從這里開始。 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]

我在docker-compose.yml文件中做的。 我還將端口暴露在外面。

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

但是我無法從我的計算機上成功調用 API。

rest API 文檔說,如果我向/admin端點發送獲取請求,我會得到響應。

GET /admin

當我使用 Postman 或從瀏覽器嘗試此操作時,它無法訪問服務器並返回 500 錯誤。

但是,當我使用docker exec -it進入容器並嘗試 curl localhost:8081/admin時,我得到了正確的響應。 因此,在容器內 API 已啟動並運行,但並未暴露在外部。

在我的一次試用中,我在另一個容器中添加了一個前端應用程序,並將 rest 請求發送到 Solr 和 Nutch 容器。 Solr 工作,Nutch 以 500 失敗。這告訴我,Nutch 容器不僅外部無法訪問,而且同一網絡內的容器也無法訪問。

知道如何解決這個問題嗎?

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.

因此,您需要使用-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