Installation and start-up under MongoDB CentOS

Source: Internet
Author: User
Tags mongodb mongodb server

1. Download mongodb:http://download.csdn.net/detail/swazer_z/9314681 can also go to the official website to download the latest installation package: Https://www.mongodb.org/downloads

2. Extract files to a directory, and then rename: [Root@localhost src]# tar-xzvf mongodb-linux-x86_64-3.0.7.tgz [root@localhost src]# MV Mongodb-li nux-x86_64-3.0.7/usr/local/mongodb/

3. View the file after installation: [Root@localhost src]# cd/usr/local/mongodb/[root@localhost mongodb]# ls bin gnu-agpl-3.0 README third-party-notices [root@localhost mongodb]# cd bin/[root@localhost bin]# ls bsondump dbbak MONGO mongod mo Ngodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongostat
Bin Mongod is the MongoDB server process, MONGO is its client, other commands for MongoDB other uses such as MongoDB file export.

4. Start MongoDB.

To first set up the MongoDB to store data files and log files in the directory, which is based on/data: [root@localhost etc]# cd/data/[root@localhost data]# LS DB log

Use Mongod to start mongodb under bin under the MongoDB installation directory./mongod--dbpath=/data/db/--logpath=/data/log/mongodb.log

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

   First See if MongoDB is started by looking at the port number. [root@localhost data]# netstat -lanp | grep  "27017"    tcp         0      0 0.0.0.0:27017                0.0.0.0:*                    LISTEN       1573/mongod             Unix  2      [ acc ]     stream      LISTENING     5874   1573/mongod          /tmp/mongodb-27017.sock  

As you can see, the success has started and now access the database using the MONGO client. [Root@localhost bin]# cd/usr/local/mongodb/bin/[root@localhost bin]#./mongo MongoDB Shell version:2.6.11 Cting to:test >

This step shows that the installation has been successful.

5. Additional work.

Note that the above we start MongoDB are manually using Mongod to start, so shut down the computer, the next time it does not start, so it has to manually start, so in order to avoid this tedious work, you can put Mongod into the service from the startup item, This allows the computer to open the Mongod service also started.

Edit/etc/rc.local, add the following code and save it. #add mongondb service rm-rf/data/db/* &&/usr/local/mongodb/bin/mongod--dbpath=/data/db/--logpath=/data/log /mongodb.log--logappend&

We restart the computer to see if the MongoDB is started, restart can be directly using the MONGO command login, and finally found that can be successful.

In addition, we use the MONGO command to log in MongoDB and go to the directory where the MONGO command is being executed./mongo, this is not a bit of a hassle. So, we can simplify this, copy the command file to/usr/bin, so that you can use the MONGO command in any directory.  [root@localhost bin]# ls bsondump dbbak MONGO mongod mongodump mongoexport mongofiles mongoimport MONGOs Mongosniff Mongostat [root@localhost bin]# CP mongo/usr/bin/

Go to any directory try the MONGO command: [root@localhost bin]# CD/root@localhost/]# MONGO MongoDB Shell version:1.8.1 connecting to: Test >

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

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.