这篇文章主要介绍解决mongodb端口占用的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

启动mongod:

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

错误提示:

SatAug1709:02:02[initandlisten]ERROR:listen():bind()failederrno:98Addressalreadyinuseforsocket:0.0.0.0:27017SatAug1709:02:02[initandlisten]ERROR:addralreadyinuse

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

解决办法:

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

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

ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programnametcp00127.0.0.1:280170.0.0.0:*LISTEN953/mongodtcp00127.0.0.1:530.0.0.0:*LISTEN1546/dnsmasqtcp00127.0.0.1:6310.0.0.0:*LISTEN653/cupsdtcp00127.0.0.1:270170.0.0.0:*LISTEN953/mongodtcp10192.168.5.124:5687491.189.89.144:80CLOSE_WAIT1913/ubuntu-geoip-ptcp01192.168.5.124:45890220.181.111.24:80FIN_WAIT1-tcp00192.168.5.124:44867219.148.35.218:80ESTABLISHED2219/firefox

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

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

ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programnametcp00127.0.0.1:530.0.0.0:*LISTEN1546/dnsmasqtcp00127.0.0.1:6310.0.0.0:*LISTEN653/cupsdtcp00192.168.5.124:6080561.172.207.130:80TIME_WAIT-tcp10192.168.5.124:5687491.189.89.144:80CLOSE_WAIT1913/ubuntu-geoip-ptcp00192.168.5.124:54370117.79.157.237:80TIME_WAIT-

OK,已经成功杀掉进程。

root@wangyuyu-Vostro-1440:/usr/bin#./mongodSatAug1709:32:25[initandlisten]waitingforconnectionsonport27017SatAug1709:32:25[websvr]adminwebconsolewaitingforconnectionsonport28017

问题解决。

以上是解决mongodb端口占用的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!