按照http://ruby-china.org/topics/454mongodb数据库第一次很轻松的连上了,第二天却怎么也连接不上,然后在找到一个帖子说开启了没,安装,
suu@suu-virtual-machine:~$ ps aux | grep mongo
mongodb 5491 5.5 1.4 155304 29932 ? Ssl 22:54 0:00 /usr/bin/mongod --config /etc/mongodb.conf
suu 5504 0.0 0.0 5684 800 pts/2 S+ 22:54 0:00 grep --color=auto mongo
看来是开启了,
然后就这样确认 shell 下能不能连上:
suu@suu-virtual-machine:~$ mongo 127.0.0.1:27017
MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:27017/test
Fri Feb 14 22:38:10.305 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
还是不行,
在网上搜了好多,http://www.markpoor.com/connecting_mongodb_failed/说得清楚: 就是:电脑/服务器崩溃->非安全关闭,触发 mongodb 保护程序->系统自动在数据库根目录的 mongod.lock 文件上做记录->mongod.lock 非空,mongd 程序拒绝启动->无法连接数据库
因为我用的是虚拟机,加上用 redis,mysql 和 sql 的时候也没有关掉就关了虚拟机,所以习惯性直接关机 QAQ
处理方法: 删除数据库根目录下的 mongod.lock 文件里的东西就行了
然后重启虚拟机:sudo service mongodb start
suu@suu-virtual-machine:~$ mongo 127.0.0.1:27017
MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:27017/test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
Fri Feb 14 22:54:11.748 [initandlisten]
Fri Feb 14 22:54:11.748 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Fri Feb 14 22:54:11.748 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
Fri Feb 14 22:54:11.748 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.
Fri Feb 14 22:54:11.748 [initandlisten] ** See http://dochub.mongodb.org/core/32bit
Fri Feb 14 22:54:11.748 [initandlisten]
搞了一天半,用了 n 种办法,没想到居然是这么简单的,记录下来,如果遇到类似问题的话就说不定可以节省掉不必要的麻烦了 QAQ,以我为鉴