Linux Setup MongoDB boot __linux

Source: Internet
Author: User
Tags mongodb mongodb client

Add a MongoDB service to a random boot

Vi/etc/rc.local

Use the VI Editor to open the configuration file and add the following line of code to it

/usr/local/mongodb/bin/mongod-dbpath=/usr/local/mongodb/data/db--fork--port 27017--logpath=/usr/local/mongodb/ Log/work.log--logappend--auth

Start a service

/usr/local/mongodb/bin/mongod-dbpath=/usr/local/mongodb/data/db--fork--port 27017--logpath=/usr/local/mongodb/ Log/work.log--logappend--auth

Other:

MongoDB installed and configured under Linux

Here I choose Rehl 6 as its operating carrier.

1. Download MongoDB Linux version (note 32-bit and 64-bit difference), download address: http://www.mongodb.org/downloads

2. Place the downloaded MongoDB installation file mongodb-linux-i686-1.6.5.tgz under/usr/local/

3. Decompression TAR-ZXVF mongodb-linux-i686-1.6.5.tgz

Rename MV Mongodb-linux-i686-1.6.5.tgz MongoDB

4, create the database file directory, default to/data/db, I put the database file directory under the current folder, Mkdir-p data/db, create log directory mkdir logs

5. Start 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 boot

Vi/etc/rc.local

Use the VI Editor to open the configuration file and add the following line of code to it

/usr/local/mongodb/bin/mongod-dbpath=/usr/local/mongodb/data/db--port 27017

-logpath=/usr/local/mongodb/log--logappend

8. Connect the MongoDB client, and the following message will start successfully
./mongodbbin/mongo
MongoDB Shell version:1.6.5
Connecting To:test
>

9, script startup shutdown MongoDB

# # Start-mongod.sh

Mongodir =/usr/local/mongodb
Mongod = $MONGODIR/bin/mongod
MONGO = $MONGODIR/bin/mongo
Dbdir = $MONGODIR/data/db
LOGPATH = $MONGODIR/log/mongodb.log

# Mongod'll 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.tmp
awk ' NR = = 2 {print $} ' < out.tmp > Mongod.pid

Sleep 3
$MONGO < Onstart.js

# # in Onstart.js

Use admin;
Db.runcommand ("Logrotate");

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.