How to convert a MongoDB replica set to a stand alone server

后端 未结 5 1847
我寻月下人不归
我寻月下人不归 2020-12-14 06:38

Consider, I have 4 replicate sets and the config is as follows:

{
 \"_id\": \"rs_0\",
 \"version\": 5,
 \"members\" : [
  {\"_id\": 1, \"host\": \"127.0.0.1:         


        
5条回答
  •  死守一世寂寞
    2020-12-14 06:58

    The MongoDB Documentation suggests the following to perform maintenance on a replica set member, which brings the the replica set member into standalone mode for further operations. With little modification it can be made standalone:

    1. If node in concern is the only node in a shard, drain the chunks to other shards as per MongoDB documentation here, or else the sharded database will break, i.e.
      • Make sure balancer is enabled by connecting to mongos and run sh.startBalancer(timeout, interval)
      • For the shard in concern, go to admin database and db.adminCommand( { removeShard: "mongodb0" } )
      • Check draining status by repeating above removeShard command, wait for draining to complete
    2. If node in concern is primary, do rs.stepDown(300)
    3. Stop the node by running db.shutdownServer()
    4. Change the yaml config by:
      • commenting out replication.replSetName (--replSetName in command line)
      • commenting out sharding.clusterRole for shard or config server (--shardsvc and --configsvr in command line)
      • commenting out net.port, then change it to a different port (--port in command line)
    5. Start the mongod instance
    6. If change is permanent, go to other mongod instance and run rs.remove("host:port")

    After this, the node in concern should be up and running in standalone mode.

提交回复
热议问题