问题描述
我遵循mongodb安装documents.中提到的所有步骤
对于Ubuntu 16.04
步骤1:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
步骤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
步骤3:
sudo apt-get update
步骤4:
sudo apt-get install -y mongodb-org
步骤5:
sudo service mongod start
当我启动mongodb时出现错误
"Failed to start mongod.service: Unit mongod.service not found." please help me to solve this.
最佳解决方法
很可能单位mongodb.service被屏蔽了。使用以下命令取消屏蔽它。
sudo systemctl unmask mongodb
和re-run
sudo service mongod start
次佳解决方法
请按照以下步骤操作。
1-完全卸载当前安装
sudo service mongod stop
删除包裹
sudo apt-get purge mongodb-org*
删除文件夹
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
2-如官方网站所述重新安装,我将写下所有步骤。 enter link description here
导入公钥
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
为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
更新清单
sudo apt-get update
安装最新的软件包
sudo apt-get install -y mongodb-org
3-现在应该可以了,请尝试以下命令
sudo service mongod start
并检查状态
mongo
它应该出现mongo shell
第三种解决方法
无法启动mongod.service:找不到单元mongod.service
如果您遵循的是官方文档,并且遇到上述错误,则意味着您的计算机上尚未启用mongod.service(我说的是Ubuntu 16.04)。您需要使用以下命令来执行此操作
sudo systemctl enable mongod.service
现在您可以使用以下命令启动mongodb
sudo service mongod start
第四种方法
我想您缺少’b’吗?
sudo service mongod start
应该
sudo service mongodb start
我认为是这样吗?
第五种方法
只需尝试使用以下命令:
$ sudo systemctl enable mongod
第六种方法
[解]
只需输入
sudo mongod
它会工作。
第七种方法
$service mongodb start
$service mongodb status
当我开始使用上述命令时,状态为活动
第八种方法
我很长一段时间都遇到了同样的错误,尝试在Google上进行几乎所有的安装,但都找不到答案…
我按照https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/的说明进行操作,但始终收到错误信息无法启动mongod.service:未找到单元mongod.service
我首先使用以下命令进行安装:sudo apt-get install -y mongodb-org然后注意到我在运行:
$ sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
mongodb-org-mongos mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed
mongodb-org mongodb-org-mongos mongodb-org-shell mongodb-org-tools
0 to upgrade, 4 to newly install, 0 to remove and 46 not to upgrade.
Need to get 0 B/40.1 MB of archives.
After this operation, 178 MB of additional disk space will be used.
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 379307 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_4.0.3_amd64.deb ...
Unpacking mongodb-org-shell (4.0.3) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_4.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (4.0.3) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_4.0.3_amd64.deb ...
Unpacking mongodb-org-tools (4.0.3) ...
Preparing to unpack .../mongodb-org_4.0.3_amd64.deb ...
Unpacking mongodb-org (4.0.3) ...
Setting up mongodb-org-shell (4.0.3) ...
Setting up mongodb-org-mongos (4.0.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up mongodb-org-tools (4.0.3) ...
Setting up mongodb-org (4.0.3) ...
$ mongod --version
db version v2.6.12
2018-10-26T12:03:12.362+0200 git version: d73c92b1c85703828b55c2916a5dd4ad46535f6a
数据库版本是2.6.12,而不是最新的4.0.3。因此,请确保您尚未安装mongodb-org-server,如果是,则请确保将其更新为目标版本(如@ https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/所示->步骤4-安装特定版本的MongoDB。)
target_version = 4.0.3
sudo apt-get install -y mongodb-org = target_version mongodb-org-server = target_version mongodb-org-shell = target_version mongodb-org-mongos = target_version mongodb-org-tools = target_version
$ sudo apt-get install -y mongodb-org=4.0.3 mongodb-org-server=4.0.3 mongodb-org-shell=4.0.3 mongodb-org-mongos=4.0.3 mongodb-org-tools=4.0.3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed
mongodb-org mongodb-org-mongos mongodb-org-shell mongodb-org-tools
The following packages will be upgraded:
mongodb-org-server
1 to upgrade, 4 to newly install, 0 to remove and 45 not to upgrade.
Need to get 15.7 MB/55.8 MB of archives.
After this operation, 217 MB of additional disk space will be used.
Get:1 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0/multiverse amd64 mongodb-org-server amd64 4.0.3 [15.7 MB]
Fetched 15.7 MB in 2s (6,289 kB/s)
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 379306 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_4.0.3_amd64.deb ...
Unpacking mongodb-org-shell (4.0.3) ...
**Preparing to unpack .../mongodb-org-server_4.0.3_amd64.deb ...
Failed to stop mongod.service: Unit mongod.service not loaded.
invoke-rc.d: initscript mongod, action "stop" failed.
dpkg: warning: old mongodb-org-server package pre-removal script subprocess returned error exit status 5
dpkg: trying script from the new package instead ...
dpkg: ... it looks like that went OK
Unpacking mongodb-org-server (4.0.3) over (2.6.12) ...**
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_4.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (4.0.3) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_4.0.3_amd64.deb ...
Unpacking mongodb-org-tools (4.0.3) ...
Preparing to unpack .../mongodb-org_4.0.3_amd64.deb ...
Unpacking mongodb-org (4.0.3) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up mongodb-org-shell (4.0.3) ...
Setting up mongodb-org-mongos (4.0.3) ...
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up mongodb-org-tools (4.0.3) ...
Setting up mongodb-org-server (4.0.3) ...
Installing new version of config file /etc/mongod.conf ...
Setting up mongodb-org (4.0.3) ...
然后,这一切对我有用:D
第九种方法
可能是您使用了错误版本的mongodb列表文件。我遇到了这个问题,但是当没有为Ubuntu 16.04选择正确的列表文件时,这是我的错误。默认选择为Ubuntu 14.04,这是我的错误的原因:“无法启动mongod.service:未找到Unit mongod.service。”
第十种方法
对于Ubuntu 16.04.5,注意到在我安装了多台服务器之后,MongoDB安装并不会在安装后自动启用mongod.service文件,因此我们需要如下启用它:
下面的问题检查mongod是否已启用
systemctl list-unit-files --type=service
如果显示为”disabled”,则需要启用它。
sudo systemctl enable mongod.service
如果我们想查看mongod.service文件是否存在以防丢失,请签入
ls /lib/systemd/system
您会看到一个文件
/lib/systemd/system/mongod.service