码迷,mamicode.com
首页 > 数据库 > 详细

mongodb2.6.7升级3.03

时间:2015-05-22 19:34:10      阅读:410      评论:0      收藏:0      [点我收藏+]

标签:mongob

MongoDB 3.0于2015年3月3日正式发布。可以毫不夸张的说,该版本的新增特性标志着MongoDB这款典型的NoSQL数据库已经进入了一个全新的发展阶段。

3.0版本的新增特性

   插件式存储引擎API

   WiredTiger存储引擎

   MMAPv1存储引擎提升

   复制集改进

   分片集群改进


由于使用到3.0新增的功能,我们决定升级mongodb-3.0.3


本地测试

IP:192.168.5.66  

系统版本:Centos6.5_64-2.6.32  

Mongodb版本:

mongodb-linux-x86_64-2.6.7.tgz

mongodb-linux-x86_64-3.0.3.gz


测试机一台启动不同端口  一个mongos  一个configdb  两个分片  2个仲裁节点


端口分配:

分片1

shard1(副本集):192.168.5.66:27001

shard11(主):192.168.5.66:27011

arbiter1(权重)192.168.5.66:27000

 

分片2:

shard2(副本集):192.168.5.66:27002

shaed22(主):192.168.5.66:27022

arbiter2(权重):192.168.5.66:27222

 

mongos:192.168.5.66:27111

configdb:192.168.5.66:27100

 

2配置mongodb-2.6.7集群

分片1主库:


/usr/local/mongodb-2.6.7/bin/mongod -f /usr/local/mongodb-2.6.7/conf/shard11.conf

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/shard11.conf 

logpath = /data/logs/shard11.log

logappend = true

pidfilepath = /data/mdb/shard11/shard1.pid

dbpath = /data/mdb/shard11/data

directoryperdb = true

replSet = replset1

rest = true

oplogSize = 1024

fork = true

shardsvr = true

port = 27011

journal = true


分片1副本集:

/usr/local/mongodb-2.6.7/bin/mongod -f /usr/local/mongodb-2.6.7/conf/shard1.conf

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/shard1.conf 

logpath = /data/logs/shard1.log

logappend = true

pidfilepath = /data/mdb/shard1/shard1.pid

dbpath = /data/mdb/shard1/data

directoryperdb = true

replSet = replset1

rest = true

oplogSize = 1024

fork = true

shardsvr = true

port = 27001

journal = true




分片1仲裁:

/usr/local/mongodb-2.6.7/bin/mongod -f /usr/local/mongodb-2.6.7/conf/arbiter1.conf

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/arbiter1.conf 

logpath = /data/logs/arbiter1.log

logappend = true

pidfilepath = /data/mdb/arbiter1/arbiter1.pid

dbpath = /data/mdb/arbiter1/data

directoryperdb = true

replSet = replset1

rest = true

oplogSize = 1024

fork = true

shardsvr = true

port = 27000

journal = true


分片2主库:

/usr/local/mongodb-2.6.7/bin/mongod -f /usr/local/mongodb-2.6.7/conf/shard22.conf  

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/shard22.conf 

logpath = /data/logs/shard22.log

logappend = true

pidfilepath = /data/mdb/shard22/shard22.pid

dbpath = /data/mdb/shard22/data

directoryperdb = true

replSet = replset2

rest = true

oplogSize = 1024

fork = true

shardsvr = true

port = 27022

journal = true

 


分片2副本集:  

/usr/local/mongodb-2.6.7/bin/mongod -f /usr/local/mongodb-2.6.7/conf/shard2.conf

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/shard2.conf 

logpath = /data/logs/shard2.log

logappend = true

pidfilepath = /data/mdb/shard2/shard2.pid

dbpath = /data/mdb/shard2/data

directoryperdb = true

replSet = replset2

rest = true

oplogSize = 1024

fork = true

shardsvr = true

port = 27002

journal = true

        


分片2仲裁:  

/usr/local/mongodb-2.6.7/bin/mongod -f /usr/local/mongodb-2.6.7/conf/arbiter2.conf

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/arbiter2.conf 

logpath = /data/logs/arbiter2.log

logappend = true

pidfilepath = /data/mdb/arbiter2/arbiter1.pid

