我安装了 mongodb 到/opt/mongodb 目录下,然后
export PATH=$PATH:/opt/mongodb/bin
重启 shell 执行:
crazyjin@T500:~$ sudo mongod
sudo: mongod:找不到命令
切换到 root 后则可以找到命令,mongod 正常运行
crazyjin@T500:~$ sudo su
root@T500:/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
crazyjin@T500:~$ 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
crazyjin@T500:~$ 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
crazyjin@T500:~$
这可以说明问题么?
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.
#9 楼 @fenprace
crazyjin@T500:/$ 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
crazyjin@T500:/$ sudo su
root@T500:/# 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
root@T500:/#
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.