升級到 Ubuntu 16.04 後 MongoDB 3.0.2 無法啟動

升級到 Ubuntu 16.04 後 MongoDB 3.0.2 無法啟動

我最近升級到 Ubuntu 16.04,之後 MongoDB 3.0.2 無法啟動。

$ sudo service mongod start

這會拋出錯誤:

Failed to start mongod.service: Unit mongod.service failed to load: No such file or directory.

我透過執行看到了這些錯誤日誌systemctl status mongod.service

● mongod.service
   Loaded: loaded (/etc/init.d/mongod; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2016-04-29 10:48:02 IST; 10s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8624 ExecStart=/etc/init.d/mongod start (code=exited, status=1/FAILURE)

mongod[8223]: Rather than invoking init scripts through /etc/init.d, use the service(8)
mongod[8223]: utility, e.g. service mongod start
mongod[8223]: initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection
mongod[8223]: Since the script you are attempting to invoke has been converted to an
mongod[8223]: Upstart job, you may also use the start(8) utility, e.g. start mongod
mongod[8223]: start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection r
systemd[1]: mongod.service: Control process exited, code=exited status=1
systemd[1]: Failed to start mongod.service.
systemd[1]: mongod.service: Unit entered failed state.
systemd[1]: mongod.service: Failed with result 'exit-code'.

我嘗試了下面提到的解決方案,但沒有一個有效:

  1. 建立了一個檔案 /lib/systemd/system/mongodb.service ,內容如下:

[Unit] Description=高效能、無模式的以文件為導向的資料庫 After=network.target

[服務] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf

[安裝] WantedBy=多用戶.target

  1. 嘗試安裝 upstartv sudo apt-get install upstart-sysv

答案1

  • 刪除 upstart-sysv 您可以透過 systemd 單元啟動 mongo。
  • 檢查您的 mongod.config 設定檔。不應該有processManagement.forktrue
  • 檢查您執行腳本的 mongo dbpath 和日誌資料夾mongodb使用者(在服務文件中)應該有權存取這些文件。
  • 如果仍然有問題,請檢查您的 mongod.log 檔案(您在設定檔中指定它),您可以在那裡找到更詳細的錯誤。

答案2

好吧,我做了:

    • 備份:

    # cp -vr /var/lib/mongodb /root/

    # cp /etc/mongod.conf /root

    • 刪除舊的初始化:

    # rm -fr /etc/init.d/mongod

3 - 建立文件/etc/systemd/system/multi-user.target.wants/mongod.service, 喜歡:

# nano /etc/systemd/system/multi-user.target.wants/mongod.service

4 - 我從其他已經是 Xenial 的系統複製了這個腳本:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/env bash -c "numactl --interleave=all /usr/bin/mongod --quiet --config /etc/mongod.conf"
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

5 - 如果您嘗試啟動它仍然失敗(看看啟動命令,它使用數位, 所以:

# apt-get install -y numactl

6 - 重裝服務:

# systemctl daemon-reload

7 - 刪除舊鎖(祈禱你的資料庫正常):

# rm -fr /var/lib/mongodb/mongod.lock

8 - 重新啟動,檢查狀態並高興:

# systemctl restart mongod.service
# systemctl status mongod.service
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/multi-user.target.wants/mongod.service; bad; vendor preset: enabled)
   Active: active (running) since Qui 2018-05-17 21:15:16 -03; 2s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 6301 (mongod)
   CGroup: /system.slice/mongod.service
           └─6301 /usr/bin/mongod --quiet --config /etc/mongod.conf

Mai 17 21:15:16 xx-server systemd[1]: Started High-performance, schema-free document-oriented database.

````

我今天剛遇到這個問題,所以,也許在 LTS 領域仍然有一些使用 MongoDB 的 Trusty 系統是 Xenial。抱歉標記,我仍在改進這一點。祝大家一切順利!

相關內容