mongodb 服务未启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9884233/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:34:30  来源:igfitidea点击:

mongodb service is not starting up

mongodb

提问by Esenbek Kydyr uulu

I've installed the mongodb 2.0.3, using the mongodb-10gen debian package. Everything went well, except the service which is installed by default is not starting up when computer starts. The mongodis running only as root user. maybe this is the reason. but as far as I know, the services should be running since they are added by the root user.

我已经使用 mongodb-10gen debian 包安装了 mongodb 2.0.3。一切都很顺利,除了默认安装的服务在计算机启动时没有启动。的mongod运行仅作为根用户。也许这就是原因。但据我所知,服务应该正在运行,因为它们是由 root 用户添加的。

What may be the solution?

可能的解决方案是什么?

if I run just mongod

如果我只是跑 mongod

Tue Mar 27 13:00:44 [initandlisten] couldn't open /data/db/transaction_processor_dummy_development.ns errno:1 Operation not permitted

If I run sudo service mongodb startit says:

如果我运行sudo service mongodb start它说:

mongodb start/running, process 4861

but there's no process when looking with htopand mongosays:

但是在查看htopmongo说时没有过程:

MongoDB shell version: 2.0.3
connecting to: test
Tue Mar 27 13:02:40 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed

采纳答案by Esenbek Kydyr uulu

Fixed!

固定的!

The reason was the dbpathvariable in /etc/mongodb.conf. Previously, I was using mongodb 1.8, where the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongodwith --config /etc/mongodb.confoption.

原因是 中的dbpath变量/etc/mongodb.conf。以前,我使用的是 mongodb 1.8,其中 dbpath 的默认值为/data/db. upstart 作业mongodb(随 mongodb-10gen 包一起提供)调用mongodwith--config /etc/mongodb.conf选项。

As a solution, I only had to change the owner of the /data/dbdirectory recursively.

作为解决方案,我只需要/data/db递归地更改目录的所有者。

回答by Nianliang

On my ubuntu server, just run:

在我的 ubuntu 服务器上,运行:

sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start

回答by RyanH

This can also happen if your file permissions get changed somehow. Removing the lock file didn't help, and we were getting errors in the log file like:

如果您的文件权限以某种方式更改,也会发生这种情况。删除锁定文件没有帮助,我们在日志文件中收到错误,例如:

2016-01-20T09:14:58.210-0800 [initandlisten] warning couldn't write to / rename file /var/lib/mongodb/journal/prealloc.0: couldn't open file    /var/lib/mongodb/journal/prealloc.0 for writing errno:13 Permission denied
2016-01-20T09:14:58.288-0800 [initandlisten] couldn't open /var/lib/mongodb/local.ns errno:13 Permission denied
2016-01-20T09:14:58.288-0800 [initandlisten] error couldn't open file /var/lib/mongodb/local.ns terminating

So, went to check permissions:

所以,去检查权限:

ls -l /var/lib/mongodb

total 245780
drwxr-xr-x 2 mongodb mongodb     4096 Jan 20 09:14 journal
drwxr-xr-x 2 root    root        4096 Jan 20 09:11 local
-rw------- 1 root    root    67108864 Jan 20 09:11 local.0
-rw------- 1 root    root    16777216 Jan 20 09:11 local.ns
-rwxr-xr-x 1 mongodb nogroup        0 Jan 20 09:14 mongod.lock

To fix:

修理:

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

Remove the lock file if it's still there:

如果它仍然存在,请删除锁定文件:

# rm /var/lib/mongodb/mongod.lock

Start mongodb

启动mongodb

# service mongodb start

Tail the log and you should see at the end of it:

跟踪日志,您应该在其末尾看到:

tail -f /var/log/mongodb/mongodb.log
2016-01-20T09:16:02.025-0800 [initandlisten] waiting for connections on port 27017

回答by Andres

I was boredof this problem so I decided to create a shell script to restore my mongo data base easily.

我对这个问题感到厌烦,所以我决定创建一个 shell 脚本来轻松恢复我的 mongo 数据库。

#!/bin/sh
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start

http://ideone.com/EuqDZ8

http://ideone.com/EuqDZ8

回答by Socratees Samipillai

Remember that when you restart the database by removing .lock files by force, the data might get corrupted. Your server shouldn't be considered "healthy" if you restarted the server that way.

请记住,当您通过强制删除 .lock 文件重新启动数据库时,数据可能会损坏。如果您以这种方式重新启动服务器,则您的服务器不应被视为“健康”。

To amend the situation, either run

要修改这种情况,请运行

mongod --repair

or

或者

> db.repairDatabase();    

in the mongo shell to bring your database back to "healthy" state.

在 mongo shell 中使您的数据库恢复到“健康”状态。

回答by AbdullahDiaa

1 - disable forkoption in /etc/mongodb.confif enabled

1 -如果启用则禁用fork选项/etc/mongodb.conf

2 - Repair your database

2 -修复您的数据库

mongod --repair --dbpath DBPATH

3 - kill current mongod process

3 -杀死当前的 mongod 进程

Find mongo processes

查找 mongo 进程

ps -ef | grep mongo

you'll get mongod PID

你会得到 mongod PID

mongodb   PID     1  0 06:26 ?        00:00:00 /usr/bin/mongod --config /etc/mongodb.conf

Stop current mongod process

停止当前的 mongod 进程

kill -9 PID

4 - start mongoDB service

4 -启动 mongoDB 服务

service mongodb start

回答by shacharsol

For ubunto , what made it happen and was real simple is to install mongodb package:

对于 ubunto ,让它发生并且非常简单的是安装 mongodb 包:

sudo apt-get install  mongodb

回答by Joe

Sometimes you need to remove the .lock file to get the service to run

有时您需要删除 .lock 文件才能运行服务

回答by ashish

just re-installed mongo and it worked. No collections lost. Easiest solution atleast for me

刚刚重新安装了 mongo 并且它起作用了。没有收藏丢失。至少对我来说最简单的解决方案

回答by schory

Nianliang's solution turned out so useful from my Vagrant ubunuto, thart I ended up adding these 2 commands to my /etc/init.d/mongodb file:

Nianliang 的解决方案在我的 Vagrant ubunuto 中非常有用,我最终将这 2 个命令添加到我的 /etc/init.d/mongodb 文件中:

.
.
.    
start|stop|restart)
        rm /var/lib/mongodb/mongod.lock
        mongod --repair
.
.
.