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

后端 未结 5 1851
我寻月下人不归
我寻月下人不归 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:59

    Remove all secondary hosts from replica set (rs.remove('host:port')), restart the mongo deamon without replSet parameter (editing /etc/mongo.conf) and the secondary hosts starts in standalone mode again.

    The Primary host is tricky one, because you can't remove it from the replica set with rs.remove. Once you have only the primary node in the replica set, you should exit mongo shell and stop mongo. Then you edit the /etc/mongo.conf and remove the replSet parameter and start mongo again. Once you start mongo you are already in standalone mode, but the mongo shell will prompt a message like:

    2015-07-31T12:02:51.112+0100 [initandlisten] ** WARNING: mongod started without --replSet yet 1 documents are present in local.system.replset

    to remove the warning you can do 2 procedures: 1) Droping the local db and restarting mongo:

    use local
    db.dropDatabase();
    
    /etc/init.d/mongod restart
    

    2)Or if you don't want to be so radical, you can do:

    use local
    db.system.replset.find()
    

    and it will prompt a message like:

    { "_id" : "replicaSetName", "version" : 1, "members" : [ { "_id" : 0, "host" : "hostprimary:mongoport" } ] }
    

    then you will erase it using:

    db.system.replset.remove({ "_id" : "replicaSetName", "version" : 1, "members" : [ { "_id" : 0, "host" : "hostprimary:mongoport" } ] })
    

    and it will probably prompt:

    WriteResult({ "nRemoved" : 1 })
    

    Now, you can restart the mongo and the warning should be gone, and you will have your mongo in standalone mode without warnings

提交回复
热议问题