Here I use centos as its running carrier.
1. Download MongoDB Linux version (note the difference between 32-bit and 64-bit),: http://www.mongodb.org/downloads
2. Put the downloaded MongoDB Installation File mongodb-linux-i686-1.6.5.tgz under/usr/local/
3. Decompress tar-zxvf mongodb-linux-i686-1.6.5.tgz
Rename music mongodb-linux-i686-1.6.5.tgz MongoDB
4. Create a database file directory. The default value is/data/DB. I put the database file directory under the current folder, mkdir-p Data/dB, and create the log directory mkdir log.
5. Start the service
CD/usr/local/MongoDB/bin
./Mongod-dbpath = ../data/DB-logpath = ../log/MongoDB. Log
6. Start the client shell test.
[Root @ localhost bin] #./Mongo
MongoDB shell version: 1.6.5
Connecting to: Test
> DB. Foo. Save ({A: 1 })
> DB. Foo. Find ()
{"_ Id": objectid ("4d292a457e289d5d90dc6f33"), "A": 1}
7. Add the MongoDB service to the random start
VI/etc/rc. Local
Use the VI editor to open the configuration file and add the following line of code
/Usr/local/MongoDB/bin/mongod-dbpath =/usr/local/MongoDB/data/DB -- Port 27017
-Logpath =/usr/local/MongoDB/log -- logappend
8. Connect to the MongoDB client. If the following information is displayed, the startup is successful.
./Mongodbbin/Mongo
MongoDB shell version: 1.6.5
Connecting to: Test
>
9. Shut down MongoDB at script startup
## start-mongod.shMONGODIR=/usr/local/mongodbMONGOD=$MONGODIR/bin/mongodMONGO=$MONGODIR/bin/mongoDBDIR=$MONGODIR/data/dbLOGPATH=$MONGODIR/log/mongodb.log# mongod will print its pid, so store it in out.tmp, then # print it using awk to mongod.pid$MONGOD --dbpath $DBDIR --fork --logpath $LOGPATH --logappend > out.tmpawk 'NR == 2 { print $3 }' < out.tmp > mongod.pidsleep 3$MONGO < onstart.js## in onstart.jsuse admin;db.runCommand("logRotate");## stop-mongod.shkill -15 `cat $mongod.pid`