mongodb 启动 mongod.service 失败:未找到单元 mongod.service
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48092353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to start mongod.service: Unit mongod.service not found
提问by Rahul
I follow all the steps mention in MongoDB installation documentsfor Ubuntu 16.04
.
我按照所有的步骤提MongoDB的安装文件进行Ubuntu 16.04
。
Steps 1:
步骤 1:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
Steps 2:
步骤 2:
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
Steps 3:
第 3 步:
sudo apt-get update
Steps 4:
第 4 步:
sudo apt-get install -y mongodb-org
Steps 5:
步骤 5:
sudo service mongod start
when I started MongoDB got an error as:
当我启动 MongoDB 时出现错误:
Failed to start mongod.service: Unit mongod.service not found.
启动 mongod.service 失败:未找到单元 mongod.service。
回答by Jehanzeb.Malik
Most probably unit mongodb.service is masked. Use following command to unmask it.
很可能单元 mongodb.service 被屏蔽了。使用以下命令取消屏蔽。
sudo systemctl unmask mongod
sudo systemctl unmask mongod
and re-run
并重新运行
sudo service mongod start
sudo service mongod start
回答by unclexo
Failed to start mongod.service: Unit mongod.service not found
启动 mongod.service 失败:未找到单元 mongod.service
If you are following the official doc and are coming across with the error above that means mongod.serviceis not enabled yet on you machine (I am talking about Ubuntu 16.04). You need to do that using following command
如果您正在关注官方文档并遇到上述错误,则意味着您的机器上尚未启用mongod.service(我说的是 Ubuntu 16.04)。您需要使用以下命令执行此操作
sudo systemctl enable mongod.service
Now you can start mongodbusing the following command
现在您可以使用以下命令启动mongodb
sudo service mongod start
回答by CodeGench
Please follow the below steps, it should work.
请按照以下步骤操作,它应该可以工作。
1 - Uninstall current installation completely
1 - 完全卸载当前安装
Source - official instructions
来源 -官方说明
sudo service mongod stop
Remove Packages
删除包
sudo apt-get purge mongodb-org*
Remove the folders
删除文件夹
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
2 - Reinstall as described on official site, I will just write down the all steps. enter link description here
2 - 按照官方网站上的描述重新安装,我会写下所有步骤。在此处输入链接描述
Import the public key
导入公钥
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
Create a list file for Ubuntu 16.04
为 Ubuntu 16.04 创建一个列表文件
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
update the list
更新列表
sudo apt-get update
Install the latest package
安装最新的包
sudo apt-get install -y mongodb-org
3 - Now it should work, please try below command
3 - 现在它应该可以工作了,请尝试以下命令
sudo service mongod start
and check the status
并检查状态
mongo
it should appear the mongo shell
它应该出现 mongo shell
回答by Nardwacht
You are missing a 'b' I think?
我想你缺少一个'b'吗?
sudo service mongod start
should be
应该
sudo service mongodb start
I think this is the case?
我想是这样吗?
回答by Jobin Mathew
[Solution]
[解决方案]
Just type
只需输入
sudo mongod
It will work.
它会起作用。
回答by Nikhil Sharma
Just try with this command:
试试这个命令:
$ sudo systemctl enable mongod
回答by Divya Kamal Maddi
$service mongodb start
$service mongodb status
the status is active when I started using above command
当我开始使用上述命令时,状态处于活动状态
回答by Charles Sok
For Ubuntu 16.04.5, it is noticed that MongoDB installations does not auto enable the mongod.service file after installation in my case after I have installed on several servers, so we need to enable it like below:
对于 Ubuntu 16.04.5,注意到在我安装在多台服务器上之后,MongoDB 安装不会在安装后自动启用 mongod.service 文件,因此我们需要像下面这样启用它:
Issue below to check whether mongod is enabled
发出以下问题以检查是否启用了 mongod
systemctl list-unit-files --type=service
If it shows as "disabled", then you need to enable it.
如果它显示为“已禁用”,那么您需要启用它。
sudo systemctl enable mongod.service
If we want to see whether mongod.service file exists in case this file is missing, check in
如果我们想查看 mongod.service 文件是否存在,以防此文件丢失,请检查
ls /lib/systemd/system
You will see a file
你会看到一个文件
/lib/systemd/system/mongod.service
回答by mahyard
In some cases for some security reasons the unit would be marked as masked. This state is much stronger than being disabled in which you cannot even start the service manually.
在某些情况下,出于某些安全原因,该单元会被标记为已屏蔽。这种状态比被禁用要强得多,在禁用状态下您甚至无法手动启动服务。
to check this, run the following command:
要检查这一点,请运行以下命令:
systemctl list-unit-files | grep mongod
if you find out something like this:
如果你发现这样的事情:
mongod.service masked
then you can unmask the unit by:
然后您可以通过以下方式取消屏蔽该单元:
sudo systemctl unmask mongod
then you may want to start the service:
那么你可能想要启动服务:
sudo systemctl start mongod
and to enable auto-start during system boot:
并在系统启动期间启用自动启动:
sudo systemctl enable mongod
However if mongodb did not start again or was not masked at all, you have the option to reinstall it this way:
但是,如果 mongodb 没有再次启动或根本没有被屏蔽,您可以选择以这种方式重新安装它:
sudo apt-get --purge mongo*
sudo apt-get install mongodb-org
thanks to @jehanzeb-malik
感谢@jehanzeb-malik
回答by Adi Jag
The following steps helped me solve the problem of not being able to start mongodb on Ubuntu Server 18.04 LTS
以下步骤帮我解决了在Ubuntu Server 18.04 LTS上无法启动mongodb的问题
Step 1: First, remove MongoDB from previous if installed:
第 1 步:首先,如果安装了 MongoDB,则从之前删除它:
sudo apt remove --autoremove mongodb-org
sudo apt remove --autoremove mongodb-org
Step 2: Remove any mongodb repo list files:
第 2 步:删除所有 mongodb 存储库列表文件:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
Step 3: Import the public key used by the package management system:
第三步:导入包管理系统使用的公钥:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Step 4: Create a list file for MongoDB:
第 4 步:为 MongoDB 创建一个列表文件:
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Step 5: Reload local package database:
第 5 步:重新加载本地包数据库:
sudo apt-get update
Step 6: Install the MongoDB packages:
第 6 步:安装 MongoDB 软件包:
sudo apt-get install -y mongodb-org
Step 7: Start MongoDB:
第 7 步:启动 MongoDB:
sudo service mongod start
Step 8: Begin using MongoDB:
第 8 步:开始使用 MongoDB:
mongo
Hope it helps you.
希望对你有帮助。