Official documentation: https://docs.mongodb.com/manual/replication/
Start parameters:
The mongodb installed through the Linux package manager (for example: yum) will generate a default configuration file: /etc/mongod.conf,
When installing from source, you need to specify a configuration file yourself.
One is the command line parametersmongod --replSet="setname"
The other is to add in the configuration filereplication.replSetName="setname"
After starting all mongodb instances, log in to one of them to set up:
Related official documents: https://docs.mongodb.com/manual/reference/method/js-replication/
s = { _id: <string>, members: [ { _id: <int>, host: <string>,
arbiterOnly: <boolean>, priority: <number> }, ... ],
}
rs.initiate (s) Initialize or call rs.reconfig (s) to reset.
Check the configuration through rs.conf ()