ruby-on-rails 地址已在使用中-绑定(2)用于“0.0.0.0“端口3000(错误号::EADDRINUSE)

hc8w905p  于 2023-01-27  发布在  Ruby
关注(0)|答案(4)|浏览(257)

首先,我知道this error has already been listed here,但问题不同。
我有一个Rails 4应用程序,我曾经在Puma上运行过。
然后,我的一个朋友开发了这个应用程序,并建议我们使用福尔曼代替。
所以,我过去在终端中使用rails s在本地运行应用程序。
现在,我应该使用foreman start来执行此操作。
问题是,几乎每次我尝试启动应用程序,我得到以下错误:

foreman start
08:42:28 web.1  | started with pid 3398
08:42:28 web.1  | [3398] Puma starting in cluster mode...
08:42:28 web.1  | [3398] * Version 2.13.4 (ruby 2.2.1-p85), codename: A Midsummer Code's Dream
08:42:28 web.1  | [3398] * Min threads: 5, max threads: 5
08:42:28 web.1  | [3398] * Environment: development
08:42:28 web.1  | [3398] * Process workers: 2
08:42:28 web.1  | [3398] * Preloading application
08:42:31 web.1  | [3398] * Listening on tcp://0.0.0.0:3000
08:42:31 web.1  | /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:231:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:231:in `new'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:231:in `add_tcp_listener'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:98:in `block in parse'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:84:in `each'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/binder.rb:84:in `parse'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/runner.rb:119:in `load_and_bind'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/cluster.rb:304:in `run'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/lib/puma/cli.rb:215:in `run'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/gems/puma-2.13.4/bin/puma:10:in `<top (required)>'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/puma:23:in `load'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/puma:23:in `<main>'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
08:42:31 web.1  |   from /Users/TXC/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
08:42:31 web.1  | exited with code 1
08:42:31 system | sending SIGTERM to all processes

我该怎么补救呢?

  • ———-

更新:我还尝试了以下两种方法,as recommended here

ps aux | grep rails
3547   0,0  0,0  2434840    752 s000  S+    8:48     0:00.00 grep rails

但是没有ruby bin/rails server
以及:

lsof -wni tcp:3000
COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    808  TXC    8u  IPv4 0x4f6da234a6116dab      0t0  TCP *:hbci (LISTEN)
ruby    809  TXC    8u  IPv4 0x4f6da234a6116dab      0t0  TCP *:hbci (LISTEN)
ruby    810  TXC    8u  IPv4 0x4f6da234a6116dab      0t0  TCP *:hbci (LISTEN)

但我不知道我该拿这个怎么办。
每次我想在本地启动应用程序时,我都应该重新启动计算机吗?

ezykj2lf

ezykj2lf1#

如果使用的是Puma,请运行ps aux | grep puma

PID   TT  STAT      TIME COMMAND
4662   0.0  0.1  4601556   8820   ??  S    10:48am   1:10.37 puma: cluster worker 1: 4395 [my-app]
4661   0.0  0.1  4882676  10300   ??  S    10:48am   2:14.49 puma: cluster worker 0: 4395 [my-app]
4395   ??  S      0:16.88 puma 3.12.1 (tcp://0.0.0.0:3000) [my-app]

那就杀了他们。
kill -9 4395 4661 4662

rjee0c15

rjee0c152#

我也有同样的问题,小调查后发现ntop
ntop -在web浏览器中显示网络使用
1.网络统计-tulpn
TCP 0 00.0.0.0:3000 0.0.0.0电话:* 收听-
1.国家127.0.0.1
3000/tcp开放式点对点协议

n9vozmp4

n9vozmp43#

This code将自动执行修复过程
此代码将自动为您修复它
https://github.com/pailoro/rails_server_killer
修复rails服务器上“地址已在使用”问题的ruby脚本
在终端上运行它:
ruby铁路服务器杀手.rb

ni65a41a

ni65a41a4#

对我来说,解决方法很简单,但是请注意(就像命令说的那样)关闭ALLruby示例,你可以用比这更细粒度的方法来解决,比如a strategy like you mentioned

killall ruby

所有其他的事情都没有帮助我:

killall rails
# -> rails: no process found
killall puma
# -> puma: no process found

您还可以考虑以下可能相关的问题解答:

相关问题