升级到 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

[服务] 用户=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf

[安装] WantedBy=multi-user.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 - 如果你尝试启动它仍然会失败(查看启动命令,它使用numactl, 所以:

# 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 的这个范围内,可能还有一些 Trusty 系统使用 MongoDB 成为 Xenial。抱歉加了点料,我还在改进。祝大家一切顺利!

相关内容