一个扩容和版本升级的案例, 如下 :
mongoDB 1.8.1的replicaSet 需要对磁盘容量进行扩容,版本升级到2.0.2 .
从1.8升级到2.0需要注意的事项如下 :
1. 由于1.8版本使用的索引版本是v:0的, 2.0默认使用版本v:1的版本. 所以在1.8升级到2.0后新建的索引将会是v:1的。回退到1.8需要重建这些索引。
2. 对于使用mongoimport和mongoexport的脚本可能受到格式的影响
3. 2.0默认打开journaling选项,所以在版本升级的时候需要注意,可能对升级的时间有延长。
4. 1.8和2.0之间可以做相互的数据复制,所以在replicaSet环境升级还是比较方便的。
5. 升级replica SET建议先升级secondary节点,最后升级primary节点,建议使用stepDown模式.
stepDown介绍 :
replSetStepDown
db.adminCommand( { replSetStepDown : <seconds> } )
Manually tell a member to step down as primary. Node will become eligible to be primary again after the specified number of seconds. (Presumably, another node will take over by then if it were eligible.)
If the primary cannot see anyone who has synced to within 10 seconds of its latest op, the primary will reject the step down request. You can force the request by passing a force : true option.
For example:
> db.adminCommand({replSetStepDown : 1}) { "closest" : 1302040824, "difference" : 25, "errmsg" : "no secondaries within 10 seconds of my optime", "ok" : 0 } > db.adminCommand({replSetStepDown : 1, force : true}) // works
v1.7.2+: replSetStepDown closes all connections, meaning there will be no database response to this command.
v1.7.3+: the seconds parameter above can be specified. In older versions, the step down was always for one minute only.
v1.9.0+: Added ability for primary to reject step down and added force option.
具体的操作过程 :
1. 升级版本
关闭其中一台secondary, 程序文件升级到2.0.2. 开启.
操作另一台secondary.
stepDown关闭primary. 升级到2.0.2.
2. 添加磁盘.
原来的磁盘不是lvm管理的,所以在新增硬盘足够大,并且可以在OPLOG未 ROTATE之前可以完成的情况下。把新加的硬盘作为lvm管理的设备来扩,然后再把老的硬盘加入到VG,扩LV,再扩文件系统。