rails 服务器无法启动; getaddrinfo:提供节点名或服务名,或未知(SocketError)

Posted

技术标签:

【中文标题】rails 服务器无法启动; getaddrinfo:提供节点名或服务名,或未知(SocketError)【英文标题】:rails server cannot start; getaddrinfo: nodename nor servname provided, or not known (SocketError) 【发布时间】:2015-04-30 09:26:11 【问题描述】:

我还没有找到解决问题的方法,但是几天前确实有人问过同样的问题 - (Rails Server Keeps Exiting (SocketError))

启动 Rails 服务器后,系统返回一些我无法理解的错误。为了在我的 Mac 上安装 Ruby on Rails,我做了http://railsapps.github.io/installrubyonrails-mac.html 中列出的所有操作

这是我的终端回复:

$ rails server
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-02-28 02:14:46] INFO  WEBrick 1.3.1
[2015-02-28 02:14:46] INFO  ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
Exiting
/Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:232:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError)
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:232:in `foreach'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/socket.rb:459:in `tcp_server_sockets'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/utils.rb:70:in `create_listeners'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:133:in `listen'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:114:in `initialize'
    from /Users/alexshel/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:45:in `initialize'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/rack-1.6.0/lib/rack/handler/webrick.rb:32:in `new'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/rack-1.6.0/lib/rack/handler/webrick.rb:32:in `run'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/rack-1.6.0/lib/rack/server.rb:286:in `start'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/server.rb:80:in `start'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@global/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/alexshel/workspace/myapp/bin/rails:8:in `require'
    from /Users/alexshel/workspace/myapp/bin/rails:8:in `<top (required)>'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client/rails.rb:27:in `load'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client/rails.rb:27:in `call'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client/command.rb:7:in `call'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/client.rb:26:in `run'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/bin/spring:48:in `<top (required)>'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/binstub.rb:11:in `load'
    from /Users/alexshel/.rvm/gems/ruby-2.2.0@myapp/gems/spring-1.3.3/lib/spring/binstub.rb:11:in `<top (required)>'
    from /Users/alexshel/workspace/myapp/bin/spring:13:in `require'
    from /Users/alexshel/workspace/myapp/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

请帮忙。

【问题讨论】:

本地主机可能有些奇怪。你能ping通本地主机吗? 您的/etc/hosts 文件中似乎没有定义localhost 是的,我无法 ping 本地主机 【参考方案1】:

通过在private/etc/hosts文件中添加127.0.0.1 localhost记录解决了这个问题,之前由于某种原因被删除了。

【讨论】:

【参考方案2】:

对于遇到此问题的任何未来用户,我可以通过在我的 private/etc/hosts 文件末尾添加以下内容来解决它。

127.0.0.1 YOURNAME-MacBook-Pro.local

YOURNAME-MacBook-Pro 更新为您的机器名称,希望您一切就绪。

【讨论】:

P.S.您可以在“系统偏好设置”>“共享”中找到/更改您的 OS X 机器的名称(至少在 High Sierra 上),您会看到一些文本,例如“本地网络上的计算机可以在以下位置访问您的计算机:MacBook-Pro-2。本地”【参考方案3】:

尝试更改为 UNIX 编码:

brew install dos2unix
sudo dos2unix -c mac /private/etc/hosts

【讨论】:

【参考方案4】:

我在 Rails 环境中遇到了类似的 Redis 问题。我将端口号和“Redis”添加到我的 Mac 上的 /private/etc/hosts 文件中,它解决了错误。假设您的端口号是“1234”,您将添加:1234 redis。对于 localhost,您将添加:127.0.0.1 localhost。我希望这至少能为您的特定问题提供一些线索。

【讨论】:

以上是关于rails 服务器无法启动; getaddrinfo:提供节点名或服务名,或未知(SocketError)的主要内容,如果未能解决你的问题,请参考以下文章

无法在生产服务器上为 websocket-rails 启动独立服务器

rails 服务器无法启动; getaddrinfo:提供节点名或服务名,或未知(SocketError)

rails 服务器无法在 OSX 10.6.5 上使用 rvm 和 ruby​​ 1.9.2-p0 启动 mysql2

Ruby on Rails:无法加载rack / handler /

话语服务器无法启动与redis相关的错误

Rails 控制台无法在服务器上运行