Windows10 mongodb stand-alone cluster configuration
Version: mongodb-win32-x86_64-2008plus-ssl-4.1.4
The steps of downloading and installing mongodb are omitted, just click the step, and the stand-alone mongodb is just fine. Pay attention to remove the Install MongoDB Compass tick in the last step. If you think your internet speed is fast enough, you can ignore this sentence.
1. Create a data folder for the three nodes, (remember, you must create a new clean, do not copy)
2. Start mongo node 1
mongod --port 1111 --dbpath "D:\work\mongodb2\mongodb\data\db1"
--logpath "D:\work\mongodb2\mongodb\data\log1\MongoDB.log"
--replSet jsec --logappend
2. Start mongo node 2
mongod --port 2222 --dbpath "D:\work\mongodb2\mongodb\data\db2"
--logpath "D:\work\mongodb2\mongodb\data\log2\MongoDB.log"
--replSet jsec --logappend
3. Start mongo node 3
mongod --port 3333 --dbpath "D:\work\mongodb2\mongodb\data\db3"
--logpath "D:\work\mongodb2\mongodb\data\log3\MongoDB.log"
--replSet jsec --logappend
4. Connect to one of the mongo as the master node
mongo localhost:1111
5. Create a configuration file, list each member in the configuration file, know each other's existence (the second startup does not need to configure):
(1) use jsec
(2) config_jsec={"_id":"jsec","members":[{"_id":0,host:"127.0.0.1:1111"},
{"_id":1,host:"127.0.0.1:2222"},{"_id":2,host:"127.0.0.1:3333"}]}
Note: The "_id" value is the name of the replica set ("jsec") when each server starts, and this name must be consistent.
Send this configuration file to one of the replica set members, and then that member will be responsible for disseminating the configuration file to other members. If there is already a member with data in the replica set, then the configuration object must be sent to this member with data. If there is more than one member with data, then the next step to initialize the replica set cannot be performed.
6. Initialize the replica set:
rs.initiate(config_jsec)
7. View status information:
rs.status()
8. Open the client tool and use the cluster to connect
9. Click Test Connection