Windows MONGO replica set configuration one main one from one quorum

Source: Internet
Author: User
Tags auth base64 mongodb file permissions

Good memory is inferior to bad blog, record, need to use directly later.

This article configured the three MongoDB in the same machine, should be put three machines, but the resources are limited, a machine will be used, the configuration of a copy of the lumped ratio is not configured better.

This article configures the use of the database version: 3.2.6 64-bit version

1, copy three points MongoDB to the server, the directory is: Mongo_master// 27311 The main library is actually in the database runtime, which instance is the main library is not necessarily, but in order to distinguish the folder, for the time being so named
Mongo_slaver// 27321 from the library
Mongo_arbiter// 27331 Quorum server

2, the main library configuration
2.1, open cmd, enter the Mater\bin directory:
CD E:\mongo\mongo_master\bin

2.2. Execute the following command to create the database service:
Mongod--replset shard1--port 27311--logpath "E:\mongo\mongo_master\data\log\MongoDB.log--logappend"--dbpath Mongo\mongo_master\data\db "--servicename" Mongo_master "--servicedisplayname" Mongo_master "--install"

3, from the library configuration
3.1, into the Mongo-slaver\bin directory:
CD E:\mongo\mongo_slaver\bin

3.2. Execute the following command and create the database service:
Mongod--replset shard1--port 27321--logpath "E:\mongo\mongo_slaver\data\log\MongoDB.log--logappend"--dbpath Mongo\mongo_slaver\data\db "--servicename" Mongo_slaver "--servicedisplayname" Mongo_slaver "--install"

4. Quorum server Configuration
4.1, into the Mongo_arbiter\bin directory:
CD E:\mongo\mongo_arbiter\bin

4.2. Execute the following command and create the database service:
Mongod--replset shard1--port 27331--logpath "E:\mongo\mongo_arbiter\data\log\MongoDB.log--logappend"--dbpath Mongo\mongo_arbiter\data\db "--servicename" Mongo_arbiter "--servicedisplayname" Mongo_arbiter "--install"

5, start the database, configure the main library, from the library, the Quorum library:
config={_id: ' Shard1 ', members:[{_id:0,host: ' '},{_id:1,host: ' '},{_id:3,host: ' ', Arbiteronly:true}]}
Rs.initiate (config)

5.1, Description: _id value "Shard1" is the configuration name, multiple use, need to unify. Members are the MONGO instances, and the arbiteronly:true in the third member indicates that the member is the quorum server. Rs.initiate (config) enables this configuration.
5.2. View replica Set configuration: Rs.status ()
5.3, change the replica set configuration:
var config = rs.config ();
Config.members[0].host = ' '
Rs.reconfig (config)
5.4. If there is a "not master and Slaveok=false" hint error, please enter the command:
Rs.slaveok ()

6. Configure users in the main library:

6.1. Add Admin user to admin database

Use admin db.createuser ({User: "admin", pwd: "admin", roles:[{role: "Clusteradmin", DB: "admin"},{role: " Dbadminanydatabase ", DB:" admin "},{role:" Useradminanydatabase ", DB:" admin "},{role:" Readwriteanydatabase ", DB:" Admin "}]})

6.2. Add SA user to mydb database

Use MyDB db.createuser ({User: ' sa ', pwd: ' sa ', roles:[{role: ' Dbowner ', db: ' MyDB '}]})

7. Create keyfile Files
7.1, create the folder key in E:\mongo\mongo_master, create the file key in the folder, the content request is as follows:
(1) At least 6 characters, less than 1024 bytes
(2) When the certificate does not take into account the blank characters in the file
(3) The contents of the KeyFile file connected to the replica set must be the same as that of the MONGOs
(4) must be Base64 encoding, but cannot have equal sign
(5) file permissions must be x00, that is, you cannot assign any permissions to group members and other members

Windows can build a TXT file, copy a section of Base64 encoded content, delete the file suffix name. Copy the key folder together with the key file to three MONGO directories.

8, modify the main library, from the library to start the authentication method:
8.1, stop the main library service, modify the main Library start service (add startup parameter--auth):
CD E:\mongo\mongo_master\bin
Mongod--replset shard1--port 27311--auth "--keyfile" E:\mongo\mongo_master\key\key Data\log\mongodb.log "--logappend--dbpath" E:\mongo\mongo_master\data\db "--servicename"-- Servicedisplayname "Mongo_master"--reinstall

8.2, stop from the library service, modify the start service from the library
CD E:\mongo\mongo_slaver\bin
Mongod--replset shard1--port 27321--auth "--keyfile" E:\mongo\mongo_master\key\key Data\log\mongodb.log "--logappend--dbpath" E:\mongo\mongo_slaver\data\db "--servicename"-- Servicedisplayname "Mongo_slaver"--reinstall

8.3, stop the Quorum library service, modify the quorum library start service
CD E:\mongo\mongo_arbiter\bin

Mongod--replset shard1--port 27331--auth "--keyfile" E:\mongo\mongo_master\key\key \data\log\mongodb.log "--logappend--dbpath" E:\mongo\mongo_arbiter\data\db "--servicename"-- Servicedisplayname "Mongo_arbiter"--reinstall

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: 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.