sudo service mongodb restart 在 ubuntu 14.0.4 中给出“无法识别的服务错误”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26852138/
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
sudo service mongodb restart gives "unrecognized service error" in ubuntu 14.0.4
提问by dot
I just installed mongoDB on ubuntu 14.0.4. I tried to start the shell but I'm getting a connection refused error.
我刚刚在 ubuntu 14.0.4 上安装了 mongoDB。我试图启动 shell,但出现连接被拒绝的错误。
me@medev:/etc/init.d$ mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-11-10T15:06:28.084-0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-10T15:06:28.085-0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
So I decided to try to restart the service but that's failing too. I get the following error message:
所以我决定尝试重新启动服务,但这也失败了。我收到以下错误消息:
me@medev:/etc/init.d$ sudo service mongodb restart
mongodb: unrecognized service
me@medev:/etc/init.d$
This is what I have in my /var/log/mongodb/mongod.log - http://pastebin.com/MrHt8tce
这就是我在 /var/log/mongodb/mongod.log 中的内容 - http://pastebin.com/MrHt8tce
what i've tried so far:
到目前为止我尝试过的:
I found another post here: can't start mongodb as sudowhich made a comment about remove the mongo lock file.
我在这里找到了另一篇文章:无法将 mongodb 作为 sudo 启动,它发表了关于删除 mongo 锁定文件的评论。
I deleted the lock file and then retried my command but it still fails as you can see below:
我删除了锁定文件,然后重试了我的命令,但它仍然失败,如下所示:
me@medev:/var/lib/mongodb$ sudo rm mongod.lock
me@medev:/var/lib/mongodb$ ls
journal local.0 local.ns _tmp
me@medev:/var/lib/mongodb$ sudo service mongodb start
mongodb: unrecognized service
But I can start it using /etc/init.d as you can see below:
但我可以使用 /etc/init.d 启动它,如下所示:
me@medev:/var/lib/mongodb$ sudo /etc/init.d/mongod start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongod start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongod
mongod start/running, process 27469
me@medev:/var/lib/mongodb$ ls
journal local.0 local.ns mongod.lock
me@medev:/var/lib/mongodb$ mongo
MongoDB shell version: 2.6.5
connecting to: test
> db
test
>
Any ideas on why I can't start it using the service command would be appreciated. From what I've read, i should be using sudo service mongodb
关于为什么我不能使用 service 命令启动它的任何想法将不胜感激。从我读过的内容来看,我应该使用 sudo service mongodb
回答by Parvez Hassan
Try this:
尝试这个:
Write mongodb
instead of mongod
写mongodb
而不是mongod
sudo service mongodb status
回答by Alex M.
I got the same error one day You should use this:
有一天我遇到了同样的错误你应该使用这个:
1.Get the status of your mongo service:
1.获取你的mongo服务的状态:
/etc/init.d/mongod status
or
或者
sudo service mongod status
2.If it's not started repair it like this:
2.如果它没有开始修复它像这样:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
And check again if the service is started again(1)
并再次检查服务是否再次启动(1)
回答by ErichBSchulz
For me the solution was to replace
对我来说,解决方案是更换
service mongod start
with
和
start mongod
回答by cybafelo
You need to make sure the file (ex. /etc/init.d/mongodb) has execute permissions.
您需要确保文件(例如 /etc/init.d/mongodb)具有执行权限。
chmod +x /etc/init.d/mongodb
回答by Will
For debian, from the 10gen repo, between 2.4.x and 2.6.x, they renamed the init script /etc/init.d/mongodb to /etc/init.d/mongod, and the default config file from /etc/mongodb.conf to /etc/mongod.conf, and the PID and lock files from "mongodb" to "mongod" too. This made upgrading a pain, and I don't see it mentioned in their docs anywhere. Anyway, the solution is to remove the old "mongodb" versions:
对于 debian,在 2.4.x 和 2.6.x 之间的 10gen 存储库中,他们将初始化脚本 /etc/init.d/mongodb 重命名为 /etc/init.d/mongod,并将默认配置文件重命名为 /etc/mongodb .conf 到 /etc/mongod.conf,以及从“mongodb”到“mongod”的 PID 和锁定文件。这让升级变得很痛苦,我在他们的文档中没有看到任何地方提到它。无论如何,解决方案是删除旧的“mongodb”版本:
update-rc.d -f mongodb remove
rm /etc/init.d/mongodb
rm /var/run/mongodb.pid
diff -ur /etc/mongodb.conf /etc/mongod.conf
Now, look and see what config changes you need to keep, and put them in mongod.conf.
现在,查看您需要保留哪些配置更改,并将它们放在 mongod.conf 中。
Then:
然后:
rm /etc/mongodb.conf
Now you can:
现在你可以:
service mongod restart
回答by Vladyslav Kolesov
For me nothing helped, but after consulted with expirienced devops mate I've ended with solution
对我来说没有任何帮助,但在与有经验的开发伙伴协商后,我以解决方案结束
create /lib/systemd/system/mongod.service
file with content
创建/lib/systemd/system/mongod.service
包含内容的文件
[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/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
then start/stop commands should work
然后启动/停止命令应该工作
$ sudo service mongod start
For reference - I have Ubuntu 14.04 LTS, MongoDB 3.2.9 installed from
作为参考 - 我安装了 Ubuntu 14.04 LTS、MongoDB 3.2.9
deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse
回答by Eugene
I installed mongo server on Debian Jessie using manual from official site.
我使用官方网站上的手册在 Debian Jessie 上安装了 mongo 服务器。
It didn't started after recommended command sudo service mongod restart
with the same error - mongodb: unrecognized service
.
它建议命令后没有开始 sudo service mongod restart
用相同的error - mongodb: unrecognized service
。
After looking into installed package contents, I noticed that it contains only Systemd service unit, but no SystemV init script:
查看已安装的包内容后,我注意到它只包含 Systemd 服务单元,但没有 SystemV init 脚本:
# dpkg -L mongodb-org-server
/.
/usr
/usr/bin
/usr/bin/mongod
/usr/share
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/mongodb-org-server
/usr/share/doc
/usr/share/doc/mongodb-org-server
/usr/share/doc/mongodb-org-server/LICENSE-Community.txt
/usr/share/doc/mongodb-org-server/README
/usr/share/doc/mongodb-org-server/copyright
/usr/share/doc/mongodb-org-server/changelog.gz
/usr/share/doc/mongodb-org-server/GNU-AGPL-3.0.gz
/usr/share/doc/mongodb-org-server/THIRD-PARTY-NOTICES.gz
/usr/share/doc/mongodb-org-server/MPL-2.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/mongod.1.gz
/etc
/etc/mongod.conf
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/mongod.service
But my system was running on SysV init:
但是我的系统在 SysV init 上运行:
# stat /proc/1/exe
File: '/proc/1/exe' -> '/sbin/init'
So, there are 2 options now:
所以,现在有两个选择:
- (Continue on SysV) Write sysV init script manuallyas @khylo mentioned above
- (Switch to SystemD) and run
systemctl start mongod
- (在 SysV 上继续)按照上面提到的@khylo 手动编写 sysV init 脚本
- (切换到 SystemD)并运行
systemctl start mongod
回答by Touseef Murtaza
You can use mongod
command instead of mongodb
, if you find any issue regarding dbpath in mongo you can use my answer in the link below.
您可以使用mongod
command 而不是mongodb
,如果您发现有关 mongo 中 dbpath 的任何问题,您可以在下面的链接中使用我的答案。
回答by RawCode
Original Source - https://www.techrepublic.com/article/how-to-install-mongodb-community-edition-on-ubuntu-linux/
原始来源 - https://www.techrepublic.com/article/how-to-install-mongodb-community-edition-on-ubuntu-linux/
If you're on Ubuntu 16.04 and face the unrecognized service error, these instructions will fix it for you:-
如果您使用的是 Ubuntu 16.04 并面临无法识别的服务错误,这些说明将为您解决:-
- Open a terminal window.
- Issue the command
sudo apt-key adv —keyserver hkp://keyserver.ubuntu.com:80 —recv EA312927
- Issue the command
sudo touch /etc/apt/sources.list.d/mongodb-org.list
- Issue the command
sudo gedit /etc/apt/sources.list.d/mongodb-org.list
- Copy and paste one of the following lines from below (depending upon your release) into the open file.
For 12.04:
deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.6 multiverse
For 14.04:deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse
For 16.04:deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse
- 打开终端窗口。
- 发出命令
sudo apt-key adv —keyserver hkp://keyserver.ubuntu.com:80 —recv EA312927
- 发出命令
sudo touch /etc/apt/sources.list.d/mongodb-org.list
- 发出命令
sudo gedit /etc/apt/sources.list.d/mongodb-org.list
- 将以下行之一(取决于您的版本)复制并粘贴到打开的文件中。对于 12.04:
deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.6 multiverse
对于 14.04:deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.6 multiverse
对于 16.04:deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse
Make sure to edit the version number with the appropriate latest version and save the file.
确保使用适当的最新版本编辑版本号并保存文件。
InstallationOpen a terminal window and issue command sudo apt-get update && sudo apt-get install -y mongodb-org
安装打开终端窗口并发出命令sudo apt-get update && sudo apt-get install -y mongodb-org
Let the installation complete.
让安装完成。
Running MongoDBTo start the database, issue the command sudo service mongodb start
. You should now be able to issue the command to see that MongoDB is running: systemctl status mongodb
运行 MongoDB要启动数据库,请发出命令sudo service mongodb start
。您现在应该能够发出命令以查看 MongoDB 正在运行:systemctl status mongodb
Ubuntu 16.04 solutionIf you are using Ubuntu 16.04, you may run into an issue where you see the error mongodb: unrecognized service due to the switch from upstart to systemd. To get around this, you have to follow these steps.
Ubuntu 16.04 解决方案如果您使用的是 Ubuntu 16.04,您可能会遇到一个问题,您会看到错误 mongodb: unrecognized service 由于从 upstart 切换到 systemd。要解决此问题,您必须按照以下步骤操作。
If you added the
/etc/apt/sources.list.d/mongodb-org.list
, remove it with the commandsudo rm /etc/apt/sources.list.d/mongodb-org.list
Update apt with the command
sudo apt-get update
Install the official MongoDB version from the standard repositories with the command
sudo apt-get install mongodb
in order to get the service set up properlyRemove what you just installed with the command
sudo apt-get remove mongodb && sudo apt-get autoremove
如果添加了
/etc/apt/sources.list.d/mongodb-org.list
,请使用命令将其删除sudo rm /etc/apt/sources.list.d/mongodb-org.list
使用命令更新 apt
sudo apt-get update
使用命令从标准存储库安装官方 MongoDB 版本
sudo apt-get install mongodb
,以便正确设置服务删除您刚刚使用命令安装的内容
sudo apt-get remove mongodb && sudo apt-get autoremove
Now follow steps 1 through 5 listed above to install MongoDB; this should re-install the latest version of MongoDB with the systemd services already in place. When you issue the command systemctl status mongodb
you should see that the server is active.
现在按照上面列出的步骤 1 到 5 安装 MongoDB;这应该使用已经到位的 systemd 服务重新安装最新版本的 MongoDB。当您发出命令时,systemctl status mongodb
您应该看到服务器处于活动状态。
I mostly copy pasted the above (with minor modifications and typo fixes) from here - https://www.techrepublic.com/article/how-to-install-mongodb-community-edition-on-ubuntu-linux/
我主要是从这里复制粘贴上面的(稍作修改和错字修复) - https://www.techrepublic.com/article/how-to-install-mongodb-community-edition-on-ubuntu-linux/
回答by Juan Antonio
This is a simple solution that worked for me with the same problem (I think):
mv /var/lib/mongodb /var/lib/mongodb_backup
mkdir /var/lib/mongodb
chmod 700 /var/lib/mongodb
chown mongodb:daemon /var/lib/mongodb
systemctl restart mongodb or service mongod restart
这是一个简单的解决方案,对我有同样的问题(我认为):
mv /var/lib/mongodb /var/lib/mongodb_backup
mkdir /var/lib/mongodb
chmod 700 /var/lib/mongodb
chown mongodb:daemon /var/lib/mongodb
systemctl restart mongodb or service mongod restart