我的问题类似于本网站上的其他输入和建议,但没有人帮助过我。安装MongoDB后,由于数据库未运行,因此尚未启动。
首先尝试运行mongo,我回答了这个问题:
Mac-Pro-de-User: ~ user $ mongo
MongoDB shell version: 2.6.4
connecting to: test
2014-10-28T10: 47: 08713-0700 warning: Failed to connect to 127.0.0.1:27017, reason: errno: 61 Connection refused
2014-10-28T10: 47: 08713-0700 Error: could not connect to server 127.0.0.1:27017 (127.0.0.1) Attempt connection failed at src / mongo / shell / mongo.js: 146
exception: connect failed
然后尝试检查mongod,我回答了这个问题:
Mac-Pro-de-User: ~ user $ mongod
mongod --help for help and startup options
2014-10-28T10: 59: 34485-0700 [initandlisten] MongoDB starting: pid = 926 port = 27017 dbpath = / data / db host = 64-bit Mac-Pro-de-Ernesto.local
2014-10-28T10: 59: 34485-0700 [initandlisten]
2014-10-28T10: 59: 34485-0700 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, Should be at Least 1000
2014-10-28T10: 59: 34485-0700 [initandlisten] db version v2.6.4
2014-10-28T10: 59: 34485-0700 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-10-28T10: 59: 34485-0700 [initandlisten] Build info: Darwin bs-osx108-4 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root: xnu-2050.48.12 ~ 1 / x86_64 RELEASE_X86_64 BOOST_LIB_VERSION = 1_49
2014-10-28T10: 59: 34485-0700 [initandlisten] allocator: system
2014-10-28T10: 59: 34485-0700 [initandlisten] options: {}
2014-10-28T10: 59: 34486-0700 [initandlisten] journal dir = / data / db / journal
2014-10-28T10: 59: 34486-0700 [initandlisten] recover: no journal files present, no recovery needed
2014-10-28T10: 59: 34500-0700 [FileAllocator] allocating new datafile /data/db/local.ns, filling zeroes With ...
2014-10-28T10: 59: 34500-0700 [FileAllocator] creating directory / data / db / _tmp
2014-10-28T10: 59: 34512-0700 [FileAllocator] done allocating datafile /data/db/local.ns, size: 16MB, took 0.011 secs
2014-10-28T10: 59: 34726-0700 [FileAllocator] allocating new datafile /data/db/local.0, filling zeroes With ...
2014-10-28T10: 59: 35398-0700 [FileAllocator] done allocating datafile /data/db/local.0, size: 64MB, took 0.671 secs
2014-10-28T10: 59: 35695-0700 [initandlisten] build index on: local.startup_log properties: {v: 1, key: {_id: 1}, name: "_id_" ns "local.startup_log"}
2014-10-28T10: 59: 35695-0700 [initandlisten] index added to empty collection
2014-10-28T10: 59: 35695-0700 [initandlisten] Local command $ cmd command. Create {create: "startup_log" size: 10485760, capped: true} ntoreturn: 1 KeyUpdates: 0 numYields: 0 reslen: 37 1194ms
2014-10-28T10: 59: 35695-0700 [initandlisten] waiting for connections on port 27017
2014-10-28T11: 00: 34516-0700 [clientcursormon] mem (MB) res: 33 virt: 2653
2014-10-28T11: 00: 34516-0700 [clientcursormon] mapped (incl journal view): 160
2014-10-28T11: 00: 34516-0700 [clientcursormon] connections: 0
然后再次尝试连接并花一些时间,并再次说同样的话:
2014-10-28T11: 05: 34589-0700 [clientcursormon] mem (MB) res: 33 virt: 2653
2014-10-28T11: 05: 34589-0700 [clientcursormon] mapped (incl journal view): 160
2014-10-28T11: 05: 34589-0700 [clientcursormon] connections: 0
等等。如果你能提供帮助,我将非常感激。
PS:已经有/ data / db拥有777权限,我就是 使用OSX Mavericks 10.9.5
答案 0 :(得分:19)
您是否在时间戳建议的单独操作中在同一终端中运行所有这些命令? (如果没有,我希望在故障和日志之间看到重叠,以便正确诊断)。
如果是这样,那么你正在做的事情如下:
数据库需要与shell同时运行,以便您可以连接到它。因此,您应该在一个终端中启动mongod
进程,使其保持运行状态,然后打开一个新终端(或选项卡)并运行mongo
命令以连接到仍在运行的数据库。另一个选项是run mongod
as a daemon,这将允许您在返回后在同一终端中运行mongo
命令。
注意:您永远不应该拥有具有777权限的文件夹,这不是必需的,并且存在重大的安全风险。
答案 1 :(得分:1)
试试这个命令。
sudo chown mongodb /tmp/mongodb-27017.sock
和
sudo service mongod restart
答案 2 :(得分:1)
固定!
原因是/etc/mongodb.conf中的dbpath变量。以前,我使用的是mongodb 1.8,其中dbpath的默认值是/ data / db。 upstart作业mongodb(与mongodb-10gen软件包一起提供)使用--config /etc/mongodb.conf选项调用mongod。
作为解决方案,我只需要递归更改/ data / db目录的所有者。
像这样:转到“/ data”<终端中的位置,然后输入
sudo chown -R <username>:foldername
例如:
sudo chown -R raja db/
答案 3 :(得分:0)
你好,只检查你是否创建了/ data / db路径,如果你做了,那么用chmod给予755权限。