The first part of the basic chapter II install MongoDB

Source: Internet
Author: User
Tags install mongodb mongodb client mongodb server

Statement: The article is mainly from the "MongoDB Real Combat" a book, the main want to learn MongoDB knowledge through the book, deepen understanding, so write in their blog, as recorded in the last chapter, there will be a collection of MongoDB database application Java EE Web application.

1. Download

MongoDB's official Download station is http://www.mongodb.org/downloads can download the latest installer on the download page, it can be seen that the operating system support is very comprehensive, such as OS X, Linux, Windows, Solaris is supported, and each has its own 32-bit and 64-bit version of the 2.4.12 version.

The installation methods for Windows and Linux editions are described below.


2. Installation of Windows platform

Step one: Download MongoDB

Url:http://www.mongodb.org/dr//fastdl.mongodb.org/win32/mongodb-win32-i386-2.6.6.zip/download

Description: In this demo installation download using the Windows XP 32-bit environment, it is recommended that you do not use a 32-bit environment.

Step two: Set up the MONGODB program storage directory

Create a new MongoDB folder under the C: \ Disk directory, extract MongoDB to the directory, and then create a new subdirectory in the directory data and logs directory. The data directory is used to hold the MongoDB database, and the logs directory user holds the MongoDB log.

Step Three: Configure environment variables

This step is mainly for the convenience of the command line, you can add the C:\mongodb\bin to the system environment variable path.

Step four: Start the MongoDB service.

Open the CMD console and start the MongoDB service by doing the following:



Description: The default listening port for MongoDB server is 27017

Step five: Install Windows services

Perform the following actions:


At this point, you can view the services for MongoDB in Windows Services, as shown in:



Start the MongoDB service by entering the following command in the CMD console, or start directly in the Windows service


Step Six: Client connection verification

Open a cmd console, enter MONGO, if prompted below, then you can start the MongoDB tour.



Step Seven: View MongoDB logs

View the C:\mongodb\logs\mongodb.log file to view or debug the operation of MongoDB.

This completes the MongoDB installation demo of the Windows platform.

3, installation of Linux platform

3.1. Installation Instructions

System environment: CentOS-6.4 64-bit

Installation software: mongodb-linux-x86_64-2.6.6.tgz

:http://www.mongodb.org/

Upload location:/usr/src/

Installation directory:/usr/local/mongodb

Data location:/var/mongodb/data

Log location:/var/mongodb/logs


3.2. Check if MongoDB is installed

[Email protected] src]# Rpm-qa|grep MongoDB

[[Email protected] src]# service MongoDB status

Mongodb:unrecognized Service


3.3. Installing MongoDB

[Email protected] ~]# CD/USR/SRC

[Email protected] src]# Groupadd MongoDB

[Email protected] src]# useradd mongodb-g MongoDB

[Email protected] src]# TAR-ZXVF mongodb-linux-x86_64-2.6.6.tgz

[Email protected] src]# MV Mongodb-linux-x86_64-2.6.6/usr/local/mongodb

[Email protected] src]# cd/usr/local/

[Email protected] local]# chown-r Mongodb:mongodb MongoDB

[Email protected] local]# CD mongodb/

[Email protected] mongodb]# Mkdir/var/mongodb

[Email protected] mongodb]# Mkdir/var/mongodb/data

[Email protected] mongodb]# Mkdir/var/mongodb/logs

[[Email protected] mongodb]# service iptables stop//Lab environment shut down the firewall

iptables:flushing firewall rules: [OK]

Iptables:setting chains to Policy Accept:filter [OK]

iptables:unloading modules: [OK]


3.4. Configuration

Add CentOS Boot entry

[Email protected] mongodb]# VI +/etc/rc.d/rc.local

Append the MongoDB startup command script to the file:

/usr/local/mongodb/bin/mongod--dbpath=/var/mongodb/data--logpath/var/mongodb/logs/log.log-fork


3.5. Start MongoDB

[Email protected] bin]#/mongod--dbpath=/var/mongodb/data/--logpath/var/mongodb/logs/log.log-fork


3.6. Test MongoDB

[Email protected] bin]#./mongo

MongoDB Shell version:2.6.6

Connecting To:test

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

>

View the list of databases

> Show DBS

Admin (empty)

Local 0.078GB

Switch database

> Use admin

Switched to DB admin

Add User

> Db.adduser ("Xuzheng", "123456", true);

Warning:the ' AddUser ' shell Helper is DEPRECATED. Please use ' createUser ' instead

Successfully added User: {"user": "Xuzheng", "Roles": ["Readanydatabase"]}

Display Status

> Db.stats ();

{

"DB": "admin",

"Collections": 4,

"Objects": 11,

"Avgobjsize": 82.9090909090909,

"DataSize": 912,

"Storagesize": 32768,

"Numextents": 4,

"Indexes": 3,

"Indexsize": 24528,

"FileSize": 67108864,

"Nssizemb": 16,

"Datafileversion": {

"Major": 4,

"Minor": 5

},

"Extentfreelist": {

"num": 0,

"TotalSize": 0

},

"OK": 1

}


Show Current version:

> db.version ();

2.6.6

get the current working database:

> Db.getmongo ();

Connection to 127.0.0.1

Simple Insert Data:

> Db.user.insert ({"Name": "Xuzheng", age:20});

Writeresult ({"ninserted": 1})

View data:

> Db.user.find ();

{"_id": ObjectId ("549d085621fc93b35ccba9a0"), "name": "Xuzheng", "Age": 20}

Note: The above is just a simple demonstration under MongoDB most commonly used basic operations, MongoDB by default, the database listening port is 27017, if you want to remotely connect a non-service, using--port and--host to operate, as shown in:


Of course, the premise is that the remote machine must be installed with MongoDB client tools, also known as MONGO services.

At this point, MongoDB in the Windows platform and the installation of the Linux platform, due to different system environment is inconsistent, so there are some problems in the installation of other platforms, can find a solution from the Internet, not in this presentation.








The first part of the basic chapter II install 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.