无法启动 Rails localhost -(端口 3000 上没有进程 运行)

Can't start Rails localhost - (no processes running on port 3000)

试图启动我的 rails 服务器,但出现错误

=> Booting Puma
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options
[25156] Puma starting in cluster mode...
[25156] * Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
[25156] * Min threads: 5, max threads: 5
[25156] * Environment: development
[25156] * Process workers: 2
[25156] * Preloading application
[25156] * Listening on tcp://0.0.0.0:3000
Exiting
/home/ahmed/.rvm/gems/ruby-2.4.1/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 /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `new'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `add_tcp_listener'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:105:in `block in parse'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:88:in `each'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:88:in `parse'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/runner.rb:144:in `load_and_bind'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/cluster.rb:391:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/launcher.rb:174:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/rack/handler/puma.rb:69:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/server.rb:297:in `start'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:44:in `start'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
    from /home/ahmed/Rails/sample_app/bin/rails:9:in `require'
    from /home/ahmed/Rails/sample_app/bin/rails:9:in `<top (required)>'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
    from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
    from /home/ahmed/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /home/ahmed/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
    from /home/ahmed/Rails/sample_app/bin/spring:15:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

我认为端口 3000 上有一些进程或其他东西 运行ning,所以我尝试使用

找到它
lsof -wni tcp:3000

但是命令returns什么都没有,所以看起来很奇怪,有什么解决办法吗?

更新#1

我 运行 这个代码来自另一个关于 Whosebug 的问题,我得到了

➜  ~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
ruby      1595        beef-xss   17u  IPv4  32839      0t0  TCP *:3000 (LISTEN)

所以我尝试了

kill -9 1595

kill -9 32839

但没有任何效果

我也重新启动了我的电脑,但同样的问题仍然存在,我的 "tmp/pids" 文件夹中没有文件

更新#2

使用

卸载了一个叫做 beef-xss 的东西后解决了这个问题
sudo apt-get --purge remove beef-xss

您是否尝试删除 tmp/pids 中的 pid 文件? 如果文件夹中有任何东西,请尝试使用 pgrep -lf puma 找到 Puma 进程,然后查看是否有任何进程。

我认为您在同一端口上有 运行 另一台服务器,不幸的是您没有停止此操作并且命令提示符已关闭,这就是它显示此错误的原因。所以你可以解决这个问题,如果你 restart 你的电脑。

只需重新启动计算机,然后重试。

此外,您可以尝试从 tmp/pids/

中删除文件

如果您使用的是 Linux 操作系统

首先我们将使用 fuser 命令来识别哪些进程正在使用文件或套接字。

fuser -n tcp 3000
3000 / tcp: 7425

当我们想要识别正在使用 TCP 或 UDP 套接字的进程时使用 -n 参数,在我的例子中我想知道谁在使用端口 3000。

命令 returns 进程的 pid,有了这些数据和 ps 命令的帮助,我们将获得有关它的更多信息。

ps x | grep 7425
7425 pts / 3 Tl 1:15 /home/carlos/.rvm/rubies/ruby-1.9.3-p0/bin/ruby 
script / rails s

我们看到 rails 测试服务器的一个实例被挂起,以释放端口,我们使用已有的 pid 终止了进程。

kill -9 7425

然后我们看到这个过程确实已经完成了。

ps x | grep 7425
7973 pts / 3 S + 0:00 grep --color = auto 7425
[1] + Finished (killed) rails s

希望对你有用

答案的文章http://community.logicalbricks.com/node/103

我 运行 这个代码来自另一个关于 Whosebug 的问题,我得到了

➜  ~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
ruby      1595        beef-xss   17u  IPv4  32839      0t0  TCP *:3000 (LISTEN)

所以我试过了

kill -9 1595

kill -9 32839

但没有任何效果

我也重新启动了我的电脑,但同样的问题仍然存在,我的 "tmp/pids" 文件夹中没有文件

更新 #2

使用

卸载名为 beef-xss 的东西后解决了这个问题
sudo apt-get --purge remove beef-xss