single-machine switch to replica set method step
1: Back up the database, turn off 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, guaranteeing that the data has been
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: Enter the database to view the status of a few laps
The Rs.status () rs.stepdown () command can force the primary and standard node roles to be interchanged to verify that the failover function is implemented.
7: Make the repository readable (optional)
Db.getmongo (). Setslaveok ()
8: Modify the Application connection string
mongodb://192.168.191.141:27017,192.168.191.151:27017