gpt4 book ai didi

ruby-on-rails - 无法打开到本地主机的 TCP 连接:9200(连接被拒绝 - 连接(2)用于 "localhost"端口 9200)(Faraday::ConnectionFailed)

转载 作者:可可西里 更新时间:2023-11-01 02:32:57 27 4
gpt4 key购买 nike

我收到错误:Puma 发现此错误:无法打开到本地主机的 TCP 连接:9200(连接被拒绝 - 连接(2)用于“本地主机”端口 9200)(Faraday::ConnectionFailed)在我的 ubuntu rails 应用程序中14.04.

下面是我在终端中进行 Elasticsearch 的输出:

prashanth@prashanth-OptiPlex-390:~$ sudo service elasticsearch restart
* Starting Elasticsearch Server prashanth@prashanth-OptiPlex-390:~$ sudo service elasticsearch start
* Starting Elasticsearch Server * Already running. [ OK ]
prashanth@prashanth-OptiPlex-390:~$ curl -X GET 'http://localhost:9200'
curl: (7) Failed to connect to localhost port 9200: Connection refused
prashanth@prashanth-OptiPlex-390:~$

这是我在 /etc/elasticsearch/elasticsearch.yml 文件中的 Elasticsearch 设置

network.host: 127.0.0.1
transport.tcp.port: 9200
http.port: 9200

错误描述:

Puma caught this error: Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200) (Faraday::ConnectionFailed)
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:878:in `connect'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:852:in `start'
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:1398:in `request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:83:in `perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:41:in `block in call'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:88:in `with_net_http_connection'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/adapter/net_http.rb:33:in `call'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/rack_builder.rb:139:in `build_response'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/faraday-0.10.1/lib/faraday/connection.rb:377:in `run_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/transport/http/faraday.rb:23:in `block in perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/transport/base.rb:257:in `perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/home/prashanth/.rvm/gems/ruby-2.3.1/gems/elasticsearch-transport-5.0.0/lib/elasticsearch/transport/client.rb:128:in `perform_request'

最佳答案

在您发布的设置中,您的 HTTP 和 TCP 端口分配了相同的端口号

network.host: 127.0.0.1
transport.tcp.port: 9200
http.port: 9200

我建议更改 transport.tcp.port 并重试。

尝试使用默认值,除非您已经使用了端口 9300:

network.host: 127.0.0.1
transport.tcp.port: 9300
http.port: 9200

如果问题仍然存在,您可能需要在防火墙程序上打开端口。在 Ubuntu 上,这可能是 UFW。

如果您的服务脚本有一个状态函数,这可能会告诉您您的 Elasticsearch 实例是否已正常启动。如果做不到这一点,您可以使用 ps aux 来确定它是否正在运行。

$ sudo service elasticsearch status

或者

$ ps aux | grep elasticsearch

正如在类似问题中所指出的,当 Elasticsearch 未运行时,cURL 会给出拒绝连接错误(来源:Faraday::ConnectionFailed, Connection refused - connect(2) for “localhost” port 9200 Error Ruby on Rails)。

关于ruby-on-rails - 无法打开到本地主机的 TCP 连接:9200(连接被拒绝 - 连接(2)用于 "localhost"端口 9200)(Faraday::ConnectionFailed),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42526394/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com