Linux Installation MongoDB

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

Recommended to go to the official website to download the latest version, currently the latest version 3.0.

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 Mongosta T

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 directory where MongoDB stores data files and log files, you need to create them manually:

Mkdir/data/mongodb_data

Mkdir/data/mongodb_log

Touch/data/mongodb_log/mongodb.log

    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-2 7017. 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. ( You can also write a script and then run it automatically )

    1. #add MONGONDB Service
    2. /usr/local/mongodb/bin/mongod--dbpath=/data/mongodb_data/--logpath=/data/mongodb_log/mongodb.log--logappend &
Boot from startup script start_mongodb.sh Cd/usr/local/mongodb-linux-i686-2.2.1/bin//specific version specific changes./mongod--dbpath=/data/mongodb_data/ --logpath=/data/mongodb_log/mongodb.log--logappend& Path is consistent with the datapath,logpath you set MongoDB

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 Mongosta T
    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.

Linux Installation MongoDB

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.