dbpath = /data/mdb/arbiter2/data

directoryperdb = true

replSet = replset2

rest = true

oplogSize = 1024

fork = true

shardsvr = true

port = 27222

journal = true

     


configdb:

/usr/local/mongodb-2.6.7/bin/mongod -f /usr/local/mongodb-2.6.7/conf/configdb.conf

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/configdb.conf 

logpath = /data/logs/configdb.log

logappend = true

pidfilepath = /data/mdb/configdb/config.pid

dbpath = /data/mdb/configdb/data

fork = true

port = 27100

oplogSize = 2048

configsvr = true

    


mongos:

/usr/local/mongodb-2.6.7/bin/mongos -f /usr/local/mongodb-2.6.7/conf/mongos.conf

[root@ztest ~]# cat /usr/local/mongodb-2.6.7/conf/mongos.conf 

logpath = /data/logs/mongos.log

logappend = true

fork = true

port = 27111

configdb = 192.168.5.66:27100

       




分片配置:

     分片1/usr/local/mongodb-2.6.7/bin/mongo 192.168.5.66:27011

config = {_id:"replset1", members:[

                   {_id:0,host:"192.168.5.66:27001",priority:4},

                   {_id:1,host:"192.168.5.66:27011",priority:5},

                   {_id:2,host:"192.168.5.66:27000",arbiterOnly:true},

                    

               ]

        }

 

rs.initiate(config); //更新配置

rs.status()          //查看配置信息

 

分片2/usr/local/mongodb-2.6.7/bin/mongo 192.168.5.66:27022

config = {_id:"replset2", members:[

                   {_id:0,host:"192.168.5.66:27002",priority:4},

                   {_id:1,host:"192.168.5.66:27022",priority:5},

                    {_id:2,host:"192.168.5.66:27222",arbiterOnly:true},

                    

               ]

        }

 

rs.initiate(config);  //更新配置

rs.status()          //查看配置信息

 

mongos添加路由信息:/usr/local/mongodb-2.6.7/bin/mongo 192.168.5.66:27111/admin

目前搭建了mongodb配置服务器、路由服务器,各个分片服务器,不过应用程序连接到 mongos 路由服务器并不能使用分片机制,还需要在程序里设置分片配置,让分片生效。

 #串联路由服务器与分配副本集1

 db.runCommand({addshard :"replset1/192.168.5.66:27001,192.168.5.66:27011"});


#串联路由服务器与分配副本集1 

 db.runCommand({addshard :"replset2/192.168.5.66:27002,192.168.5.66:27022"});

 

 use admin

 printShardingStatus()          //查看分片信息

 

 

3手动添加数据:/usr/local/mongodb-2.6.7/bin/mongo 192.168.5.66:27111/admin

use testapm

for (var i= 1; i <= 20; i++)db.haha.save({tid:i,name:"username"+i,age:i});

for (var i= 1; i <= 10; i++)db.table1.save({tid:i,name:"username"+i,age:i});

for (var i= 1; i <= 15; i++)db.table2.save({tid:i,name:"username"+i,age:i});

 

use crash

for (var i= 1; i <= 15; i++)db.tab1.save({tid:i,name:"username"+i,age:i});

for (var i= 1; i <= 15; i++)db.tab2.save({tid:i,name:"username"+i,age:i});

for (var i= 1; i <= 15; i++)db.table3.save({tid:i,name:"username"+i,age:i});

4开始升级mongosconfigdb先升级

拷贝配置文件: 

