我收到错误:Puma发现了这个错误:无法打开到localhost的TCP连接:9200(连接被拒绝 - 连接(2)for“localhost”端口9200)(Faraday :: ConnectionFailed)在ubuntu的rails应用程序中14.04。
下面是我在终端弹性搜索的输出:
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
文件
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'
答案 0 :(得分:1)
在您发布的设置中,您的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)。
答案 1 :(得分:0)
您有Docker吗?对我而言,唯一的解决方案是完全卸载Docker。 另外,我认为问题出在码头工人使用的端口上。
如果您不像我那样使用很多,只需将其删除即可。