Ruby-on-rails 无法打开到 localhost:9200 的 TCP 连接(连接被拒绝 - “本地主机”端口 9200 的连接(2))(Faraday::ConnectionFailed)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42526394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200) (Faraday::ConnectionFailed)
提问by John
I am getting the error: Puma caught this error: Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200) (Faraday::ConnectionFailed) in my rails application in ubuntu 14.04.
我收到错误:Puma 在 ubuntu 14.04 的 Rails 应用程序中发现了这个错误:无法打开到 localhost:9200 的 TCP 连接(连接被拒绝 - “本地主机”端口 9200 的连接(2))(Faraday::ConnectionFailed)。
below is the output of my elastic search in terminal:
以下是我在终端中的弹性搜索的输出:
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:~$
here are the my elastic search settings in /etc/elasticsearch/elasticsearch.ymlfile
这是我在/etc/elasticsearch/elasticsearch.yml文件中的弹性搜索设置
network.host: 127.0.0.1
transport.tcp.port: 9200
http.port: 9200
error description:
错误描述:
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'
回答by Donglecow
In the settings you posted, your HTTP and TCP ports have the same port number assigned
在您发布的设置中,您的 HTTP 和 TCP 端口分配了相同的端口号
network.host: 127.0.0.1
transport.tcp.port: 9200
http.port: 9200
I would suggest changing the transport.tcp.portand trying again.
我建议更改transport.tcp.port并重试。
Try using the defaults unless you already have port 9300 in use:
尝试使用默认值,除非您已经使用了端口 9300:
network.host: 127.0.0.1
transport.tcp.port: 9300
http.port: 9200
If you are still facing issues, you may need to open up the ports on your firewall program. On Ubuntu, this is likely UFW.
如果您仍然遇到问题,则可能需要打开防火墙程序上的端口。在 Ubuntu 上,这可能是 UFW。
If your service script has a status function, this may tell you if your Elasticsearch instance has started up properly or not. Failing this, you can use ps auxto determine if it is running.
如果您的服务脚本具有状态函数,这可能会告诉您您的 Elasticsearch 实例是否已正确启动。如果失败,您可以使用ps aux它来确定它是否正在运行。
$ sudo service elasticsearch status
Or
或者
$ ps aux | grep elasticsearch
As pointed out in similar questions, cURL can give a refused connection error when Elasticsearch isn't running (source: Faraday::ConnectionFailed, Connection refused - connect(2) for “localhost” port 9200 Error Ruby on Rails).
正如在类似问题中所指出的那样,当 Elasticsearch 未运行时,cURL 可能会出现拒绝连接错误(来源:Faraday::ConnectionFailed,连接被拒绝 - connect(2) for “localhost” port 9200 Error Ruby on Rails)。
回答by Lucas Riboli
Do you have Docker? The only solution for me was unninstall Docker completely. Otherwhise, i think the problem is something about the port that docker use.
你有 Docker 吗?对我来说唯一的解决方案是完全卸载 Docker。否则,我认为问题出在 docker 使用的端口上。
If you don't use alot like me, just remove it and you're good to go.
如果您不像我那样经常使用,只需将其删除即可。

