MongoDB: Remove an Arbiter From a Replica Set

Removing an arbiter from MongoDB Replica Set can be quite tricky, and official MongoDB documentation does not say it directly how to do it.

MongoDB Logo

I assume that you have auth enabled (just like I have), so lets start with connecting to your ReplicaSet "repl" master as an administrator:

mongo mongo.domain.com/admin -u admin -p pass

You will see the following prompt:
repl:PRIMARY>

Type in conf=rs.conf()
repl:PRIMARY> conf = rs.conf()
{
 "_id" : "repl",
 "version" : 8,
 "members" : [
  {
   "_id" : 0,
   "host" : "mongo.server.com:27017",
   "priority" : 2
  },
  {
   "_id" : 1,
   "host" : "mongo1.server.com:27017"
  },
  {
   "_id" : 2,
   "host" : "arbiter.server.com:27017",
   "arbiterOnly" : true
  },
  {
   "_id" : 3,
   "host" : "mongo2.server.com:27017"
  }
 ]
}

Now lets adjust the configuration by removing member from 3rd position using JS splice() method:

repl:PRIMARY> conf.members.splice(2,1)
repl:PRIMARY> conf
{
 "_id" : "repl",
 "version" : 8,
 "members" : [
  {
   "_id" : 0,
   "host" : "mongo.server.com:27017",
   "priority" : 2
  },
  {
   "_id" : 1,
   "host" : "mongo1.server.com:27017"
  },
  {
   "_id" : 3,
   "host" : "mongo2.server.com:27017"
  }
 ]
}

Finally, lets ask MongoDB to reconfigure the replica set


repl:PRIMARY> rs.reconfig(conf)
Tue Jul 16 01:14:32.165 DBClientCursor::init call() failed
Tue Jul 16 01:14:32.165 trying reconnect to localhost:27017
Tue Jul 16 01:14:32.165 reconnect localhost:27017 ok
reconnected to server after rs command (which is normal)
repl:PRIMARY>
repl:PRIMARY> rs.conf()
{
 "_id" : "repl",
 "version" : 9,
 "members" : [
  {
   "_id" : 0,
   "host" : "mongo.server.com:27017",
   "priority" : 2
  },
  {
   "_id" : 1,
   "host" : "mongo1.server.com:27017"
  },
  {
   "_id" : 3,
   "host" : "mongo2.server.com:27017"
  }
 ]
}


Type in rs.status() to verify that arbiter was removed from ReplicaSet, and by our example we have 1 primary and 2 secondaries.

repl:PRIMARY> rs.status()

Congratulations, you have updated your MongoDB ReplicaSet (notice, there is new version number 9 in rs.conf() - MongoDB automatically updates it to newer version when you call rs.reconfig())

More reading: 10Gen Announces MongoDB Backup Service

Comments

Popular posts from this blog

Stubbing and Mocking Static Methods with PHPUnit

Enable HTTP/2 Support in AWS ELB

How To Attach Your EBS volume to multiple EC2 instances