我安装了mongodb到/opt/mongodb目录下,然后
export PATH=$PATH:/opt/mongodb/bin
重启 shell 执行:
[email protected]:~$ sudo mongod
sudo: mongod:找不到命令
切换到 root 后则可以找到命令,mongod 正常运行
[email protected]:~$ sudo su
[email protected]:/home/crazyjin# mongod
mongod --help for help and startup options
……
不用 root 权限也可以执行,但是:
Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
何解?
#2 楼 @vincenttone
[email protected]:~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/crazyjin/sda3/myscript/:/opt/jdk1.6/bin:/opt/jdk1.6/jre/bin:/opt/mongodb2.4.3/bin
[email protected]:~$ sudo echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/crazyjin/sda3/myscript/:/opt/jdk1.6/bin:/opt/jdk1.6/jre/bin:/opt/mongodb2.4.3/bin
[email protected]:~$
这可以说明问题么?
Because it said "Permission denied"
Mongodb created
/db/data
as the default directory to store the database after installing, and it belongs to root defaultly.
#7 楼 @fenprace i tried to start mongod under the priority of root:
sudo mongod
but it always return this:
[email protected]:/$ sudo mongod
sudo: mongod:找不到命令
that's what makes me confused.
#9 楼 @fenprace
[email protected]:/$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/crazyjin/sda3/myscript/:/opt/jdk1.6/bin:/opt/jdk1.6/jre/bin:/opt/mongodb2.4.3/bin
[email protected]:/$ sudo su
[email protected]:/# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/crazyjin/sda3/myscript/:/opt/jdk1.6/bin:/opt/jdk1.6/jre/bin:/opt/mongodb2.4.3/bin
[email protected]:/#
when i ln /opt/mngodb/bin/mongod to /usr/local/bin/mongod as a symbolic link and i excutes
sudo mongod
it works well.
i read manpage of sudo.but i can not understant it.it looks like there are some security policies there. The symbolic links solved my problem. thank you.
#9 楼 @fenprace If you use Ubuntu and some other linux distributions, the root password is unknown actually. You can have a try to run su
, and input your password. You'll get an error.
To run a shell as the root, you can run sudo su
, it means running su
as the root. And the su command will start a shell. Simply running sudo bash
is also available.
This problem won't happen on Archlinux, Gentoo and most of the server linux distributions. Because on these linux distributions, the root's password is set by user before the installation and the password is known. So if you are using one of the above, just running su
also works well.