最近一个业务需要进行升级,之前的版本是1.6,我准备升级到最新的2.0.5,而且原来用的pair,到了2.0.5当然要使用replica set<wbr style=""><div style="">升级已经转换步骤:</div> <div style="">1.对原来pair中slave数据库进行重建,slave转换成replica sets的主节点</div> <div style="">2.停止服务,把master的数据迁移至转换的主节点。</div> <div style="">3.启动服务连接至新建的主节点。</div> <div style="">4.对pair中master数据库进行重建,在主节点中将新建的replica set从节点加入即可。</div> <div style=""> <div style="line-height:25px">mongod --replSet=rep1 -f /opt/mongodata/conf/mongod.conf</div> <div style="line-height:25px">配置文件内容如下:</div> <div style="line-height:25px">logpath=/var/log/mongo/mongod.log</div> <div style="line-height:25px">logappend=true</div> <div style="line-height:25px">fork = true</div> <div style="line-height:25px">port = xxxx</div> <div style="line-height:25px">dbpath = /opt/mongodata</div> <div style="line-height:25px">noauth = true</div> <div style="line-height:25px">nohttpinterface = true</div> <div style="line-height:25px">nssize = 128</div> <div style="line-height:25px">directoryperdb = true</div> <div style="line-height:25px">maxConns = 1500</div> <div style="line-height:25px">oplogSize = 10240</div> <div style="line-height:25px">journal = true</div> <div style="line-height:25px">journalCommitInterval = 40</div> <div style="line-height:25px">pidfilepath = /opt/mongodata/conf/mongod_xxxx.pid</div> <div style="line-height:25px">登录新建的主节点:</div> <div style="line-height:25px">mongod 127.0.0.1:xxxx/admin</div> <div style="line-height:25px">rs.initiate({</div> <div style="line-height:25px"> "_id" : "rep1",</div> <div style="line-height:25px"> "version" : 1,</div> <div style="line-height:25px"> "members" : [</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> "_id" : 0,</div> <div style="line-height:25px"> "host" : "192.168.168.100:1234",</div> <div style="line-height:25px"> "priority" : 1</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> ]</div> <div style="line-height:25px">})</div> <div style="line-height:25px">加好以后可以通过rs.conf()等等一些命令看下相关信息,rs.help()可以看下帮助命令</div> <div style="line-height:25px">关闭原pair中master,通过mongoexpport等一些导入导出的命令进行数据迁移至上面新建的节点</div> <div style="line-height:25px">开启服务连接新建的主节点</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px">从节点和主节点配置一样,启动后,继续到主节点添加从节点</div> <div style="line-height:25px">rs.reconfig({</div> <div style="line-height:25px"> "_id" : "rep1",</div> <div style="line-height:25px"> "version" : 1,</div> <div style="line-height:25px"> "members" : [</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> "_id" : 0,</div> <div style="line-height:25px"> "host" : "192.168.168.100:1234",</div> <div style="line-height:25px"> "priority" : 1</div> <div style="line-height:25px"> },</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> "_id" : 1,</div> <div style="line-height:25px"> "host" : "192.168.168.101:1234"</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> ]</div> <div style="line-height:25px">})</div> </div> <div style="">这里101就是新加的从节点。从节点启动后,先是recovery状态,数据量大可能会消耗一些时间,recovery后,会变成secondary。</div> </wbr>
1.6 pair convert 2.0 replica sets
最新推荐文章于 2024-08-31 23:36:42 发布