Ruby on Rails - 已经在使用的地址 - bind(2)for“0.0.0.0”port 3000(Errno :: EADDRINUSE)

时间:2017-09-12 13:28:47

标签: ruby-on-rails server port puma

当我尝试从本地计算机启动rails服务器时,收到以下错误消息。

/Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `new'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `add_tcp_listener'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:105:in `block in parse'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:88:in `each'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:88:in `parse'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/runner.rb:144:in `load_and_bind'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/cluster.rb:391:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/launcher.rb:174:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/rack/handler/puma.rb:69:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rack-2.0.3/lib/rack/server.rb:297:in `start'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/server.rb:104:in `start'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:85:in `server'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/zachdobbs/sample_app/bin/rails:9:in `require'
from /Users/zachdobbs/sample_app/bin/rails:9:in `<top (required)>'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/zachdobbs/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /Users/zachdobbs/sample_app/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

这个错误突然发生,我不确定它的原因是什么。当我在网上看时,我注意到问题可能是在端口3000上运行的另一个服务,但是当我尝试运行'lsof -i tcp:3000'时,我没有得到任何结果。

在puma.rb中,我定义。

port        ENV.fetch("PORT") { 3000 }
rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

当我将端口值更改为8080之类的服务器时,服务器将运行。我很困惑为什么服务器不会在端口3000上启动。我试图运行的每个命令都显示我没有在该端口上运行的服务。

2 个答案:

答案 0 :(得分:2)

我知道这是一篇很老的帖子,但我不得不回答,以防其他人像我一样来到这里。

当您在 puma 配置中声明 portbind 命令时,它将尝试绑定到所有这些端口或地址。

在本例中,您指定了 port 两次,因此它试图同时绑定到两个,第二个将失败。

答案 1 :(得分:0)

尝试以下方法:

> sudo ps ax | grep rails
#1338 pts/1    Sl+    0:06 /usr/bin/ruby2.3 bin/rails c
#1707 pts/0    Rl+    0:07 /usr/bin/ruby2.3 bin/rails s

> sudo kill -9 1707

> rails s