Mongo服务启动或重启始终失败

时间:2017-04-24 13:22:21

标签: linux mongodb ubuntu ubuntu-16.04

我已经安装了mongodb,然后我创建了一个mongo服务:

 [Unit]
    Description=High-performance, schema-free document-oriented database
    After=network.target

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

    [Install]
    WantedBy=multi-user.target

但是当我启动服务然后检查状态时,我总是得到这个错误:

● mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-04-24 13:08:55 UTC; 6min ago
  Process: 1094 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=48)
 Main PID: 1094 (code=exited, status=48)

Apr 24 13:08:54 ip-172-31-37-163 systemd[1]: Started High-performance, schema-free document-oriented database.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Main process exited, code=exited, status=48/n/a
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Unit entered failed state.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Failed with result 'exit-code'.

5 个答案:

答案 0 :(得分:8)

问题出在配置文件和更改

  

bindIp:127.0.0.1,X.X.X.X

  

bindIp:[127.0.0.1,X.X.X.X]

解决了我的问题

答案 1 :(得分:3)

尝试更改所有者权限

chown -R mongodb:mongodb / var / lib / mongodb

小丑mongodb:mongodb /tmp/mongodb-27017.sock

答案 2 :(得分:2)

在MongoDB 3.6中,@ Chlebta提出的括号对我不起作用,返回错误:

  

mongod.service:退出主流程,代码=退出,状态= 2 / INVALIDARGUMENT

我的错误是用逗号和空格分隔IP地址。地址之间只能有逗号:

bindIp: 127.0.0.1,X.X.X.X,Y.Y.Y.Y

答案 3 :(得分:0)

Ubuntu 20.04和MongoDB服务器版本4.4.2的更新...

对我来说,最终的问题是我试图使用计算机的 public IP地址。

一旦指定了我的 私有 IP地址,一切便开始正常工作。 mongod服务启动时没有任何错误,现在我可以从远程计算机连接到它。

在Ubuntu上,您可以使用以下命令来获取您的私有IP地址:

hostname -I | awk '{print $1}'

这是 /etc/mongod.conf 中的内容(仅显示相关部分和部分私有IP地址):

net:
  port: 27017
  bindIp: 127.0.0.1, 172.##.##.##

security:
  authorization: enabled

请注意,将两个IP地址放在方括号内(如已接受的答案一样)对我不起作用,并且导致mongod状态码为2(实际上是 mongod.conf 中的语法错误) >文件)。同样,尽管不需要,逗号后的空格现在似乎也可以使用。

答案 4 :(得分:-1)

我只是重启系统(sudo reboot)它对我有用。我不知道为什么。

相关问题