Install and configure MongoDB in Windows, mongodbwindows

Source: Internet
Author: User
Tags create mongodb install mongodb

Install and configure MongoDB in Windows, mongodbwindows
MongoDB Installation

1. first go to the official website (http://www.mongodb.org/downloads) to download the appropriate installation package, the latest version is 2.6
The installation package is in the zip and msi formats. We recommend that you download the zip format. The msi is actually decompressed, and the installation path is not selected during installation. The default installation path is C: \ Program Files \ MongoDB 2.6 Standard Directory, select a 32-bit or 64-bit directory based on your system

My computer is a 64-bit win8 system. Download the 64-bit zip package and decompress it to the D: \ MongoDB directory.

Create the database Directory D: \ MongoDB \ data. Then open the command line window and switch to the D: \ MongoDB \ bin directory to execute the following command:

Here, -- dbpath specifies the database storage directory. Note that there are two "-"

mongod --dbpath D:\MongoDB\data

This is a command line window that prints some startup information. The last line shows the following information, indicating that the startup is successful.

2014-04-23T10:38:48.391+0800 [initandlisten] waiting for connections on port 27017

Enter http: // localhost: 27017/in the browser.

It looks like you are trying to access MongoDB over HTTP on the native driver port.
The details are as follows:

By now, mongodb has been installed, which is much simpler than imagined.

Install MongoDB as a Windows Service

To install mongodb as a windows service, you only need to add -- install after the command line executed above.

mongod --dbpath D:\MongoDB\data --install

According to the normal story, the service should be installed successfully, but unfortunately, the following prompt appears:

--install has to be used with --logpath

As prompted, We need to specify the log directory, So we create the log directory D: \ MongoDB \ logs and then re-execute the command

mongod --dbpath D:\MongoDB\data --logpath=D:\MongoDB\logs\mongodb.log --logappend

However, the prompt shows that the Log Path is still not specified. After several attempts, we find that this is a bug in version 2.6 and will fix it in the next version. Then we have two options: one is to use the previous version 2.4.9, another option is to install the service successfully with version 2.4.9 and then upgrade it to version 2.6? Directly replace the 2.4.9 file with version 2.6). Do we have other options? Of course, the answer is yes. Use SC command to create a service and Use net start to start the service.

sc create MongoDB binPath= "D:\MongoDB\bin\mongod.exe --service --dbpath D:\MongoDB\data --logpath=D:\MongoDB\logs\mongodb.log  --logappend"
net start MongoDB

MongoDB configuration file

Unfortunately, there is no default configuration file in the officially downloaded installation package. To use the configuration file, you can only create one by yourself. In addition, we recommend that you use the configuration file to manage MongoDB configurations, you can use configuration files to configure database files, log files, and other configurations at a glance.

Decompress the installation package to D: \ MongoDB.

Create Database Directory D: \ MongoDB \ data

Create a log directory D: \ MongoDB \ logs

Create the configuration file directory D: \ MongoDB \ etc

Create the configuration file D: \ MongoDB \ etc \ mongodb. conf

Dbpath = D: \ MongoDB \ data # Database path logpath = D: \ MongoDB \ logs \ mongodb. log # log output file path logappend = true # The Error log adopts the append mode. After this option is configured, mongodb logs will be appended to the existing log files, instead of creating a new file journal = true # enable log files, quiet = true by default # This option can filter out useless log information, if debugging is required, set it to falseport = 27017 # The default port number is 27017.

Here only a few common items are specified, for more detailed configuration, please refer to the official documentation http://docs.mongodb.org/manual/reference/configuration-options/

Note: The preceding directories are created by the blogger. The official website does not regulate the path of the configuration file, which is determined based on your preferences.

After the configuration file and related directories are created, start MongoDB using the following method:

  • Normal start
    mongod --config D:\MongoDB\etc\mongodb.conf
  • Install as a Windows Service
    Note: The 2.6 version cannot be installed successfully in win7 or win8 64-bit versions, but is not tested in other systems.
    mongod --config D:\MongoDB\etc\mongodb.conf --install
  • Use SC to install Windows Services
    sc create MongoDB binPath= "D:\MongoDB\bin\mongod.exe --service --config=D:\MongoDB\etc\mongodb.conf"

     

Note that after a log file is specified, the log will be output to the specified log file no matter whether it is specified in the configuration file or in the command line, no log output is displayed on the command line interface.

 

Note:

Version 2.6 cannot install windows service BUG link https://jira.mongodb.org/browse/SERVER-13515

Official website of MongoDB: http://www.mongodb.org/

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.