最近centos服务器上的MongoDB频繁出问题,导致我的express不能正常访问。
输入mongo显示不能连接
[root@****** ~]# mongo
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
具体原因不清楚,百度一番,最终找到解决办法(原理也不是很清楚)
[root@**** ~]# mongod -f /www/server/mongodb/config.conf --repair
about to fork child process, waiting until server is ready for connections.
forked process: 20447
child process started successfully, parent exiting
[root@iZj6ccn40u760fits4pn99Z ~]# mongod -f /www/server/mongodb/config.conf --fork
about to fork child process, waiting until server is ready for connections.
forked process: 25382
child process started successfully, parent exiting
再次输入mongo就可以正确进入了。
记录一下,以备后续。
因为原因不明,不保证其他人照做也无效。