over 1 year ago

运行rails s失败
报错信息提示端口被占用

liu@liudeMBP ⮀ ~/job-listing-4 ⮀ ⭠ master± ⮀ rails s
=> Booting Puma
=> Rails 5.0.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.5.2 (ruby 2.3.1-p112), codename: Amateur Raccoon Rocketry
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Exiting
/Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:268:in `initialize': Address already in use - bind(2) for "::1" port 3000 (Errno::EADDRINUSE)
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:268:in `new'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:268:in `add_tcp_listener'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:262:in `block in add_tcp_listener'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:261:in `each'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:261:in `add_tcp_listener'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:102:in `block in parse'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:85:in `each'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/binder.rb:85:in `parse'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/runner.rb:129:in `load_and_bind'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/single.rb:84:in `run'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/launcher.rb:172:in `run'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/rack/handler/puma.rb:51:in `run'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:296:in `start'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/server.rb:79:in `start'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:90:in `block in server'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `tap'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `server'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/liu/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'
    from /Users/liu/job-listing-4/bin/rails:9:in `require'

解决方法一:
运行命令kill -9 $(lsof -i tcp:3000 -t)
解决方法二:
运行命令
lsof -wni tcp:3000
会然后

liu@liudeMBP ⮀ ~/job-listing-4 ⮀ ⭠ master± ⮀ lsof -wni tcp:3000
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    63770  liu   31u  IPv6 0x65581cea89ae3cb7      0t0  TCP [::1]:hbci (LISTEN)
ruby    63770  liu   32u  IPv4 0x65581ceaaaf58807      0t0  TCP 127.0.0.1:hbci (LISTEN)

然后运行命令kill -9 PID号
杀掉进程

 liu@liudeMBP ⮀ ~/job-listing-4 ⮀ ⭠ master± ⮀ lsof -i tcp:3000
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ruby    64049  liu   31u  IPv6 0x65581cea89ae3cb7      0t0  TCP localhost:hbci (LISTEN)
ruby    64049  liu   32u  IPv4 0x65581ceaaafe6807      0t0  TCP localhost:hbci (LISTEN)
 liu@liudeMBP ⮀ ~/job-listing-4 ⮀ ⭠ master± ⮀ kill -9 64049
← 1/14 日记 database.yml问题 →
 
comments powered by Disqus