MongoDB in Windows Server installation deployment and remote connection MongoDB

Source: Internet
Author: User
Tags auth mongodb like

(. \ means that you need to show trust under Windows PowerShell on the server to perform this command before it will be executed, or you can remove it if you use it on your computer.)

On-premises use does not require permission to turn on the security mode on the server, so you need to have the original command plus--auth (user name and password when connecting) to enable permissions.

Now that you need a username and password, you must first set it up in non-secure mode before you turn on Safe mode.

1. Download MongoDB can be downloaded in the official website to adapt to their own system version I'm here with windows2008 64-bit https://www.mongodb.org/downloads.

2. Install the download of MongoDB like software by default is installed in the C:\Program FILES\MONGODB installation location When you can install the choice.

3. Enable non-secure mode to create the admin account: (i installed in the D disk, the path according to their actual situation to modify)

1. Open Windows PowerShell (equivalent to the cmd we use locally) first open to the installed directory with CD D:\mongodb\bin

Perform a post-typing command. \mongod.exe--dbpath D:\mongodb\data--logpath=d:\mongodb\logs\mongodb.log--logappend

--dbpath D:\mongodb\data is a folder to store data (you can specify, I am here in MongoDB built a folder called data)

--logpath=d:\mongodb\logs\mongodb.log is stored in the log (if the command is wrong you should not have a folder Logs folder and a file Mongodb.log)

--logappend logs are logged in an additional way, and if this parameter is not added, the log file is rewritten each time it is started

2. Reopen a command window (please do not close the first one) also open the installation directory CD D:\mongodb\bin

Perform a post-typing command. \mongo you will see the default connection to test, execute Db.createuser ({"User": "UserName", "pwd": "Userpwd", "CustomData": {employeeid:12345} , "Roles": [{role: "Clusteradmin", DB: "admin"},{role: "Readanydatabase", DB: "admin"}, "ReadWrite"]},{w: "Majority" , wtimeout:5000})

For an explanation of the above command:

User document Field Description

User field, the name of the new user;
PWD field, user's password;
Cusomdata field, for any content, for example, can be introduced to the user's full name;
Roles field, specify the user's role, you can use an empty array to set a null role for the new user;
In the Roles field, you can specify built-in roles and user-defined roles.

Database role roles:https://docs.mongodb.org/manual/reference/built-in-roles/#built-in-roles

Writeconcern Documentation (English is not good does not understand translation official oneself see https://docs.mongodb.org/manual/reference/write-concern/)

4. To this account has been created to complete can enable Safe mode to turn off the original command window to reopen the same CD D:\mongodb\bin

Perform a post-typing command. \mongod.exe--dbpath D:\mongodb\data--logpath=d:\mongodb\logs\mongodb.log--logappend--auth--install

--auth means boot Safe mode

After you start Safe mode, if there is no authentication, the operation will prompt the error not authorized

1. Use Admin (opens a data collection with the Create LOGIN permission)

2. Db.auth ("UserName", "Userpwd") the user name password is correct, will show 1 indicates success, you can operate. You can also add rights accounts to other data sets.

--install indicates that creating a service in Windows does not have to open a command window and not have to restart the server after you have to re-use the command to open MongoDB can set the service to start automatically.

After setting up the first start service can go to the service to find MongoDB start it can also use the command to start the net start MongoDB, stop the corresponding is the net stop MongoDB

5. Remote connection to the server MongoDB

1.CD to the installed directory

2. Execution MONGO 192.168.0.1:27017/admin-u wuyubing-p wyb123456

The server address depends on the actual situation.

may not be connected because the server default port number 27017 is not open, you need to open the port number settings as follows:

Control Panel system security Windows Firewall Advanced Settings Inbound rules new rule port TCP specific port input 27017 allow links to follow the default settings or know that people can do their own other settings to determine the name of the rule to complete.

MongoDB in Windows Server installation deployment and remote connection 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.