1. 关闭服务
服务器位置:127.0.0.1:37133
#登陆到该备份节点 mongo --port 37133 #关闭节点 shard3:RECOVERING > use admin; shard3:RECOVERING > db.shutdownServer(); shard3:RECOVERING > exit;
2. 并以单机模式启动
#修改配置文件 vi /home/mongodb/mongodb2.6/shard/shard3.conf #原文件 dbpath=/home/mongodb/mongodb2.6/shard/data/shard3 logpath=/home/mongodb/mongodb2.6/shard/logs/shard3.log port=37133 oplogSize=20 logappend=true fork=true quiet=true nojournal=true shardsvr=true replSet=shard3 #修改为=> dbpath=/home/mongodb/mongodb2.6/shard/data/shard3 logpath=/home/mongodb/mongodb2.6/shard/logs/shard3.log port=37139 #此处把37133->37139, 在37139端口临时启动 oplogSize=2048 #此处把20->2048 修改oplog大小 logappend=true fork=true quiet=true nojournal=true shardsvr=true # replSet=shard3 #此处把副本集配置去除,先以单机形式启动
#启动服务 /home/mongodb/mongodb2.6/bin/mongod -f /home/mongodb/mongodb2.6/shard/shard3.conf
3. 重新构建oplog
# 登陆到刚启动的节点 > use local # 删除临时数据 > db.temp.drop() # 保存oplog的最新的时间点 > db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() ) # 查询一下是否有保存到,有数据返回就行 > db.temp.find() # 删除旧的oplog > db.oplog.rs.drop() # 创建一个新的Oplog,大小为2G > db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024 * 1024) } ) # 把刚保存到临时目录的数据重新写会oplog > db.oplog.rs.save( db.temp.findOne()) # 查一下是否有保存到 > db.oplog.rs.find() # 关闭服务,稍后以副本集模式启动该节点 > use admin > db.shutdownServer()
4. 以副本集模式启动
#修改配置文件 dbpath=/home/mongodb/mongodb2.6/shard/data/shard3 logpath=/home/mongodb/mongodb2.6/shard/logs/shard3.log port=37133 #还原回来37133 oplogSize=2048 logappend=true fork=true quiet=true nojournal=true shardsvr=true replSet=shard3 #还原回来replSet=shard3
#启动服务 /home/mongodb/mongodb2.6/bin/mongod -f /home/mongodb/mongodb2.6/shard/shard3.conf