MongoDB environment deployment

Source: Internet
Author: User
Tags mongodb 32 bit mongodb client mongodb monitoring mongodb version centos server

Http://www.cnblogs.com/yoolonet/archive/2011/08/27/2155701.html

A series of articles about MongoDB recently used MongoDB as a data storage system to record their own applications and problems in actual development. I hope this will be helpful to my friends who are getting started with MongoDB.

In brief, MongoDB is a type of nosql database. MongoDB is a good choice for Internet applications with large data volumes, high concurrency, and weak things.

Its design philosophy is that "databases are specializing-the" one size fits all "approach no longer applies." Here I will talk little about it.

There are a lot of introductions to MongoDB on the Internet, and the information is better than what I said. Here I will only talk about my applications in the project. After all, practice is the standard for testing truth.

In the entire series, the Data Structure Stored is

{"Time": "time", "userid": "User ID", "sessionid": "sessionid", "ip": "user access IP", "title ": "Access webpage title", "url": "Access webpage URL "}
In these articles, each example is explained using the client shell and C # driver.
Driver download on the official website (http://www.mongodb.org/display/DOCS/CSharp+Language+Center)

Part I environment deployment
Section 1st: deployment of the MongoDB Environment
Section II basic document operations
Section 1st: naming rules
Section 2nd: Basic Data Types
Section 3rd: Principles of insert and batch insert
Section 4th: Find Query
Section 5th: Query conditions, $ where query, or query, $ not, nested Query
Section 6th: Regular Expression Query
Section 7th: upsert, $ set, $ Inc, $ Puch, $ addtoset, $ each, $ ne
Section 8th: findandmodify
Section 9th: usage of cursors
Section 10th: Aggregate Query, Count, distinct, Group
Section 11th: mapreduce
Section 12th: Index
Part III advanced document operations
Section 1st: gridfs
Section 2nd: DB. Eval
Section 3rd: storing Javascript
Section 4th: dbref database reference
Part IV MANAGEMENT
Section 1st: Start and Stop MongoDB in Linux and Windows
Section 2nd: Monitoring
Section 3rd: Backup and repair
Section 4th: master-slave Replication
Section 5th: multipart
Section V comprehensive
Section 1st: How shell commands work
Section 2nd: exceptions and solutions encountered during actual development
Section 3rd: Basic Framework Design Based on MongoDB C # Driver (with source code)

Author: yoolo

Source: http://www.cnblogs.com/yoolonet

The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent and provide the original article connection clearly on the article page.

Section 1 Deployment

The deployment of the MongoDB environment is simple. People who have already used it will certainly share the same idea with me. First download the corresponding version (http://www.mongodb.org/downloads) on the official website, to distinguish whether your own is 32-bit or 64-bit.
MongoDB version. The even version is the stable version and the odd version is the development version. For example, stable version (1.2.0, 1.2.1, 1.2.2, etc.) is started with 1.2, and development version (1.3.0, 1.3.1, 1.3.2, etc.) Starting with 1.3 ).

My local development environment is win7 (32bit, dual-core), the company's development environment centos (a Linux version, 64bit, 4 CPUs)

 

In Windows

1: Decompress the downloaded compressed file. (I am on E: \ nosql \ MongoDB)
2: create a directory to store database files. The default value is/data/DB/(c: \ data \ dB in Windows ).
3: Go to the MongoDB decompressed directory (I am in E: \ nosql \ MongoDB ),
> Cd E: \ nosql \ MongoDB \ bin
> Mongod help can view some MongoDB parameters. Below are the three common parameters I listed: DB storage path, log storage path, and log storage method.

-- Dbpath Arg directory for datafiles
-- Logpath Arg log file to send write to instead of stdout-has to be
A file, not directory

-- Logappend append to logpath instead of over-Writing

> Mongod -- dbpath E: \ nosql \ MongoDB \ data -- logpath = E: \ nosql \ MongoDB \ log \ MongoDB. log -- logappend
All output going to: e: \ nosql \ MongoDB \ log \ MongoDB. log will be displayed in the CMD window.

Enter http: // localhost: 27017/in the browser and you will see the following prompt:
You are trying to access MongoDB on the native driver port. For HTTP diagnostic access, add 1000 to the port number

In this way, the MongoDB Database Service has been successfully started.

Enter http: // localhost: 28017/in the browser, which is a monitoring interface of the MongoDB system. If you specify the -- Port port number, you must use a port number greater than 1000 to access MongoDB.
Monitoring Interface.

4: open another cmd window and start a MongoDB client.
> Cd E: \ nosql \ MongoDB \ bin
> Mongo
MongoDB shell version: 1.8.3-RC0
Connecting to: Test
>

> Show DBS // view the system database. These are my local DBS.
Admin (empty)
Local (empty)
Loginlog 0.125 GB
Logintest 0.0625 GB
Mymongodb 0.03125 GB
Test Db 0.999755859375 GB
> Help // view the help information of the currently executed role

 

Deploy MongoDB in centos. I connected to the company's centos server through securecrt. It has the same deployment operations on Windows.
Download the corresponding official version and decompress it to the corresponding directory. My directory is/root/soft, listing extracted files

[Root @ app-vwsc-01 soft] # ls
Mongodb-linux-x86_64-1.8.2
Mongodb-linux-x86_64-1.8.2.tar nagios-nrpe_2.8.1.tar.gz
Nagios-plugins-1.4.15 nagios-plugins-1.4.15.tar.gz nrpe-2.8.1
[Root @ app-vwsc-01 soft] # cd mongodb-linux-x86_64-1.8.2/bin
[Root @ app-vwsc-01 bin] # ls
Bsondump Mongo mongod mongodump unzip Export Program Files submit import mongorestore mongos unzip sniff unzip stat
[Root @ app-vwsc-01 bin] #. /mongod -- dbpath/root/mongodbpro/data/DB -- logpath/root/mongodbpro/data/log/MongoDB. log -- logappend // start the mongod Server
All output going to:/root/mongodbpro/data/log/MongoDB. Log // at this time, the MongoDB service has been started.

Start a MongoDB Client
[Root @ app-vwsc-01 bin] #./Mongo
MongoDB shell version: 1.8.2
Connecting to: Test
> Show DBS // view the current database

 

Currently, all the deployment has been completed on win7 and centos, but pay attention to the following points:

1: After we start the MongoDB service, all MongoDB logs are written to the MongoDB. Log File in win7. (This file is customized by me)
** Note: When Using MongoDB 32 bit, you are limited to about 2 gigabytes of data
** See http://blog.mongodb.org/post/137788967/32-bit-limitations
** With -- dur, the limit is lower

Sat Aug 27 16:48:17 [initandlisten] DB version v1.8.3-RC0, pdfile version 4.5
Sat Aug 27 16:48:17 [initandlisten] git version: 81147c1ca4cc10d9a81a0a2afdf364ab1ca8867d
Sat Aug 27 16:48:17 [initandlisten] Build sys info: Windows (5, 1, 2600, 2, 'service pack 3') boost_lib_version = listen 35
Sat Aug 27 16:48:18 [initandlisten] waiting for connectionon port 27017
Sat Aug 27 16:48:18 [websvr] Web Admin Interface listening on port 28017
Sat Aug 27 16:49:02 [initandlisten] connection accepted from 127.0.0.1: 1398 #1
Sat Aug 27 17:04:10 [conn1] terminating, shutdown command canceled ed
Sat Aug 27 17:04:10 dbexit: shutdown called
Sat Aug 27 17:04:10 [conn1] shutdown: going to close listening sockets...
Sat Aug 27 17:04:10 [conn1] Closing listening socket: 188
Sat Aug 27 17:04:10 [conn1] Closing listening socket: 196
Sat Aug 27 17:04:10 [conn1] shutdown: going to flush diaglog...
Sat Aug 27 17:04:10 [conn1] shutdown: going to close sockets...
Sat Aug 27 17:04:10 [conn1] shutdown: Waiting for FS preallocator...
Sat Aug 27 17:04:10 [conn1] shutdown: Closing all files...
Sat Aug 27 17:04:10 closeallfiles () finished
Sat Aug 27 17:04:10 [conn1] shutdown: removing FS lock...
Sat Aug 27 17:04:10 dbexit: really exiting now

In the above warning, it means that in 32-Bit mode, MongoDB can only process 2 GB of data, because I use 32-bit MongoDB and MongoDB uses the memory-mapped file storage engine, if a stable version is used on a 64-bit machine, this warning will not be returned.

We need to develop the habit of viewing logs, which is useful for MongoDB monitoring.

2: Disable the MongoDB service. This method is provided first and will be mentioned later.
> Use admin // switch to Admin
Switched to DB Admin
> DB. shutdownserver () // execute shutdownserver ()
Sat Aug 27 18:02:57 dbclientcursor: init call () failed
Sat Aug 27 18:02:57 query failed: Admin. $ cmd {shutdown: 1.0} to: 127.0.0.1
Server shocould be down...
Sat Aug 27 18:02:57 trying reconnect to 127.0.0.1
Sat Aug 27 18:02:58 reconnect 127.0.0.1 failed couldn't connect to server 127.0.0.1
Sat Aug 27 18:02:58 error: Error doing query: Unknown shell/collection. JS: 150
> Exit // then exit.

2: Start the CMD window in win7. I suggest using Windows powershell, which is much better than the CMD window.
3: I add "// explanation" after some commands. This is not a command and serves only as one of my explanations.
4: In the next section, I will talk about the basic operations of MongoDB and the selection of the C # driver. I hope you can help me with the problem of writing.

 

For more information, see my previous articles in the MongoDB series.

Author: yoolo

Source: http://www.cnblogs.com/yoolonet/archive/2011/08/27/2155701.html

The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent and provide the original article connection clearly on the article page.

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.