1. ホーム
  2. MongoDB

MongoDB起動時の例外エラーと正しいシャットダウン方法

2022-02-14 10:51:39
<パス

エラー1を報告する。

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


回避策

1. 診断データを削除してください。

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ファイルを削除してください。(ロックファイルのパスは様々です)

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番号を探し、電源を切ってからstartコマンドを再入力してください。

sudo netstat -anp|more
Activate Internet connections (server and established connections)
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 を停止する

方法1:プロセスを表示してkillコマンドを使用する。kill -9は使用できない

方法2:クライアントに入り、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& quot; }, 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


1. mongodbを新規にインストールし、sudo service mongod start (sudo service mongod restart)を実行すると、両方とも起動に失敗すると報告します。

View /var/log/mongodb/mongod.log.

2015-07-27T11:49:10.476+0800 I CONTROL ***** SERVER RESTARTED *****
2015-07-27T11:49:10.548+0800 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 192.168.1.235:27017
2015-07-27T11:49:10.548+0800 E NETWORK [initandlisten] addr already in use
2015-07-27T11:49:10.549+0800 W - [initandlisten] Detected unclean shutdown - /var/lib/mongo/mongod.lock is not empty.
2015-07-27T11:49:10.582+0800 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to lock file: /var/lib/mongo/mongod.lock errno:11 Resource temporarily unavailable. is a mongod instance already running?, terminating
2015-07-27T11:49:10.582+0800 I CONTROL [initandlisten] dbexit: rc: 100
2015-07-27T11:56:46.954+0800 I CONTROL ***** SERVER RESTARTED *****
2015-07-27T11:56:47.017+0800 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 192.168.1.235:27017
2015-07-27T11:56:47.017+0800 E NETWORK [initandlisten] addr already in use
2015-07-27T11:56:47.018+0800 W - [initandlisten] Detected unclean shutdown - /var/lib/mongo/mongod.lock is not empty.
2015-07-27T11:56:47.018+0800 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to lock file: /var/lib/mongo/mongod.lock errno:11 Resource temporarily unavailable. is a mongod instance already running?, terminating
2015-07-27T11:56:47.018+0800 I CONTROL [initandlisten] dbexit: rc: 100



解決手順

  1. Delete the log file /var/log/mongodb/mongod.log


rm /var/log/mongodb/mongod.log

  2. Delete the lock file


rm /var/log/mongodb/mongod.log

  3. Execute the repair


sudo /usr/bin/mongod -repair -dbpath /var/lib/mongodb / -repairpath /tmp/mongodb

4-最終手段:サーバー側を再起動する

reboot