修改mongodb集群IP

  1. 关闭集群的所有节点
  2. 以单机模式启动b
# bind_ip 为新地址
./mongod --bind_ip xx.xx.xx.xx --port 29012 --dbpath /rs1/mongodb/lcc2 --logpath /home/qboxserver/mongodb/log/lcc2.log -logappend --oplogSize 20000 --storageEngine rocksdb --rocksdbCacheSizeGB 10 &
  1. 进入到数据库里面修改副本信息
./mongo xx.xx.xx.xx:29012
use local
db.system.replset.find()
{ "_id" : "lcc2", "version" : 1, "protocolVersion" : NumberLong(1), "members" : [ { "_id" : 1, "host" : "xx.xx.xx.xx:29012", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 3, "tags" : {  }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 2, "host" : "xx.xx.xx.xx:29012", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 2, "tags" : {  }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 3, "host" : "xx.xx.xx.xx:29012", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : {  }, "slaveDelay" : NumberLong(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "getLastErrorModes" : {  }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("5c24cbaa2045a8fe36840702") } }
# 修改为新集群IP
cfg={ "_id" : "lcc2", "version" : 1, "protocolVersion" : NumberLong(1), "members" : [ { "_id" : 1, "host" : "xx.xx.xx.xx:29012", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 3, "tags" : {  }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 2, "host" : "xx.xx.xx.xx:29012", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 2, "tags" : {  }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 3, "host" : "xx.xx.xx.xx:29012", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : {  }, "slaveDelay" : NumberLong(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "getLastErrorModes" : {  }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("5c24cbaa2045a8fe36840702") } }
db.system.replset.update({"_id":"lcc2”},cfg
  1. 以集群的方式启动,需改动启动文件里面的IP为新IP
./mongod --bind_ip xx.xx.xx.xx --port 29012 --dbpath /rs1/mongodb/lcc2 --logpath /home/qboxserver/mongodb/log/lcc2.log -logappend --oplogSize 20000 --storageEngine rocksdb --rocksdbCacheSizeGB 10 --replSet lcc2 &

你可能感兴趣的:(数据库)