1) Create these directories as below
2) Start the mongod process for each replica.
mongod --bind_ip 192.168.56.1 --port 27020 --replSet rs0 --dbpath D:\MongoDB\Replicaset\data2 --oplogSize 200 --logpath D:\MongoDB\Replicaset\log2\log2.txt
--Bind_ip - is used to accept connections on a particular node. By specifying the IP address with --bind-ip
, you're telling MongoDB to listen for incoming connections on that specific network interface of the node.
--replSet - to indicate the node is part of the replicaSet, but yet to configure command using rs.initiate after the processes from all the nodes started.
--OplogSize - option is used in the mongod
process to specify the size of the oplog (operations log) for a replica set member. The oplog is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases.
3) Connect to Replica 1 and set variable:
>mongosh –port 27019
Store the current configuration of ReplicaSet in a variable and check it is set correctly:
4) Execute rs.initiate(rconfig)
command to start the replica set configuration process.
5) Check the status of ReplicaSet after initialization
>rs.status()
6) Run db.isMaster() command to see node status
Configured a MongoDB ReplicaSet successfully!
No comments:
Post a Comment