一、升级前检测
使用2.6.0的db.upgradeCheckAllDBs()检测是否兼容原先2.4.9版本的数据
./mongodb-linux-x86_64-2.6.4/bin/mongo --port 30000
>db = connect("127.0.0.1:27017/database")
> use admin
>db.upgradeCheckAllDBs()
//官方的建议是只有此步检测通过后才建议从2.4升级到2.6,需要等待段时间
上面是执行检测的方法,但在实际使用中请执行以下的命令
# /root/mongodb-linux-x86_64-2.6.4/bin/mongo admin --port 27017
--eval "db.upgradeCheckAllDBs()"| tee
/tmp/upgradecheckalldbs.txt
直接通过mongos check即可
二、如果db.upgradeCheckAllDBs()检测通过,那就准备升级吧,如果有数据错误或不兼容,请干掉它或者修复它。
1.将老的mongodb程序备份,启动新的mongodb2.6
2.这里会出错,主要是config的错误,如下:
2015-05-19T10:53:49.444+0800
[mongosMain] ERROR: error upgrading config database to v5 :: caused
by :: newer version 5 of mongo config metadata is required, current
version is 4, need to run mongos with --upgrade
3.执行upgrade命令
/usr/local/mongodb/bin/mongos --configdb
xx1:20000,xx2:20000,xx3:20000 --port 30000
--logpath /home/data/mongos.log --logappend --fork --upgrade
依然报错:
2015-05-19T11:00:21.006+0800
[mongosMain] ERROR: error upgrading config database to v5 :: caused
by :: balancer must be stopped for config upgrade
需要先停掉config的balancer
4.随便登陆一台config,执行
sh.stopBalancer()
然后在启动mongos即可
[root@localhost ~]# /usr/local/mongodb/bin/mongos --configdb
xx1:27000,xx2:27000,xx3:27000 --port 30000
--logpath /data/mongos.log --logappend --fork --upgrade
about to fork child process, waiting until server is ready for
connections.
forked process: 31258
child process started successfully, parent exiting
出现上述输出,表示upgrade完成。
5.启动mongos
一定注意时间同步问题,否则upgrade会一直等待而不执行。