我正在尝试使用osx来玩mongodb,为此我需要在我的mongodb exe目录中使用以下内容创建一个目录
mkdir /data/db
但是当我尝试这样做时,我的命令提示符将返回以下内容
$ mkdir /data/db
mkdir: /data: No such file or directory
目前我的mongodb exe没有启用命令行,也就是说它不在bash的路径中,有没有人知道如何让mongodb程序全局化?
提前致谢
加入 所以我尝试了添加bash文件和
$ sudo mkdir -p /data/db/
$ mkdir -p /data/db
只需输入
即可$ mongod
仍然无效,我必须输入以下内容
$ ./mongod
但是它给出了以下
$ ./mongod
./mongod --help for help and startup options
Thu Jul 18 13:27:37.558 [initandlisten] MongoDB starting : pid=1042 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 13:27:37.559 [initandlisten]
Thu Jul 18 13:27:37.559 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 13:27:37.559 [initandlisten] db version v2.4.5
Thu Jul 18 13:27:37.559 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 13:27:37.559 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu- 1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 13:27:37.559 [initandlisten] allocator: system
Thu Jul 18 13:27:37.559 [initandlisten] options: {}
Thu Jul 18 13:27:37.559 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Thu Jul 18 13:27:37.559 dbexit:
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: final commit...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: closing all files...
Thu Jul 18 13:27:37.559 [initandlisten] closeAllFiles() finished
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 13:27:37.559 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Thu Jul 18 13:27:37.559 dbexit: really exiting now
编辑2:
尝试
sudo chown 'myusername' /data/db
既不 sudo ./mongod 要么 ./mongod
工作
编辑3:
$ ./mongod
./mongod --help for help and startup options
Thu Jul 18 14:11:35.144 [initandlisten] MongoDB starting : pid=1550 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 14:11:35.145 [initandlisten]
Thu Jul 18 14:11:35.145 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 14:11:35.145 [initandlisten] db version v2.4.5
Thu Jul 18 14:11:35.145 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 14:11:35.145 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 14:11:35.145 [initandlisten] allocator: system
Thu Jul 18 14:11:35.145 [initandlisten] options: {}
Thu Jul 18 14:11:35.145 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Thu Jul 18 14:11:35.145 dbexit:
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: final commit...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: closing all files...
Thu Jul 18 14:11:35.145 [initandlisten] closeAllFiles() finished
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 14:11:35.145 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Thu Jul 18 14:11:35.145 dbexit: really exiting now
$ sudo ./mongod
./mongod --help for help and startup options
Thu Jul 18 14:11:43.450 [initandlisten] MongoDB starting : pid=1552 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 14:11:43.451 [initandlisten]
Thu Jul 18 14:11:43.451 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 14:11:43.451 [initandlisten] db version v2.4.5
Thu Jul 18 14:11:43.451 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 14:11:43.451 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 14:11:43.451 [initandlisten] allocator: system
Thu Jul 18 14:11:43.451 [initandlisten] options: {}
Thu Jul 18 14:11:43.451 [initandlisten] journal dir=/data/db/journal
Thu Jul 18 14:11:43.451 [initandlisten] recover : no journal files present, no recovery needed
Thu Jul 18 14:11:43.489 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
Thu Jul 18 14:11:43.489 [websvr] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:28017
Thu Jul 18 14:11:43.489 [initandlisten] ERROR: addr already in use
Thu Jul 18 14:11:43.489 [websvr] ERROR: addr already in use
Thu Jul 18 14:11:43.489 [initandlisten] now exiting
Thu Jul 18 14:11:43.489 dbexit:
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: final commit...
Thu Jul 18 14:11:43.500 [initandlisten] shutdown: closing all files...
Thu Jul 18 14:11:43.505 [initandlisten] closeAllFiles() finished
Thu Jul 18 14:11:43.505 [initandlisten] journalCleanup...
Thu Jul 18 14:11:43.505 [initandlisten] removeJournalFiles
Thu Jul 18 14:11:43.506 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 14:11:43.506 dbexit: really exiting now
编辑4:
$ sudo killall mongod
Password:
$ sudo rm -rf /data/db
$ sudo mkdir -p /data/db
$ sudo chown xxxxx/data/db
usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ...
chown [-fhv] [-R [-H | -L | -P]] :group file ...
$ ./mongod
./mongod --help for help and startup options
Thu Jul 18 14:27:04.047 [initandlisten] MongoDB starting : pid=417 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 14:27:04.047 [initandlisten]
Thu Jul 18 14:27:04.047 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 14:27:04.047 [initandlisten] db version v2.4.5
Thu Jul 18 14:27:04.047 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 14:27:04.047 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 14:27:04.047 [initandlisten] allocator: system
Thu Jul 18 14:27:04.047 [initandlisten] options: {}
Thu Jul 18 14:27:04.110 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Thu Jul 18 14:27:04.110 dbexit:
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: final commit...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: closing all files...
Thu Jul 18 14:27:04.119 [initandlisten] closeAllFiles() finished
Thu Jul 18 14:27:04.119 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 14:27:04.119 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Thu Jul 18 14:27:04.119 dbexit: really exiting now
答案 0 :(得分:-1)
你能把它添加到你的bashrc吗?
cd
nano .bashrc
mongodb="path_To_mongodb.exe" ## add this to bashrc, save and quit. Then restart terminal.
确保没有空格。将“path_To_mongodb.exe”替换为exe的实际路径。确保它在正确的文件中,并保存,终端重新启动,如果您在脚本中尝试它,请通过添加
来扩展变量shopt -s expand_aliases
source ~/.bashrc
到剧本的开头。