环境:
OS:Centos 7
mongodb:4.4.22
1.停掉当前运行的mongodb
/usr/local/services/mongodb/bin/mongo localhost:29001
use admin
db.shutdownServer()
2.网络层面修改ip地址
[root@localhost network-scripts]# service network restart
3.修改参数
修改配置文件,注释掉副本集参数和修改bind_ip参数
vi /home/middle/mongodb/conf/mongo.cnf
##replSet=s1
bind_ip=192.168.1.108,127.0.0.1
4.启动mongodb
[root@localhost ~]# /usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf
5.更新db.system.replset表
/usr/local/services/mongodb/bin/mongo 192.168.1.108:29001 use local cfg = db.system.replset.findOne({_id: 's1'}) cfg.members[0].host = "192.168.1.108:29001" db.system.replset.update({_id: 's1'}, cfg) db.system.replset.find()
6.关闭mongodb
/usr/local/services/mongodb/bin/mongo localhost:29001
use admin
db.shutdownServer()
7.修改参数后启动
vi /home/middle/mongodb/conf/mongo.cnf
replSet=s1
启动
[root@localhost ~]# /usr/local/services/mongodb/bin/mongod -f /home/middle/mongodb/conf/mongo.cnf
8.登录查看
/usr/local/services/mongodb/bin/mongo 192.168.1.108:29001 s1:PRIMARY> rs.conf() { "_id" : "s1", "version" : 56419, "protocolVersion" : NumberLong(1), "writeConcernMajorityJournalDefault" : true, "members" : [ { "_id" : 0, "host" : "192.168.1.108:29001", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : -1, "catchUpTakeoverDelayMillis" : 30000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("64d20b9a0dd2e7e36110962a") } }
标签:bin,mongo,mongodb,update,usr,ip,services,local From: https://www.cnblogs.com/hxlasky/p/17616278.html