无法启动mongod.service:找不到单元mongod.service


41

无论出于什么原因,每当我尝试将MongoDB作为服务启动(sudo服务mongod启动)时,都会出现以下错误:

无法启动mongod.service:找不到单元mongod.service。我遵循安装步骤提及以下链接 mongo db安装 失败

system> sudo systemctl start mongodb
Failed to start mongodb.service: Unknown unit: mongodb.service

当我尝试sudo mongod

MongoDB shell version: 3.2.13 connecting to: - 
2017-06-03T16:19:28.513+0530 W NETWORK [thread1] 
Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused 
2017-06-03T16:19:28.514+0530 E QUERY [thread1] 
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:229:14 @(connect):1:6 exception: connect failed

当我尝试mongod --repair

2017-06-03T16:32:35.514+0530 I CONTROL [initandlisten] 
MongoDB starting : pid=17423 port=27017 dbpath=/data/db 64-bit host=sid-Ideapad-Z570 2017-06-03T16:32:35.514+0530 I 
CONTROL [initandlisten] db version v3.2.13 [listen] target_arch: x86_64 2017-06-03T16:32:35.514+0530 I 
CONTROL [initandlisten] options: {} 2017-06-03T16:32:35.540+0530 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating

该命令的输出是什么:ls /etc/systemd/system | grep mongo输出?
Ali Razmdideh

输出是mongodb.service
Siddharth Jain

你有这个文件吗?/usr/bin/mongod; 如果您有该命令的输出内容sudo mongod
Ali Razmdideh

MongoDB shell version: 3.2.13 connecting to: - 2017-06-03T16:19:28.513+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused 2017-06-03T16:19:28.514+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:229:14 @(connect):1:6 exception: connect failed
Siddharth Jain

1
mongod --repair然后尝试sudo mongod; 这可能会有所帮助
Ali Razmdideh

Answers:


64

我重新安装了mongod-org,因为我的数据仍将保持安全。

问题是我运行时我的系统找不到mongod.service sudo service mongod status

运行此命令可以修复它并恢复服务:

sudo systemctl enable mongod

然后,我要做的就是将正确的配置复制到/etc/mongod.conf并运行

sudo service mongod restart

9
我试图启用mongod,但这表明Failed to execute operation: No such file or directory
Mostafiz Rahman

刚指出,这一工程时已经安装了MongoDB的回购MongoDB的社区版
yeeking

试试:sudo service mongodb status
Xonshiz

16

这对我有用。

  1. 从系统中完全卸载mongo:

    sudo service mongod stop 
    sudo apt-get purge mongodb-org* 
    sudo rm -r /var/log/mongodb 
    sudo rm -r /var/lib/mongodb
    
  2. 现在,使用以下命令重新安装mongodb:

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
    echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
    sudo apt-get update
    sudo apt-get install -y mongodb-org
    

    要安装特定发行版,您必须分别指定每个组件包以及版本号,如以下示例所示:

    sudo apt-get install -y mongodb-org=3.6.0 mongodb-org-server=3.6.0 mongodb-org-shell=3.6.0 mongodb-org-mongos=3.6.0 mongodb-org-tools=3.6.0
    
  3. 现在您可以看到mongod正常运行,但同样的问题困扰着您。问题是您的系统在运行时找不到mongod.service sudo service mongod status

    运行此命令可以修复它并恢复服务:

    sudo systemctl enable mongod
    
  4. 现在,您都可以使用mongo。

    sudo service mongod restart
    

我已经完成了您的指南,但出现以下错误:Failed to enable unit: Unit file mongod.service does not exist.@Akash Jain
Alper

在此之后,我取得了成功,但是在步骤3中我做到了,sudo systemctl enable mongodb而在步骤4中我做到了sudo systemctl start mongodb。请注意bmongodb中的意外内容,而不仅仅是mongod。
ArtHare

3

即使我使用官方安装教程(https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/)安装了Mongodb,我也遇到了OP提到的确切问题,

注意:在本教程的第2步(为Mongodb创建一个列表文件)中,重要的是单击计算机上特定于特定版本的Ubuntu的选项卡。默认情况下,它显示Ubuntu 14.04,它创建了OP提到的问题(无法启动mongod.service:未找到Unit mongod.service)

当我最终注意到在步骤2中,我必须正确选择Ubuntu 16.04(对我而言)时,安装成功,并且在此mongod运行之后没有任何问题。


谢谢,我也没有注意到版本标签!按照docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/中的说明进行卸载,然后使用合适的版本再次安装。
皮特·蒙哥马利
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.