MongoDB Learning (v) Linux environment installation MongoDB

Source: Internet
Author: User
Tags create directory iptables

A. Download

Download from http://www.mongodb.org/downloads address: Mongodb-linux-x86_64-2.4.11.tar

Two. Installation

1> Setting up the MongoDB directory
[[email protected] home] #cd/home/apps
attached: Create directory commands under CentOS [[email protected] home]#mkdir-p/home/apps

2> uploading the file Mongodb-linux-x86_64-2.4.11.tar to the/home/apps directory

3> unzip a file
[[email protected] apps] #tar xzf Mongodb-linux-x86_64-2.4.11.tar
folder Rename
[[email protected] apps] #mv mongodb-linux-x86_64-2.4.11 MongoDB

4> Creating directories and Files
[email protected] apps]# mkdir-p mongodb/data/db
[email protected] apps]# mkdir-p mongodb/logs
[email protected] apps]# touch mongodb/logs/mongodb.logs

5> Start Service
[email protected] apps]#./mongodb/bin/mongod-dbpath=/home/apps/mongodb/data/db-logpath=/home/apps/mongodb/ Logs/mongodb.logs
All output going to:/home/apps/mongodb/logs/mongodb.logs

6> The MongoDB service into a random start
[[email protected] apps] #vi/etc/rc.local
Use the VI Editor to open the configuration file and add the following line of code to it
[email protected] Apps]#/home/apps/mongodb/bin/mongod--dbpath/home/apps/mongodb/data/db--port 27017--logpath /home/apps/mongodb/logs/mongodb.logs--logappend


7> Connect MongoDB ( be careful not to close the previous interface and need to reopen a window connection )
[email protected] apps]#/home/apps/mongodb/bin/mongo DBName
MongoDB Shell version:2.4.11
Connecting To:dbname
Welcome to the MongoDB shell.
for interactive help, type ' help '.
for more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the Support group
Http://groups.google.com/group/mongodb-user

The above interface indicates a successful connection.

three. LAN connection MongoDB

In accordance with the above operation, MongoDB installed under Linux has completed, the local connection MongoDB has also been successful. Then we have to consider another problem, how LAN to connect MongoDB? How do Windows machines in a local area network connect to MongoDB in a Linux machine? The practice is as simple as that:

[Email protected] Apps]#./mongodb/bin/mongo 192.168.5.100/dbname

But it's important to note here that we need to open MongoDB's port number on CentOS, and then we'll talk about how to open the specified port on CentOS. First, check to see if this port is occupied:

[[email protected] apps] #netstat-ANP |grep 27017

[[email  Protected] apps]# vi /etc/sysconfig/iptables , add the following to the file:

# Firewall configuration written by System-config-securitylevel
# Manual Customization of this file are not recommended.
:i Nput Accept [0:0]
:forward accept [0:0]
:output ACCEPT [0:0]
:rh-firewall-1-input-[0:0]

commit

Then restart the service.

[[email protected] apps] #service iptables restart

At this point, you can begin to access MongoDB deployed on CentOS via the local area network.

Enter http://192.168.5.100:27017/in the local browser, if the following appears:

You is trying to access MongoDB on the native driver port. For HTTP diagnostic access, add the port number
Indicates a successful connection.

Four. Problems encountered during installation

1. error:couldn ' t connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91

Workaround: Execute the following statement

[[email protected] MongoDB]#./bin/mongod-dbpath=data/db

2. Restart Firewall times error:

Workaround: Add a commit at the end.

MongoDB Learning (v) Linux environment 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.