MongoDB启动异常 报错 及 正确的关闭方法

报错1:

[ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost.

解决办法:

1、删除掉diagnostic数据:

rm -f /var/lib/mongo/diagnostic.data/*

2、启动mongodb。

进入MongoDB的bin目录下,

 sudo ./mongod

报错2:

2018-07-20T22:42:08.645+0800 I STORAGE  [initandlisten] exception in initAndListen: DBPathInUse: Unable to lock the lock file:

(Unknown error). Another mongod instance is already running on the /data/db directory, terminating.

2018-07-20T22:42:08.645+0800 I CONTROL  [initandlisten] now exiting
2018-07-20T22:42:08.645+0800 I CONTROL  [initandlisten] shutting down with code:100

解决办法:mongodb非正常关闭 删除mongod.lock文件即可.(lock文件所在路径各有不同)

sudo rm /data/db/mongod.lock

报错3:

2018-07-20T22:29:17.982+0800 I CONTROL  [initandlisten] MongoDB starting : pid=3499 port=27017 dbpath=/data/db 64-bit host=xumovm

......

2018-07-20T21:12:05.974+0800 E STORAGE  [initandlisten] Failed to set up listener: SocketException: Address already in use

解决办法:

找到mongo之前运行的PID号,关掉它,重新输入启动命令

sudo netstat -anp|more
激活Internet连接 (服务器和已建立连接的)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
 PID/Program name    
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN     
 2515/./mongod       

sudo kill 2515

正确的关闭方法:停止Mongodb

方法一:查看进程,使用kill命令;不能使用kill -9

方法二:在在客户端进去,使用shutdown命令

/usr/local/mongodb/bin:$ ./mongod
> use admin; 
switched to db admin 
> db.shutdownServer();
 server should be down...
2018-07-20T23:06:30.230+0800 I NETWORK  [initandlisten] waiting for connections on port 27017
2018-07-20T23:13:37.028+0800 I NETWORK  [listener] connection accepted from 127.0.0.1:56738 #1 (1 connection now open)
2018-07-20T23:13:37.029+0800 I NETWORK  [conn1] received client metadata from 127.0.0.1:56738 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "4.0.0" }, os: { type: "Linux", name: "Ubuntu", architecture: "x86_64", version: "18.04" } }
2018-07-20T23:13:59.951+0800 I COMMAND  [conn1] terminating, shutdown command received { shutdown: 1.0, $db: "admin" }
2018-07-20T23:13:59.951+0800 I NETWORK  [conn1] shutdown: going to close listening sockets...
2018-07-20T23:13:59.951+0800 I NETWORK  [conn1] removing socket file: /tmp/mongodb-27017.sock
2018-07-20T23:13:59.952+0800 I FTDC     [conn1] Shutting down full-time diagnostic data capture
2018-07-20T23:13:59.956+0800 I STORAGE  [conn1] WiredTigerKVEngine shutting down
2018-07-20T23:14:00.049+0800 I STORAGE  [conn1] shutdown: removing fs lock...
2018-07-20T23:14:00.049+0800 I CONTROL  [conn1] now exiting
2018-07-20T23:14:00.049+0800 I CONTROL  [conn1] shutting down with code:0

猜你喜欢

转载自blog.csdn.net/dashen180309/article/details/81138730