我的mongo测试环境部署图:
192.168.28.121 /usr/local/mongo/bin/mongod -f /etc/mongo_27017.conf /usr/local/mongo/bin/mongos -f /etc/mongo_27018.conf 192.168.28.44 /usr/local/mongo/bin/mongod -f /etc/mongo_27017.conf // primary /usr/local/mongo/bin/mongod -f /etc/mongo_27018.conf /usr/local/mongo/bin/mongod -f /etc/mongo_27019.conf // 仲裁 192.168.28.45 /usr/local/mongo/bin/mongod -f /etc/mongo_27017.conf // primary /usr/local/mongo/bin/mongod -f /etc/mongo_27018.conf /usr/local/mongo/bin/mongod -f /etc/mongo_27019.conf // 仲裁
mongodb升级步骤有些琐碎,总共分为以下六步:
- 检查mongo是否可更新
- 关闭balancer
- 更新mongs路由节点
- 更新config配置节点
- 更新分片和复制集节点
- 启动balancer
这里是mongodb2.4到2.6.9的更新,先到官网下载mongodb2.6:
http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.9.tgz
准备好后,具体操作步骤如下:
线上注意加上:numactl --interleave=all
1、检查mongo是否可更新
2.6版本下
// 新版本连接老版本的mongos路由端口20000 检查 ./bin/mongo --port 20000 mongos > use admin > db.upgradeCheckAllDBs()
2、关闭balancer
2.4版本:关闭balancer 负载均衡,检查没有balancer,等着直到没有balancer
> sh.stopBalancer() > while( db.locks.findOne({_id: "balancer"}).state ) { print("waiting..."); sleep(1000); }
3、更新mongs路由节点
2.4版本关闭所有monogs,2.6版本启动,配置文件在2.4里面
/usr/local/mongo2.6.9/bin/mongos -f /etc/mongo_27018.conf --upgrade /usr/local/mongo2.6.9/bin/mongos -f /etc/mongo_27018.conf
4、更新config配置节点
2.4版本关闭所有mongod配置,2.6版本启动,配置文件在2.4里面
升级时,至少保持一个config在线。
/usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27017.conf --upgrade /usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27017.conf
5、更新分片和复制集节点
先升级secondry,关闭服务
/usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27018.conf --upgrade /usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27018.conf
其次升级primary,先切primary.stepDown
> rs.stepDown() > rs.status() //等到当前primary变成 SECONDARY ,其他有的 SECONDARY 变成primary,这时升级 > db.shutdownServer() /usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27017.conf --upgrade /usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27017.conf
最后升级arbiter仲裁服务
/usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27019.conf --upgrade /usr/local/mongo2.6.9/bin/mongod -f /etc/mongo_27019.conf
6、启动balancer
2.6版本,稍微等待一下即可。
> sh.startBalancer()
到这里已经完成mongodb升级,测试下。
可能遇到一下问题:
[mongosMain] ERROR: error upgrading config database to v5 :: caused by :: newer version 5 of mo
ngo config metadata is required, current version is 4, need to run mongos with --upgrade
解决方法:
./bin/mongos -f ../mongodb-2.4.1/conf/route20000.conf --upgrade
ERROR: child process failed, exited with error number 100
日志:exception in initAndListen: 12596 old lock file, terminating
解决方法:
没有正确关闭mongo引起的,删除mongodb.lock,在启动mongo指定的data-path里面
rm data/shard10001/mongodb.lock