Windows10 mongodb standalone cluster configuration
Version: mongodb-win32-x86_64-2008plus-ssl-4.0.4
The steps of downloading and installing mongodb are omitted, just click one step, and the single mongodb is just fine. Pay attention to remove the check of the Install MongoDB Compass in the last step. If you feel that your network speed is fast enough, you can ignore this sentence.
1. Create a data folder for three nodes
2. Start
Start mongo1
mongod --port 1111 --dbpath "D:\work\mongodb2\mongodb\data\db1" --logpath "D:\work\mongodb2\mongodb\data\log1\MongoDB.log" --replSet jsec --logappend
Start mongo2
mongod --port 2222 --dbpath "D:\work\mongodb2\mongodb\data\db2" --logpath "D:\work\mongodb2\mongodb\data\log2\MongoDB.log" --replSet jsec --logappend
Start mongo3
mongod --port 3333 --dbpath "D:\work\mongodb2\mongodb\data\db3" --logpath "D:\work\mongodb2\mongodb\data\log3\MongoDB.log" --replSet jsec --logappend
2. Connect one of the mongo as the master node
mongo localhost:1111
Create a configuration file, list each member in the configuration file, and know the existence of each other (the second startup does not need to be configured):
use jsec
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") at the start of each server. This name must be consistent.
Send this configuration file to one of the replica set members, and then the member will be responsible for distributing 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 replica set cannot be initialized:
rs.initiate(config_jsec)
You can now view the status information:
rs.status()
Now you can connect in a cluster
Click Test Connection