简体   繁体   中英

How to check if Mongodb is properly installed

I installed MongoDb yesterday on a Mac Snow Leopard and got the following error message

Mongo::ConnectionFailure: Failed to connect to a master node at localhost:27017

when trying to run some tests in Rails that used a mongodb.

Another SO question mongo - ruby connection problem about the same error message had an answer that recommended removing the lock file

 sudo rm /var/lib/mongodb/mongod.lock

but when I run that command i'm getting

 No such file or directory

Any ideas how I can figure out how to get it working or see if it's properly installed?

The easiest way to run mongodb on Mac OS is:

Download binary package from http://www.mongodb.org/downloads , for me, I am using lastest 64 bit version ( http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.2.tgz )

  1. mkdir -p $HOME/opt
  2. cd $HOME/opt
  3. wget http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.2.tgz to download the latest (2.0.2 for now) 64 bit binary package for Mac OS
  4. tar xf mongodb-osx-x86_64-2.0.2.tgz -C $HOME/opt to unpack the package, and it will be unpacked to $HOME/opt/mongodb-osx-x86_64-2.0.2
  5. mkdir -p $HOME/opt/mongodata to create the data directory for mongodb
  6. $HOME/opt/mongodb-osx-x86_64-2.0.2/bin/mongod --dbpath=$HOME/opt/mongodata --logpath=$HOME/opt/mongod.log to start the mongodb daemon
  7. Then you can run $HOME/opt/mongodb-osx-x86_64-2.0.2/bin/mongo to connect to your local mongodb service

You can also have http://www.mongodb.org/display/DOCS/Quickstart+OS+X as additional reference

It's not running mongod. You need to start it, probably with a script so you can control how it starts. The script I use on my mac looks like: mongod -f /etc/mongodb.conf & .

At this point I can't remember if the install came with /etc/mongodb.conf, or if I put it there myself. It's fairly simple. I store my data/log in my user folder (this is obviously a development environment):

dbpath = /Users/me/data/
logpath = /Users/me/mongo.log

# Only accept local connections
bind_ip = 127.0.0.1

You'll also need to create your data folder, if it doesn't exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM