[MongoDB] Build a Mongo database replica set (similar to a cluster) on the windows platform and mongodbmongo

Source: Internet
Author: User
Tags md5 hash

[MongoDB] Build a Mongo database replica set (similar to a cluster) on the windows platform and mongodbmongo

Replica Sets (Replica set) is a new feature in mongodDB1.6, which enables automatic failover and Automatic Repair of node members. The data in each database is completely consistent, this greatly reduces the risk of spof.

【]


It indicates the architecture of the Replica Set with three nodes. This figure is from the book Mongodb Management and Development essentials written by Hongwan. It can be seen that the structure is similar to a cluster, but it can be used as a cluster. Because it does play the same role as the cluster implementation.

1. Deploy Replica Sets.

Next we will show how to deploy the Replica Sets of three nodes on one server.



2. Start the Replica Service

Open three command windows, and then execute the following three statements.

mongod.exe  --replSet rs1 --keyFile "D:\Program Files\mongodb\data\replica\key\r0" --port 28010 --dbpath "D:\Program Files\mongodb\data\replica\data\r0" --logpath "D:\Program Files\mongodb\data\replica\log\r0.log" --logappendmongod.exe  --replSet rs1 --keyFile "D:\Program Files\mongodb\data\replica\key\r1" --port 28011 --dbpath "D:\Program Files\mongodb\data\replica\data\r1" --logpath "D:\Program Files\mongodb\data\replica\log\r1.log" --logappendcd /d D:\Program Files\mongodb\binmongod.exe  --replSet rs1 --keyFile "D:\Program Files\mongodb\data\replica\key\r2" --port 28012 --dbpath "D:\Program Files\mongodb\data\replica\data\r2" --logpath "D:\Program Files\mongodb\data\replica\log\r2.log" --logappend




3. log on to the client and initialize the Replica Sets Environment






How to Create a mongodb database with a user name and password

I'm so angry. Let's just put it down. Below is a part of my notes on mongodb.
By default, mongoDB user authentication is disabled.
Modify the/etc/cmdd. conf file. By default, any client in mongoDB can connect to port 27017 without authentication. By default, there is no administrator account. By modifying this configuration file, you can change it to permission authentication during login.
If you want to create a user for a database in mongoDB, you must first enter the database and then use the addUser command. You can also set the user to read-only (db. addUser ("jack", "jack", true), and the third parameter to indicate whether the user is a "read-only user ").

To use a super administrator, you must first connect to the admin database and log on to the administrator account, and then connect to other databases to exercise administrator privileges.

User information storage and authentication process

Similarly, MySQL saves system user information in the mysql. user table. MongoDB also saves the username and pwd of the system user in the admin. system. users collection. Pwd = md5 (username + ": mongo:" + real_password ). This is not a problem. Username And: mongo: It is equivalent to adding a salt value to the original password. Even if attackers obtain the md5 hash stored in the database, they cannot simply find the original password from the rainbow table.

Common permission management commands

1. # enter the database admin

Use admin

2. # Add or modify user passwords

Db. addUser ('name', 'pwd ')

3. # view the user list

Db. system. users. find ()

4. # User Authentication

Db. auth ('name', 'pwd ')
If this one returns 1, the authentication is successful. Only after the authentication is successful can the database be operated.

5. # delete a user

Db. removeUser ('name ')

6. # view all users

Show users

7. # view all databases

Show dbs

8. # view all collections

Show collections

9. # view the status of each collection

Db. printCollectionStats ()

10. # view master-slave replication status

Db. printReplicationInfo ()

A client tool used to connect to the mongodb database.

Jmongobroue, MonvoVUE, and windows command lines can also be used.

However, it is best to use the next enhanced cmd Tool, such as powercmd, because it cannot be displayed in the command line, and it is not necessarily displayed in the client tool. If you want to learn mongo, you 'd better learn to knock on commands instead of "click it"

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.