single-machine switch to replica set method step
1: Back up the database and shut down the current database
/u03/mongodb/bin/mongodump-d Configuration-o/u02/dump/
Use admin db.shutdownserver ();
2: Start two data nodes on both machines as follows:
/u01/mongo/bin/mongod--dbpath=/u01/mongodb/data/--logpath=/u01/mongodb/logs/node1.log--replSet replcopy/ 192.168.191.141:27017--fork
/u01/mongo/bin/mongod--dbpath=/u01/mongodb/data/--logpath=/u01/mongodb/logs/node2.log--replSetreplcopy/ 192.168.191.151:27017--fork
The data file for the first node is the data file directory of the previous single point, ensuring that the data remains
3: Start the quorum node on another machine
u01/mongo/bin/mongod--dbpath=/u01/mongodb/arbiter/--port 20000--logpath=/u01/mongodb/logs/arbiter.log--replSet Replcopy/192.168.191.141:27017,192.168.191.151:27017--fork
/admin
4: Add Configuration
CFG = {_id: "Replcopy", Members: [{_id:0, Host: "192.168.191.141:27017"}, {_id:1,host: "192.168.191 .151:27,017 "}]}
Rs.initiate (CFG)
5: Add quorum node
Rs.addarb ("192.168.191.150:20000");
6: Go to the database to see the status of several laps
Rs.status () rs.stepdown () This command forces primary and standard node roles to be interchanged to verify that failover functionality can be implemented.
7: Make the library readable (optional)
Db.getmongo (). Setslaveok ()
8: Modify Application Connection string
mongodb://192.168.191.141:27017,192.168.191.151:27017