cp /usr/local/mongodb-2.6.7/conf/* /usr/local/mongodb-3.0.3/conf/


mongodb3.0.3的数据目录和2.6.7数据目录分开

创建新的数据目录:

mkdir /data/mdb2/{shard1,configdb,shard11,shard2,shard22,arbiter1,arbiter2}/data -p


需要修改3.0.3版本配置文件,修改数据存储路径:

 configdb.conf  ==》   dbpath = /data/mdb2/configdb/data

 shard1.conf   ==》  dbpath = /data/mdb2/shard1/data   storageEngine=wiredTiger //添加新的数据引擎

 shard11.conf   ==》  dbpath = /data/mdb2/shard11/data   storageEngine=wiredTiger //添加新的数据引擎

 shard2.conf   ==》  dbpath = /data/mdb2/shard2/data   storageEngine=wiredTiger //添加新的数据引擎

 shard22.conf   ==》  dbpath = /data/mdb2/shard22/data   storageEngine=wiredTiger //添加新的数据引擎

 arbiter1.conf  ==》  dbpath = /data/mdb2/arbiter1/data   storageEngine=wiredTiger //添加新的数据引擎

 arbiter2.conf  ==》  dbpath = /data/mdb2/arbiter2/data   storageEngine=wiredTiger //添加新的数据引擎



首先备份configdb数据库:

/usr/local/mongodb-2.6.7/bin/mongodump -h192.168.5.66:27100 -o 2.6.7conf


然后停掉configdb 

启动3.0.3 configdb:

/usr/local/mongodb-3.0.3/bin/mongod -f /usr/local/mongodb-3.0.3/conf/configdb.conf


 

mongos停掉然后执行

/usr/local/mongodb-3.0.3/bin/mongos -f/usr/local/mongodb-3.0.3/conf/mongos.conf  --upgrade

 

启动mongos3.0.3

/usr/local/mongodb-3.0.3/bin/mongos -f/usr/local/mongodb-3.0.3/conf/mongos.conf

 

configdb导入数据:/usr/local/mongodb-3.0.3/bin/mongorestore -h192.168.5.66:27100 --dir /root/2.6.7conf/

Configdbmongos3.0.3升级完成


5.数据库升级3.0.3

a.将2.6.7版的分片1主库停掉,2.6.7版本从库自动升级为主库,启动配置为3.0.3版本新的数据引擎, 启动以后开始复制数据数据复制完以后接管主库。

连接3.0.3版本分片1主库查看:

[root@ztest data]#/usr/local/mongodb-3.0.3/bin/mongo 192.168.5.66:27011

MongoDB shell version: 3.0.3

connecting to: 192.168.5.66:27011/test

Server has startup warnings:

2015-05-20T21:11:16.919+0800 I CONTROL  ** WARNING: --rest is specified without--httpinterface,

2015-05-20T21:11:16.920+0800 I CONTROL  **         enabling http interface

2015-05-20T21:11:17.469+0800 I CONTROL  [initandlisten] ** WARNING: You are runningthis process as the root user, which is not recommended.

2015-05-20T21:11:17.469+0800 I CONTROL  [initandlisten]

2015-05-20T21:11:17.470+0800 I CONTROL  [initandlisten]

2015-05-20T21:11:17.470+0800 I CONTROL  [initandlisten] ** WARNING:/sys/kernel/mm/transparent_hugepage/enabled is ‘always‘.

2015-05-20T21:11:17.470+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘

2015-05-20T21:11:17.470+0800 I CONTROL  [initandlisten]

2015-05-20T21:11:17.470+0800 I CONTROL  [initandlisten] ** WARNING:/sys/kernel/mm/transparent_hugepage/defrag is ‘always‘.

2015-05-20T21:11:17.470+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘

2015-05-20T21:11:17.470+0800 I CONTROL  [initandlisten]

replset1:PRIMARY> show dbs

local    0.000GB

testapm  0.000GB

replset1:PRIMARY> use testapm

switched to db testapm

replset1:PRIMARY> show collections

haha

table1

table2

replset1:PRIMARY> db.haha.find()

{ "_id" :ObjectId("555c858d9252c900b8cdeadc"), "tid" : 1,"name" : "username1", "age" : 1 }

{ "_id" :ObjectId("555c858e9252c900b8cdeadd"), "tid" : 2,"name" : "username2", "age" : 2 }

{ "_id" : ObjectId("555c858e9252c900b8cdeade"),"tid" : 3, "name" : "username3", "age": 3 }

{ "_id" :ObjectId("555c858e9252c900b8cdeadf"), "tid" : 4,"name" : "username4", "age" : 4 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae0"), "tid" : 5,"name" : "username5", "age" : 5 }

{ "_id" : ObjectId("555c858e9252c900b8cdeae1"),"tid" : 6, "name" : "username6", "age": 6 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae2"), "tid" : 7,"name" : "username7", "age" : 7 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae3"), "tid" : 8,"name" : "username8", "age" : 8 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae4"), "tid" : 9,"name" : "username9", "age" : 9 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae5"), "tid" : 10,"name" : "username10", "age" : 10 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae6"), "tid" : 11,"name" : "username11", "age" : 11 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae7"), "tid" : 12,"name" : "username12", "age" : 12 }

{ "_id" :ObjectId("555c858e9252c900b8cdeae8"), "tid" : 13,"name" : "username13", "age" : 13 }

{ "_id" : ObjectId("555c858e9252c900b8cdeae9"),"tid" : 14, "name" : "username14","age" : 14 }

{ "_id" :ObjectId("555c858e9252c900b8cdeaea"), "tid" : 15,"name" : "username15", "age" : 15 }

{ "_id" :ObjectId("555c858e9252c900b8cdeaeb"), "tid" : 16,"name" : "username16", "age" : 16 }

{ "_id" :ObjectId("555c858e9252c900b8cdeaec"), "tid" : 17,"name" : "username17", "age" : 17 }

{ "_id" :ObjectId("555c858e9252c900b8cdeaed"), "tid" : 18,"name" : "username18", "age" : 18 }

{ "_id" :ObjectId("555c858e9252c900b8cdeaee"), "tid" : 19,"name" : "username19", "age" : 19 }

{ "_id" :ObjectId("555c858e9252c900b8cdeaef"), "tid" : 20,"name" : "username20", "age" : 20 }

replset1:PRIMARY> db.table1.find()

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf0"), "tid" : 1,"name" : "username1", "age" : 1 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf1"), "tid" : 2,"name" : "username2", "age" : 2 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf2"), "tid" : 3,"name" : "username3", "age" : 3 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf3"), "tid" : 4,"name" : "username4", "age" : 4 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf4"), "tid" : 5,"name" : "username5", "age" : 5 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf5"), "tid" : 6,"name" : "username6", "age" : 6 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf6"), "tid" : 7,"name" : "username7", "age" : 7 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf7"), "tid" : 8,"name" : "username8", "age" : 8 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf8"), "tid" : 9,"name" : "username9", "age" : 9 }

{ "_id" : ObjectId("555c85ac9252c900b8cdeaf9"),"tid" : 10, "name" : "username10","age" : 10 }

replset1:PRIMARY> db.table2.find()

{ "_id" :ObjectId("555c85b99252c900b8cdeafa"), "tid" : 1,"name" : "username1", "age" : 1 }

{ "_id" :ObjectId("555c85b99252c900b8cdeafb"), "tid" : 2,"name" : "username2", "age" : 2 }

{ "_id" :ObjectId("555c85b99252c900b8cdeafc"), "tid" : 3,"name" : "username3", "age" : 3 }

{ "_id" :ObjectId("555c85b99252c900b8cdeafd"), "tid" : 4,"name" : "username4", "age" : 4 }

{ "_id" : ObjectId("555c85b99252c900b8cdeafe"),"tid" : 5, "name" : "username5", "age": 5 }

{ "_id" :ObjectId("555c85b99252c900b8cdeaff"), "tid" : 6,"name" : "username6", "age" : 6 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb00"), "tid" : 7,"name" : "username7", "age" : 7 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb01"), "tid" : 8,"name" : "username8", "age" : 8 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb02"), "tid" : 9,"name" : "username9", "age" : 9 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb03"), "tid" : 10,"name" : "username10", "age" : 10 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb04"), "tid" : 11,"name" : "username11", "age" : 11 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb05"), "tid" : 12,"name" : "username12", "age" : 12 }

{ "_id" : ObjectId("555c85b99252c900b8cdeb06"),"tid" : 13, "name" : "username13","age" : 13 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb07"), "tid" : 14,"name" : "username14", "age" : 14 }

{ "_id" :ObjectId("555c85b99252c900b8cdeb08"), "tid" : 15,"name" : "username15", "age" : 15 }

replset1:PRIMARY>


b.停掉2.6.7版本从库,配置3.0.3版本新数据引擎启动。

[root@ztest data]#/usr/local/mongodb-3.0.3/bin/mongo 192.168.5.66:27001

MongoDB shell version: 3.0.3

connecting to: 192.168.5.66:27001/test

Server has startup warnings:

2015-05-20T21:32:18.322+0800 I CONTROL  ** WARNING: --rest is specified without--httpinterface,

2015-05-20T21:32:18.322+0800 I CONTROL  **         enabling http interface

2015-05-20T21:32:18.888+0800 I CONTROL  [initandlisten] ** WARNING: You are runningthis process as the root user, which is not recommended.

2015-05-20T21:32:18.888+0800 I CONTROL  [initandlisten]

2015-05-20T21:32:18.888+0800 I CONTROL  [initandlisten]

2015-05-20T21:32:18.888+0800 I CONTROL  [initandlisten] ** WARNING:/sys/kernel/mm/transparent_hugepage/enabled is ‘always‘.

2015-05-20T21:32:18.888+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘

2015-05-20T21:32:18.889+0800 I CONTROL  [initandlisten]

2015-05-20T21:32:18.889+0800 I CONTROL  [initandlisten] ** WARNING:/sys/kernel/mm/transparent_hugepage/defrag is ‘always‘.

2015-05-20T21:32:18.889+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘

2015-05-20T21:32:18.889+0800 I CONTROL  [initandlisten]

replset1:STARTUP2>

replset1:SECONDARY>

replset1:SECONDARY>

replset1:SECONDARY>

replset1:SECONDARY>

replset1:SECONDARY>show dbs

2015-05-20T21:32:56.364+0800 E QUERY    Error: listDatabases failed:{"note" : "from execCommand", "ok" : 0,"errmsg" : "not master" }      //当在从节点查看数据时  会报错

对于replica set 中的secondary 节点默认是不可读的,

在各个从节点  执行  db.getMongo().setSlaveOk();    这个就行了

 

    at Error(<anonymous>)

    atMongo.getDBs (src/mongo/shell/mongo.js:47:15)

    atshellHelper.show (src/mongo/shell/utils.js:630:33)

    atshellHelper (src/mongo/shell/utils.js:524:36)

    at (shellhelp2):1:1at src/mongo/shell/mongo.js:47

replset1:SECONDARY>db.getMongo().setSlaveOk();

replset1:SECONDARY> show dbs

local    0.000GB

testapm  0.000GB

replset1:SECONDARY>use testapm

switched to db testapm

replset1:SECONDARY>show collections

haha

table1

table2

replset1:SECONDARY>db.table1.find()

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf0"), "tid" : 1,"name" : "username1", "age" : 1 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf1"), "tid" : 2,"name" : "username2", "age" : 2 }

{ "_id" : ObjectId("555c85ac9252c900b8cdeaf2"),"tid" : 3, "name" : "username3", "age": 3 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf3"), "tid" : 4,"name" : "username4", "age" : 4 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf4"), "tid" : 5,"name" : "username5", "age" : 5 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf5"), "tid" : 6,"name" : "username6", "age" : 6 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf6"), "tid" : 7,"name" : "username7", "age" : 7 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf7"), "tid" : 8,"name" : "username8", "age" : 8 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf8"), "tid" : 9,"name" : "username9", "age" : 9 }

{ "_id" :ObjectId("555c85ac9252c900b8cdeaf9"), "tid" : 10,"name" : "username10", "age" : 10 }

replset1:SECONDARY>

c.升级2.6.7仲裁节点arbiter1和2.6.7分片2步骤和上边一样不在描述


6.不同版本数据size变化


mongo-2.6.7版本数据:


技术分享



mongo-3.0.3版本数据:

技术分享


总结:**注意最终还是需要停mongos和configdb(mongos和configdb也需要升级,停止几分钟即可)**

Mongo-2.6.7数据升级(导入)为Mongo-3.0.3。数据显示要比老版本少,不确定是不是新的引擎数据有压缩。

 

注意:该环境为测试环境测试,仅供参考。

线上环境升级请在测试环境模拟线上测试,在确认没有问题,再在线上实施。



文章mongodb3.0新特性:

http://www.open-open.com/lib/view/open1427078982824.html#_label3

官方文档:http://docs.mongodb.org/manual/release-notes/3.0/


 


本文出自 “mongodb升级3.0” 博客,请务必保留此出处http://jiachen.blog.51cto.com/3296673/1653846

mongodb2.6.7升级3.03

标签:mongob

原文地址:http://jiachen.blog.51cto.com/3296673/1653846

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!