Ruby-on-rails 地址已在使用 - bind(2) (Errno::EADDRINUSE)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31039998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Address already in use - bind(2) (Errno::EADDRINUSE)
提问by Cornelius Wilson
I am trying to deploy Rails app with the Puma web server. When trying to start Puma server with a config file bundle exec puma -C config/puma.rbI get an error that the address is already in use.
我正在尝试使用 Puma Web 服务器部署 Rails 应用程序。尝试使用配置文件启动 Puma 服务器时bundle exec puma -C config/puma.rb,出现地址已被使用的错误。
Does someone know how to fix this?
有人知道如何解决这个问题吗?
bundle exec puma -C config/puma.rb
[23699] Puma starting in cluster mode...
[23699] * Version 2.11.3 (ruby 2.0.0-p353), codename: Intrepid Squirrel
[23699] * Min threads: 5, max threads: 5
[23699] * Environment: development
[23699] * Process workers: 2
[23699] * Preloading application
Jdbc-MySQL is only for use with JRuby
[23699] * Listening on tcp://0.0.0.0:3000
/.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `new'
from /Users/lexi87/.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `add_tcp_listener'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:96:in `block in parse'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:82:in `each'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:82:in `parse'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/runner.rb:119:in `load_and_bind'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/cluster.rb:302:in `run'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/cli.rb:216:in `run'
from /rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/bin/puma:10:in `<top (required)>'
from /.rvm/gems/ruby-2.0.0-p353/bin/puma:23:in `load'
from /.rvm/gems/ruby-2.0.0-p353/bin/puma:23:in `<main>'
from /.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
from /.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
回答by Zoker
You need to use kill -9 59780with 59780replaced with found PID number (use lsof -wni tcp:3000to see which process used 3000port and get the process PID).
您需要使用kill -9 59780with59780替换为找到的 PID 号(用于lsof -wni tcp:3000查看哪个进程使用了3000端口并获取进程 PID)。
Or you can just modify your puma config change the tcp port tcp://127.0.0.1:3000from 3000to 9292or other port that not been used.
或者您可以修改您的 puma 配置,将 tcp 端口tcp://127.0.0.1:3000从更改3000为9292或其他未使用的端口。
Or you can start your rails app by using:
或者您可以使用以下命令启动您的 rails 应用程序:
bundle exec puma -C config/puma.rb -b tcp://127.0.0.1:3001
回答by Sawo Cliff
To kill the puma process first run
首先运行杀死puma进程
lsof -wni tcp:3000
to show what is using port 3000. Then use the PID that comes with the result to run the kill process.
显示正在使用端口 3000 的内容。然后使用结果附带的 PID 运行终止进程。
For example after running lsof -wni tcp:3000 you might get something like
例如,在运行 lsof -wni tcp:3000 之后,您可能会得到类似
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 3366 dummy 8u IPv4 16901 0t0 TCP 127.0.0.1:3000 (LISTEN)
Now run the following to kill the process. (where 3366 is the PID)
现在运行以下命令来终止进程。(其中 3366 是 PID)
kill -9 3366
Should resolve the issue
应该解决问题
回答by ana
you can also try this trick:
你也可以试试这个技巧:
ps aux | grep puma
sample output:
示例输出:
myname 77921 0.0 0.0 2433828 1972 s000 R+ 11:17AM 0:00.00 grep puma
myname 67661 0.0 2.3 2680504 191204 s002 S+ 11:00AM 0:18.38 puma 3.11.2 (tcp://localhost:3000) [my_proj]
then:
然后:
kill 67661
回答by Flavio Wuensche
Found the script below in this github issue. Works great for me.
在这个github 问题中找到了下面的脚本。对我很有用。
#!/usr/bin/env ruby
port = ARGV.first || 3000
system("sudo echo kill-server-on #{port}")
pid = `sudo lsof -iTCP -sTCP:LISTEN -n -P | grep #{port} | awk '{ print }' | head -n 1`.strip
puts "PID: #{pid}"
`kill -9 #{pid}` unless pid.empty?
You can either run it in irb or inside a ruby file.
您可以在 irb 或 ruby 文件中运行它。
For the latter, create server_killer.rbthen run it with ruby server_killer.rb
对于后者,创建server_killer.rb然后运行它ruby server_killer.rb
回答by Nsoseka
If the above solutions don't work on ubuntu/linux then you can try this
如果上述解决方案在 ubuntu/linux 上不起作用,那么你可以试试这个
sudo fuser -k -n tcp port
Run it several times to kill processes on your port of choosing. port could be 3000 for example. You would have killed all the processes if you see no output after running the command
运行几次以杀死您选择的端口上的进程。例如,端口可以是 3000。如果在运行命令后看不到任何输出,您将杀死所有进程
回答by Ali
You can find and kill the running processes: ps aux | grep pumaThen you can kill it with kill PID
你可以找到并杀死正在运行的进程:ps aux | grep puma然后你可以用kill PID

