天天看點

mongodb安裝後無法啟動問題記錄

mongodb安裝後無法啟動問題記錄

剛接觸mongodb,安裝後一直無法啟動

[[email protected] data]# systemctl start mongod
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
           

然後檢視systemctl status mongod.service和journalctl -xe檢視資訊,感覺有用的資訊就是下面這句

從網上查了大量資料,大部分都說資料庫鎖住啦,但我這是第一次啟動,怎麼會鎖住了?而且也沒有lock檔案。偶然發現有一篇記錄mysql啟動錯誤的部落格,部落客檢視上面兩個資訊無果後又去檢視mysql的服務日志,最終找到了原因,瞬間感覺有了出路,于是找到mongodb的日志檔案,打開檢視:

--T16::+ I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0", port:  }, processManagement: { fork: true, pidFilePa
th: "/var/run/mongodb/mongod.pid", timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/mnt/mongodb/data/mongo", journal: { enabled: true } }, systemLog: { destination: "f
ile", logAppend: true, path: "/mnt/mongodb/log/mongod.log" } }
--T16::+ I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /mnt/mongodb/data/mongo not found., terminating
--T16::+ I CONTROL  [initandlisten] now exiting
--T16::+ I CONTROL  [initandlisten] shutting down with code:
           

很明顯,我改了配置檔案中資料庫内容的目錄,但是并沒有建立。建立好目錄,再給個讀權限,重新啟動,果然成功啦!

總結:不要過度依賴systemctl status mongod.service和journalctl -xe,有時候這裡面得内容反而會把我們帶偏了。