Ubuntu上的MongoDB无法作为服务启动,日志中没有任何内容 [英] MongoDB on Ubuntu won't start as a service, nothing in the log

查看:440
本文介绍了Ubuntu上的MongoDB无法作为服务启动,日志中没有任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu上运行MongoDB 2.2,如果我运行:

Am running MongoDB 2.2 on Ubuntu and if I run:

sudo mongod

我收到一个错误,它找不到/data/db,它不在数据库所在的位置.在mongod.conf中,数据库路径指定为db所在的Ubuntu 10gen默认/var/lib/mongodb.似乎mongod找不到conf文件.所以当我跑步时:

I get an error that it can't find /data/db, which is not where the database is. In mongod.conf the database path is specified as the Ubuntu 10gen default /var/lib/mongodb which is where the db is located. Seems like mongod is not finding the conf file. So when I run:

sudo mongod -f /etc/mongodb.conf

服务器正常启动,并且输出记录到日志文件:/var/log/mongodb/mongodb.log.所有人都开心.我可以切换到另一个shell,登录mongo shell,查看数据库并运行查询.

The server starts up fine and output is logged to the log file: /var/log/mongodb/mongodb.log. All is happy. I can switch to another shell, log into mongo shell, see the databases and run queries.

因此,我取消了该操作并尝试作为服务运行:

So, I cancel out of that and try to run as a service:

> sudo status mongodb
mongodb stop/waiting
> sudo start mongodb
mongodb start/running, process 10468

到目前为止看起来不错,但是mongo服务器没有启动.运行另一个:

Looks good so far, but the mongo server did not start. Running another:

> sudo status mongodb
mongodb stop/waiting
> mongo
MongoDB shell version: 2.2.0
connecting to: test
Sat Sep  1 19:07:43 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed

测试"不是正确的数据库,并且日志文件中没有任何内容.

"test" is not the correct database, and nothing appears in the log file.

我不知所措.我检查了暴发户脚本,它们看起来还不错. /etc/init/mongodb.conf运行:

I am at a loss as to what could be wrong. I checked the upstart scripts and they seem fine. /etc/init/mongodb.conf runs:

mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb.conf

推荐答案

好的,所有这些都归功于权限,但让我们逐步介绍它.当您运行sudo mongod时,它根本不会加载配置文件,实际上是从默认编译的端口开始-端口数据库路径 db等.-这就是为什么您收到有关无法找到该文件夹​​的错误的原因. "Ubuntu默认值"仅在将其指向配置文件时使用(如果您开始使用service命令,则将在后台为您完成此操作).

OK, this all comes down to permissions, but let's take it step by step. When you run sudo mongod it does not load a config file at all, it literally starts with the compiled in defaults - port 27017, database path of /data/db etc. - that is why you got the error about not being able to find that folder. The "Ubuntu default" is only used when you point it at the config file (if you start using the service command, this is done for you behind the scenes).

接下来,您将像这样运行它:

Next you ran it like this:

sudo mongod -f /etc/mongodb.conf

如果以前没有问题,那么现在将有-您已经以正常配置(指向您通常的dbpath和日志)作为root用户运行了该过程.这意味着该普通的MongoDB文件夹中现在将有许多文件,其中的user:group为root:root.

If there weren't problems before, then there will be now - you have run the process, with your normal config (pointing at your usual dbpath and log) as the root user. That means that there are going to now be a number of files in that normal MongoDB folder with the user:group of root:root.

当您尝试再次将其作为普通服务启动时,这将导致错误,因为mongodb用户(该服务将尝试运行该用户)将无权访问这些root:root文件,可能无法写入日志文件为您提供任何信息.

This will cause errors when you try to start it as a normal service again, because the mongodb user (which the service will attempt to run as) will not have permission to access those root:root files, and most notably, it will probably not be able to write to the log file to give you any information.

因此,要将其作为常规服务运行,我们需要修复这些权限.首先,确保MongoDB当前未以root用户身份运行,然后:

Therefore, to run it as a normal service, we need to fix those permissions. First, make sure MongoDB is not currently running as root, then:

cd /var/log/mongodb
sudo chown -R mongodb:mongodb .
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb .

应该可以解决这个问题(假设user:group是mongodb:mongodb),尽管最好用ls -al或类似的方法进行验证.完成此操作后,您应该能够使服务再次成功启动.

That should fix it up (assuming the user:group is mongodb:mongodb), though it's probably best to verify with an ls -al or similar to be sure. Once this is done you should be able to get the service to start successfully again.

这篇关于Ubuntu上的MongoDB无法作为服务启动,日志中没有任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