ITPub博客

首页 > IT职业 > IT生活 > mongodb端口占用怎么解决

mongodb端口占用怎么解决

IT生活 作者:lcc 时间:2021-09-11 10:25:16 0 删除 编辑

启动mongod:

root@wangyuyu-Vostro-1440:/usr/bin# ./mongod

错误提示:

Sat Aug 17 09:02:02 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 
0.0.0.0:27017
Sat Aug 17 09:02:02 [initandlisten] ERROR: addr already in use

原因是启动mongod时端口被占用。

解决办法:

使用命令:root@wangyuyu-Vostro-1440:/usr/bin# netstat -anp|more

可以看到客户端还保持着与服务器的连接。

Proto Recv-Q Send-Q       Local Address         Foreign Address          State       
PID/Program name
tcp        0      0 127.0.0.1:28017         0.0.0.0:*            LISTEN      
953/mongod      
tcp        0      0 127.0.0.1:53           0.0.0.0:*            LISTEN      
1546/dnsmasq    
tcp        0      0 127.0.0.1:631           0.0.0.0:*             LISTEN      
653/cupsd       
tcp        0      0 127.0.0.1:27017         0.0.0.0:*            LISTEN      
953/mongod      
tcp        1      0 192.168.5.124:56874     91.189.89.144:80        CLOSE_WAIT  
1913/ubuntu-geoip-p
tcp        0      1 192.168.5.124:45890     220.181.111.24:80       FIN_WAIT1   
-               
tcp        0      0 192.168.5.124:44867     219.148.35.218:80       ESTABLISHED
2219/firefox

杀死953进程:root@wangyuyu-Vostro-1440:/usr/bin# kill -9 953

再次查看服务器连接状态:

Proto Recv-Q Send-Q      Local Address        Foreign Address              State       
PID/Program name
tcp        0      0 127.0.0.1:53          0.0.0.0:*                LISTEN      
1546/dnsmasq    
tcp        0      0 127.0.0.1:631         0.0.0.0:*               LISTEN      
653/cupsd       
tcp        0      0 192.168.5.124:60805     61.172.207.130:80       TIME_WAIT   
-               
tcp        1      0 192.168.5.124:56874     91.189.89.144:80        CLOSE_WAIT  
1913/ubuntu-geoip-p
tcp        0      0 192.168.5.124:54370     117.79.157.237:80       TIME_WAIT   
-

OK,已经成功杀掉进程。

root@wangyuyu-Vostro-1440:/usr/bin# ./mongod
Sat Aug 17 09:32:25 [initandlisten] waiting for connections on port 27017
Sat Aug 17 09:32:25 [websvr] admin web console waiting for connections on port 28017

问题解决。

python学习网,大量的免费MongoDB入门教程,欢迎在线学习!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2331/viewspace-2835142/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-06

  • 博文量
    119
  • 访问量
    12366