mongodb集群升级
mongodb3.0简介
MongoDB 3.0于2015年3月3日正式发布。可以毫不夸张的说,该版本的新增特性标志着MongoDB这款典型的NoSQL数据库已经进入了一个全新的发展阶段。
3.0版本的新增特性:
插件式存储引擎API
MMAPv1存储引擎提升
WiredTiger存储引擎
复制集改进
分片集群改进
官方文档:http://docs.mongodb.org/manual/release-notes/3.0/
分片集群配置请看上一篇文章:
http://jiachen.blog.51cto.com/3296673/1689494
mongodb-2.6.7升级mongodb-3.0.4
注意:线上升级需要将写的业务停掉,(config、路由升级完可以正常提供服务)
一、升级顺序
1.1、 configdb 配置库
1.2、 mongos 路由
1.3、 分片备份实例 分片(备)
1.4、 主分片实例 分片(主)
二、升级前准备
配置3.0.4环境,三台服务器同样操作
tar -zxvf mongodb-linux-x86_64-3.0.4.tgz
mv mongodb-linux-x86_64-3.0.4 /usr/local/
cd /usr/local/mongodb-linux-x86_64-3.0.4/
mkdir conf
分片1服务器:192.168.2.134:(此时的配置文件必须建立为新的配置目录)
cd /usr/local/mongodb-linux-x86_64-3.0.4/conf cp ../../mongodb-linux-x86_64-2.6.7/conf/configdb1.conf . cp ../../mongodb-linux-x86_64-2.6.7/conf/mongos1.conf . mv configdb1.conf 3.0.4configdb1.conf mkdir /data/mongodb/3.0.4_configdb1/data -p [root@localhost ~]# cat /usr/local/mongodb-linux-x86_64-3.0.4/conf/3.0.4_configdb1.conf logpath = /data/mongodb/logs/3.0.4_configdb1.log logappend = true pidfilepath = /data/mongodb/pid/3.0.4_configdb1.pid dbpath = /data/mongodb/3.0.4_configdb1/data fork = true port = 27100 oplogSize = 2048 configsvr = true
分片2服务器:192.168.5.133:
cd /usr/local/mongodb-linux-x86_64-3.0.4/ cp ../../mongodb-linux-x86_64-2.6.7/conf/configdb2.conf . cp ../../mongodb-linux-x86_64-2.6.7/conf/mongos2.conf . mv configdb2.conf 3.0.4_configdb2.conf mkdir /data/mongodb/3.0.4_configdb2/data -p [root@localhost ~]# cat /usr/local/mongodb-linux-x86_64-3.0.4/conf/3.0.4_configdb2.conf logpath = /data/mongodb/logs/3.0.4_configdb2.log logappend = true pidfilepath = /data/mongodb/pid/3.0.4_config2.pid dbpath = /data/mongodb/3.0.4_configdb2/data fork = true port = 27200 oplogSize = 2048 configsvr = true
分片3服务器:192.168.5.132:
cd /usr/local/mongodb-linux-x86_64-3.0.4/ cp ../../mongodb-linux-x86_64-2.6.7/conf/mongos3.conf . cp ../../mongodb-linux-x86_64-2.6.7/conf/configdb3.conf . mv configdb3.conf 3.0.4_configdb3.conf mkdir /data/mongodb/3.0.4_configdb3/data -p [root@bjmdb4 ~]# cat /usr/local/mongodb-linux-x86_64-3.0.4/conf/3.0.4_configdb3.conf logpath = /data/mongodb/logs/3.0.4_configdb3.log logappend = true pidfilepath = /data/mongodb/pid/3.0.4_config3.pid dbpath = /data/mongodb/3.0.4_configdb3/data fork = true port = 27300 oplogSize = 2048 configsvr = true
三、开始升级(业务停止写数据)
3.1、备份configdb数据库:
先关闭平衡器防止升级出错进行数据库重建
[root@localhost ~]# /usr/local/mongodb-linux-x86_64-2.6.7/bin/mongo 192.168.2.134:27111
3.2、备份configdb数据库完成后停掉(三台服务器)2.6.7config实例,并逐个启动3.0.4实例:
分片1服务器:IP:192.168.2.134
分片2服务器:IP:192.168.2.133
分片3服务器:IP:192.168.2.132
三台服务器停掉2.6.7版本mongos然后执行 --upgrade (升级成功的话,mongos会自动退出,需要重新启动):
分片1服务器:IP:192.168.2.134
分片2服务器:IP:192.168.2.133
分片3服务器:IP:192.168.2.132
四、config导入数据:
[root@localhost ~]# /usr/local/mongodb-linux-x86_64-3.0.4/bin/mongorestore -h 192.168.2.134:27100 --dir /root/2.6.7configdb/ 2015-08-29T16:36:49.108+0800 building a list of dbs and collections to restore from /root/2.6.7configdb/ dir 2015-08-29T16:36:49.150+0800 reading metadata file from /root/2.6.7configdb/admin/tab2.metadata.json 2015-08-29T16:36:49.176+0800 restoring admin.tab2 from file /root/2.6.7configdb/admin/tab2.bson 2015-08-29T16:36:49.228+0800 reading metadata file from /root/2.6.7configdb/config/changelog.metadata.json 2015-08-29T16:36:49.230+0800 restoring config.changelog from file /root/2.6.7configdb/config/changelog.bson 2015-08-29T16:36:49.257+0800 reading metadata file from /root/2.6.7configdb/admin/tab4.metadata.json 2015-08-29T16:36:49.257+0800 restoring admin.tab4 from file /root/2.6.7configdb/admin/tab4.bson 2015-08-29T16:36:49.262+0800 reading metadata file from /root/2.6.7configdb/config/locks.metadata.json 2015-08-29T16:36:49.263+0800 restoring config.locks from file /root/2.6.7configdb/config/locks.bson 2015-08-29T16:36:49.367+0800 restoring indexes for collection config.locks from metadata 2015-08-29T16:36:50.465+0800 finished restoring config.locks 2015-08-29T16:36:50.465+0800 reading metadata file from /root/2.6.7configdb/config/lockpings.metadata.json 2015-08-29T16:36:50.465+0800 restoring config.lockpings from file /root/2.6.7configdb/config/lockpings.bson 2015-08-29T16:36:50.497+0800 restoring indexes for collection config.changelog from metadata 2015-08-29T16:36:50.525+0800 finished restoring config.changelog 2015-08-29T16:36:50.525+0800 reading metadata file from /root/2.6.7configdb/config/collections.metadata.json 2015-08-29T16:36:50.525+0800 restoring config.collections from file /root/2.6.7configdb/config/collections.bson 2015-08-29T16:36:50.829+0800 restoring indexes for collection config.lockpings from metadata 2015-08-29T16:36:50.829+0800 restoring indexes for collection admin.tab2 from metadata 2015-08-29T16:36:50.829+0800 restoring indexes for collection admin.tab4 from metadata 2015-08-29T16:36:50.830+0800 finished restoring admin.tab4 2015-08-29T16:36:50.832+0800 finished restoring admin.tab2 2015-08-29T16:36:50.832+0800 finished restoring config.lockpings 2015-08-29T16:36:50.847+0800 restoring indexes for collection config.collections from metadata 2015-08-29T16:36:50.848+0800 finished restoring config.collections 2015-08-29T16:36:50.925+0800 reading metadata file from /root/2.6.7configdb/admin/tab1.metadata.json 2015-08-29T16:36:50.925+0800 restoring admin.tab1 from file /root/2.6.7configdb/admin/tab1.bson 2015-08-29T16:36:50.925+0800 reading metadata file from /root/2.6.7configdb/config/chunks.metadata.json 2015-08-29T16:36:50.969+0800 reading metadata file from /root/2.6.7configdb/config/mongos.metadata.json 2015-08-29T16:36:50.969+0800 restoring config.mongos from file /root/2.6.7configdb/config/mongos.bson 2015-08-29T16:36:50.970+0800 restoring indexes for collection admin.tab1 from metadata 2015-08-29T16:36:50.972+0800 reading metadata file from /root/2.6.7configdb/config/databases.metadata.json 2015-08-29T16:36:50.972+0800 restoring config.databases from file /root/2.6.7configdb/config/databases.bson 2015-08-29T16:36:52.466+0800 restoring config.chunks from file /root/2.6.7configdb/config/chunks.bson 2015-08-29T16:36:54.770+0800 finished restoring admin.tab1 2015-08-29T16:36:54.770+0800 reading metadata file from /root/2.6.7configdb/config/shards.metadata.json 2015-08-29T16:36:54.770+0800 restoring config.shards from file /root/2.6.7configdb/config/shards.bson 2015-08-29T16:36:55.504+0800 [########################] config.mongos 279.0 B/279.0 B (100.0%) 2015-08-29T16:36:55.504+0800 [........................] config.databases 0.0 B/279.0 B (0.0%) 2015-08-29T16:36:55.504+0800 [........................] config.chunks 0.0 B/317.0 B (0.0%) 2015-08-29T16:36:55.504+0800 2015-08-29T16:36:55.508+0800 [########################] config.mongos 279.0 B/279.0 B (100.0%) 2015-08-29T16:36:55.508+0800 [########################] config.databases 279.0 B/279.0 B (100.0%) 2015-08-29T16:36:55.508+0800 [########################] config.chunks 317.0 B/317.0 B (100.0%) 2015-08-29T16:36:55.508+0800 [........................] config.shards 0.0 B/246.0 B (0.0%) 2015-08-29T16:36:55.508+0800 2015-08-29T16:36:55.509+0800 restoring indexes for collection config.mongos from metadata 2015-08-29T16:36:55.510+0800 restoring indexes for collection config.shards from metadata 2015-08-29T16:36:55.511+0800 restoring indexes for collection config.chunks from metadata 2015-08-29T16:36:55.511+0800 restoring indexes for collection config.databases from metadata 2015-08-29T16:36:55.511+0800 finished restoring config.databases 2015-08-29T16:36:55.511+0800 reading metadata file from /root/2.6.7configdb/config/version.metadata.json 2015-08-29T16:36:55.511+0800 restoring config.version from file /root/2.6.7configdb/config/version.bson 2015-08-29T16:36:55.977+0800 finished restoring config.chunks 2015-08-29T16:36:55.977+0800 reading metadata file from /root/2.6.7configdb/config/settings.metadata.json 2015-08-29T16:36:55.986+0800 restoring config.settings from file /root/2.6.7configdb/config/settings.bson 2015-08-29T16:36:59.506+0800 finished restoring config.shards 2015-08-29T16:36:59.506+0800 reading metadata file from /root/2.6.7configdb/config/tags.metadata.json 2015-08-29T16:36:59.527+0800 restoring config.tags from file /root/2.6.7configdb/config/tags.bson 2015-08-29T16:37:03.580+0800 finished restoring config.mongos 2015-08-29T16:37:03.580+0800 [########################] config.version 83.0 B/83.0 B (100.0%) 2015-08-29T16:37:03.580+0800 [........................] config.settings 0.0 B/72.0 B (0.0%) 2015-08-29T16:37:03.580+0800 config.tags 0.0 B 2015-08-29T16:37:03.580+0800 2015-08-29T16:37:03.590+0800 restoring indexes for collection config.tags from metadata 2015-08-29T16:37:03.591+0800 restoring indexes for collection config.version from metadata 2015-08-29T16:37:03.591+0800 finished restoring config.version 2015-08-29T16:37:03.592+0800 finished restoring config.tags 2015-08-29T16:37:03.592+0800 restoring indexes for collection config.settings from metadata 2015-08-29T16:37:03.592+0800 finished restoring config.settings 2015-08-29T16:37:03.619+0800 done
Configdb和mongos3.0.4升级完成。
查看数据查看分片信息验证并开启均衡器!
也可以用查看主备份库复制的延迟:
replset3:PRIMARY> rs.printSlaveReplicationInfo() source: 192.168.2.134:27033 syncedTo: Sat Aug 29 2015 16:26:35 GMT+0800 (CST) 0 secs (0 hrs) behind the primary replset3:PRIMARY>
如果没有延迟,可以在主库执行"rs.stepDown(3600) "让主库退位,仲裁节点会让副本集备份库接管主库,停掉主库更新配置文件启动更换数据目录,启动数据开始复制,复制完成以后接管主库。仲裁节点可以随时停掉,3.0.4启动。
其他两个复制集也是同样的操作,这样升级oK!