rails server error `initialize': getaddrinfo: Name or service not known (SocketError)
Posted
技术标签:
【中文标题】rails server error `initialize\': getaddrinfo: Name or service not known (SocketError)【英文标题】:rails server error `initialize': getaddrinfo: Name or service not known (SocketError)rails server error `initialize': getaddrinfo: Name or service not known (SocketError) 【发布时间】:2017-04-14 01:05:41 【问题描述】:我正在尝试设置一个新的 Rails 应用程序并不断收到以下堆栈跟踪:
=> Booting Puma
=> Rails 5.1.0.rc1 application starting in development on http://linux-my4o:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.4.0-p0), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://linux-my4o:9292
Exiting
/home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:269:in `initialize': getaddrinfo: Name or service not known (SocketError)
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:269:in `new'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:269:in `add_tcp_listener'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:105:in `block in parse'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:88:in `each'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/binder.rb:88:in `parse'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/runner.rb:144:in `load_and_bind'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/single.rb:87:in `run'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/puma/launcher.rb:172:in `run'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/puma-3.8.2/lib/rack/handler/puma.rb:64:in `run'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/rack-2.0.1/lib/rack/server.rb:296:in `start'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:44:in `start'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:130:in `block in perform'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:125:in `tap'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands/server/server_command.rb:125:in `perform'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/command/base.rb:63:in `perform'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/command.rb:44:in `invoke'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/railties-5.1.0.rc1/lib/rails/commands.rb:16:in `<top (required)>'
from /home/chris/Projects/cwatsondev-api/bin/rails:9:in `require'
from /home/chris/Projects/cwatsondev-api/bin/rails:9:in `<top (required)>'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
from /home/chris/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
from /home/chris/Projects/cwatsondev-api/bin/spring:15:in `require'
from /home/chris/Projects/cwatsondev-api/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
我以前在运行 Rails 服务器时从未见过这样的错误。我在 OpenSuse Tumbleweed 上使用 Rails 5.1.0.rc1。在我看来,主机名 linux-my4o 有问题。
【问题讨论】:
【参考方案1】:我想通了。只需在我的 etc/hosts
文件中添加一个新行。
127.0.0.1 linux-my4o
【讨论】:
我的主机文件中有127.0.0.1 localhost
。但它不起作用。知道为什么吗?【参考方案2】:
我通过在我的环境变量中添加以下几行来修复我的问题。对于 linux,我添加了以下行
export HOST="localhost"
如果这不起作用,尤其是因为 rails 抱怨 HOST
envvar 将被贬值,请改用它
export BINDING="localhost"
【讨论】:
以上是关于rails server error `initialize': getaddrinfo: Name or service not known (SocketError)的主要内容,如果未能解决你的问题,请参考以下文章
Mysql Lost connection to MySQL server at ‘reading initial communication packet', system error: 0
2013 - Lost connection to MySQL server at ‘reading initial communication packet , system error: 0 “I
解决MySQL Error (2013): Lost connection to MySQL server at waiting for initial communication packet(示例
Lost connection to MySQL server at ‘reading initial communication packet', system error: 0 mysq
解决MySQL Error (2013): Lost connection to MySQL server at waiting for initial communication packet
解决MySQL Error (2013): Lost connection to MySQL server at waiting for initial communication packet