1. 先删除旧的文档db.remove({});
2. 从副本集中移除待清理的成员:
(1) 登录副本集中的 Primary 服务器(/opt/mongo1/bin/mongo --port 27017)
(2) rs.remove("192.168.1.54:27019")
3. 关闭待清理的 mongodb 服务器
(1) 登录待清理的 mongodb 服务器(/opt/mongo2/bin/mongo --port 27018)
(2) user admin; db.shutdownServer();
4. 修改 mongodb 启动参数,并运行
bin/mongod --dbpath /home/mongodata2/data --port 27018 --logpath=/home/mongodata2/logs/mongodb2.log --repair --repairpath /opt/data
5. 确认 mongod 运行结束
可以用 ps axu | grep mongod 查看进程是否结束。
也可以看日志文件 /home/mongodata2/logs/mongodb2.log 是否有如下输出:
2016-05-10T13:14:41.646+0800 [conn5413] dbexit: shutdown called
2016-05-10T13:14:41.646+0800 [conn5413] shutdown: going to close listening sockets...
2016-05-10T13:14:41.646+0800 [conn5413] closing listening socket: 8
2016-05-10T13:14:41.646+0800 [conn5413] closing listening socket: 10
2016-05-10T13:14:41.646+0800 [conn5413] removing socket file: /tmp/mongodb-27018.sock
2016-05-10T13:14:41.646+0800 [conn5413] shutdown: going to flush diaglog...
2016-05-10T13:14:41.646+0800 [conn5413] shutdown: going to close sockets...
2016-05-10T13:14:41.646+0800 [conn5413] shutdown: waiting for fs preallocator...
2016-05-10T13:14:41.646+0800 [conn5413] shutdown: lock for final commit...
2016-05-10T13:14:41.646+0800 [conn5413] shutdown: final commit...
2016-05-10T13:14:41.647+0800 [conn5413] shutdown: closing all files...
2016-05-10T13:14:41.832+0800 [conn5413] closeAllFiles() finished
2016-05-10T13:14:41.832+0800 [conn5413] journalCleanup...
2016-05-10T13:14:41.832+0800 [conn5413] removeJournalFiles
2016-05-10T13:14:41.889+0800 [conn5413] shutdown: removing fs lock...
2016-05-10T13:14:41.889+0800 [conn5413] dbexit: really exiting now
6. 最后以正常方式启动 mongod,并将成员加入到副本集中
登录副本集中的 Primary 服务器
rs.add("IPADDR:27018")
查看副本集的运行结果: rs.printSlaveReplicationInfo()
原文:http://www.cnblogs.com/taoge007/p/6063710.html