Install and configure MongoDB in Linux

Source: Internet
Author: User
Tags mongodb client

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`
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.