Installation and startup under MongoDB Linux (RPM)

Source: Internet
Author: User
Tags mongodump mongorestore

1. Download MongoDB, the version downloaded here is: Mongodb-linux-i686-1.8.1.tgz.tar.

Http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.1.tgz

Related reading:

Installation and startup http://www.linuxidc.com/Linux/2011-05/36309.htm under MongoDB Linux

Advanced query Example under MongoDB http://www.linuxidc.com/Linux/2011-05/36312.htm

MongoDB Java API for Insert and single collection basic query use example http://www.linuxidc.com/Linux/2011-05/36313.htm

Query operation under MONGODB (corresponds to Java API query operation) http://www.linuxidc.com/Linux/2011-05/36314.htm

2. Unzip the file into a directory and rename it:

    1. [Root@localhost src]# tar-xzvf mongodb-linux-i686-1.8. 1.tgz.tar
    2. [Root@localhost src]# mv mongodb-linux-i686-1.8. 1/usr/local/mongodb/

3. View post-installation files:

  1. [Root@localhost src]# cd/usr/local/mongodb/
  2. [Root@localhost mongodb]# ls
  3. Bin gnu-agpl-3.0 README third-party-notices
  4. [Root@localhost mongodb]# cd bin/
  5. [Root@localhost bin]# ls
  6. Bsondump dbbak MONGO Mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongost At

The Mongod under the bin is the service-side process of MongoDB, MONGO is its client, and other commands are used for MongoDB for other purposes such as MongoDB file export.

4. Start MongoDB.

To set up a good MongoDB storage data files and log files directory, here is established under/data:

    1. [Root@localhost etc]# cd/data/
    2. [Root@localhost data]# ls
    3. Mongodb_data Mongodb_log

Use Mongod to start MongoDB under the bin under the MongoDB installation directory,

    1. ./mongod--dbpath=/data/mongodb_data/--logpath=/data/mongodb_log/mongodb.log--logappend&

After you wait for the startup to succeed, you can see if the boot was successful, the default port number is 27017, and you can also specify an unused port at startup.

Start by looking at the port number to see if MongoDB is started.

  1. [root @localhost  data]#  Netstat -lanp | grep  "27017"    
  2. Tcp        0       0  0.0. 0.0: 27017                0.0. 0.0:*                    listen      1573/mongod            
  3. Unix 2 [ACC] STREAM LISTENING 5874 1573/mongod/tmp/mongodb-27017.sock

As you can see, it started successfully and now accesses the database using the MONGO client.

    1. [Root@localhost bin]# cd/usr/local/mongodb/bin/
    2. [Root@localhost bin]#./mongo
    3. MongoDB Shell version: 1.8. 1
    4. Connecting To:test
    5. >

This step indicates that the installation is successful.

5. Additional work.

Note that the above we started MongoDB are manually use Mongod to start, so after shutting down the computer, the next time it did not start, so it has to be started manually, so in order to avoid this tedious work, you can put Mongod into the service from the startup item, In this way, when the computer opens the Mongod service is started.

To edit the/etc/rc.local, add the following code and save it.

    1. #add MONGONDB Service
    2. rm-rf/data/mongodb_data/* &&/usr/local/mongodb/bin/mongod--dbpath=/data/mongodb_data/--logpath=/data/ Mongodb_log/mongodb.log--logappend&

We restart the computer to see if MongoDB is started, restart can be directly using the MONGO command login, the final discovery can be successful.

Also, we use the MONGO command to log in to MongoDB and go to the directory where the MONGO command is located and execute./mongo, is that a bit of a problem? Therefore, we can simplify this by copy the command file to/usr/bin so that the MONGO command can be used in any directory.

    1. [Root@localhost bin]# ls
    2. Bsondump dbbak MONGO Mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongost At
    3. [Root@localhost bin]# CP mongo/usr/bin/

Go to any directory try the MONGO command:

    1. [Root@localhost bin]# CD/
    2. [Root@localhost/]# MONGO
    3. MongoDB Shell version: 1.8. 1
    4. Connecting To:test
    5. >

You can see that the login was successful, which means we can use the MONGO command just like the LS command.

Original address: http://www.linuxidc.com/Linux/2011-05/36309.htm

Installation and startup under MongoDB Linux (RPM)

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.