当前位置:  开发笔记 > 编程语言 > 正文

无法启动mongodb作为sudo

如何解决《无法启动mongodb作为sudo》经验,为你挑选了2个好方法。

尝试启动时,mongodb返回与访问文件相关的错误:

root@mongo01:~# sudo service mongodb start
mongodb start/running, process 4118
root@mongo01:~# Mon Jul 25 17:03:54 [initandlisten] MongoDB starting : pid=4118 port=27017 dbpath=/var/lib/mongodb 64-bit 
Mon Jul 25 17:03:54 [initandlisten] db version v1.8.2, pdfile version 4.5
Mon Jul 25 17:03:54 [initandlisten] git version: 433bbaa14aaba6860da15bd4de8edf600f56501b
Mon Jul 25 17:03:54 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Mon Jul 25 17:03:54 [initandlisten] couldn't open /var/lib/mongodb/adrise.ns errno:13 Permission denied
Mon Jul 25 17:03:54 [initandlisten] error couldn't open file /var/lib/mongodb/adrise.ns terminating
Mon Jul 25 17:03:54 dbexit: 
Mon Jul 25 17:03:54 [initandlisten] shutdown: going to close listening sockets...
Mon Jul 25 17:03:54 [initandlisten] shutdown: going to flush diaglog...
Mon Jul 25 17:03:54 [initandlisten] shutdown: going to close sockets...
Mon Jul 25 17:03:54 [initandlisten] shutdown: waiting for fs preallocator...
Mon Jul 25 17:03:54 [initandlisten] shutdown: closing all files...
Mon Jul 25 17:03:54 closeAllFiles() finished
Mon Jul 25 17:03:54 [initandlisten] shutdown: removing fs lock...
Mon Jul 25 17:03:54 dbexit: really exiting now

要么

Mon Jul 25 17:03:22 [initandlisten] MongoDB starting : pid=4095 port=27017 dbpath=/var/lib/mongodb 64-bit 
Mon Jul 25 17:03:22 [initandlisten] db version v1.8.2, pdfile version 4.5
Mon Jul 25 17:03:22 [initandlisten] git version: 433bbaa14aaba6860da15bd4de8edf600f56501b
Mon Jul 25 17:03:22 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Mon Jul 25 17:03:22 [initandlisten] journal dir=/var/lib/mongodb/journal
Mon Jul 25 17:03:22 [initandlisten] recover : no journal files present, no recovery needed
Mon Jul 25 17:03:22 [initandlisten] info preallocateIsFaster couldn't run; returning false
Mon Jul 25 17:03:22 [initandlisten] exception in initAndListen std::exception: couldn't open file /var/lib/mongodb/journal/j._0 for writing errno:13 Permission denied, terminating
Mon Jul 25 17:03:22 dbexit: 
Mon Jul 25 17:03:22 [initandlisten] shutdown: going to close listening sockets...
Mon Jul 25 17:03:22 [initandlisten] shutdown: going to flush diaglog...
Mon Jul 25 17:03:22 [initandlisten] shutdown: going to close sockets...
Mon Jul 25 17:03:22 [initandlisten] shutdown: waiting for fs preallocator...
Mon Jul 25 17:03:22 [initandlisten] shutdown: lock for final commit...
Mon Jul 25 17:03:22 [initandlisten] shutdown: final commit...
Mon Jul 25 17:03:22 [initandlisten] shutdown: closing all files...
Mon Jul 25 17:03:22 closeAllFiles() finished
Mon Jul 25 17:03:22 [initandlisten] shutdown: journalCleanup...
Mon Jul 25 17:03:22 [initandlisten] removeJournalFiles
Mon Jul 25 17:03:22 [initandlisten] shutdown: removing fs lock...
Mon Jul 25 17:03:22 dbexit: really exiting now

当我尝试:

root @ mongo01:〜#mongodb -f /etc/mongodb.conf

它开始正常,任何想法导致问题?

谢谢



1> Jorge Barata..:

Mon Jul 25 17:03:54 [initandlisten] couldn't open /var/lib/mongodb/adrise.ns errno:13 Permission denied

这是权限问题,请运行以下命令:

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


工作就像一个魅力.谢谢.请接受这个作为答案.
工作得很完美.我不明白为什么它以前工作!

2> 小智..:

所以我突然遇到了这个问题,我不知道为什么.问题是upstart文件想要以用户mongodb的身份运行mongo.来自/etc/init/mongodb.conf:

if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb.conf; fi

chuid部分告诉它以不同的用户身份运行,即使您以root身份运行此脚本.出于某种原因,当我ls -l进入时/var/lib/mongodb,我注意到所有文件都归root所有,这就是为什么我们的mongodb用户无法使用它们.我这样做了:

sudo chown mongodb:mongodb /var/lib/mongodb

一切都很顺利.问题首先是怎么发生的?不确定.

推荐阅读
jerry613
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有