向Mongodb集群添加新的成员节点向集群添加新节点有两种方法:方法第一种方法拷贝其他节点的数据文件到新的节点第二种方法向已有的replicaset添加新成员一.第一种方法(拷贝其他节点的数据文件到新的节点)我们在启动mongod服务之前一定要拷贝数据文件到本机。下面是空库添加到一个replicaset中的日志记录:第一步:####连接Primary库TueNov114:22:57[initandlisten]connectionacceptedfrom10.250.7.220:54235#2TueNov114:22:57[initandlisten]connectionacceptedfrom10.250.7.220:54236#3TueNov114:22:57[initandlisten]connectionacceptedfrom10.250.7.220:54237#4TueNov114:22:57[rsStart]tryingtocontact10.250.7.220:27018TueNov114:22:57[rsStart]tryingtocontact10.250.7.220:27019TueNov114:22:57[rsStart]tryingtocontact10.250.7.220:27020第二步:####从primary库复制replicaset的配置信息,并保存到本地-dbpath指定的文件目录####TueNov114:22:57[rsStart]replSetgotconfigversion2fromaremote,savinglocallyTueNov114:22:57[rsStart]replSetinfosavinganewerconfigversiontolocal.system.replsetTueNov114:22:57[FileAllocator]allocatingnewdatafile/opt/mongodata/r1/local.ns,fillingwithzeroes...TueNov114:22:57[FileAllocator]creatingdirectory/opt/mongodata/r1/_tmpTueNov114:22:57[FileAllocator]doneallocatingdatafile/opt/mongodata/r1/local.ns,size:16MB,took0.118secsTueNov114:22:57[FileAllocator]allocatingnewdatafile/opt/mongodata/r1/local.0,fillingwithzeroes...TueNov114:23:01[FileAllocator]doneallocatingdatafile/opt/mongodata/r1/local.0,size:64MB,took3.807secsTueNov114:23:01[FileAllocator]allocatingnewdatafile/opt/mongodata/r1/local.1,fillingwithzeroes...TueNov114:23:02[rsStart]replSetsaveConfigLocallydoneTueNov114:23:02[FileAllocator]doneallocatingdatafile/opt/mongodata/r1/local.1,size:128MB,took1.068secsTueNov114:23:02[rsStart]replSetSTARTUP2TueNov114:23:02[rsMgr]replSettotalnumberofvotesiseven-addarbiterorgiveonememberanextravoteTueNov114:23:02[rsSync]******第三步:####创建oplog日志文件####TueNov114:23:02[rsSync]creatingreplicationoplogofsize:944MB...TueNov114:23:02[FileAllocator]allocatingnewdatafile/opt/mongodata/r1/local.2,fillingwithzeroes...TueNov114:23:04[rsHealthPoll]replSetinfomember10.250.7.220:27018isupTueNov114:23:04[rsHealthPoll]replSetmember10.250.7.220:27018isnowinstateSECONDARYTueNov114:23:04[rsHealthPoll]replSetinfomember10.250.7.220:27019isupTueNov114:23:04[rsHealthPoll]replSetmember10.250.7.220:27019isnowinstateSECONDARYTueNov114:23:04[rsHealthPoll]replSetinfomember10.250.7.220:27020isupTueNov114:23:04[rsHealthPoll]replSetmember10.250.7.220:27020isnowinstatePRIMARYTueNov114:23:49[FileAllocator]doneallocatingdatafile/opt/mongodata/r1/local.2,size:1024MB,took46.28secsTueNov114:23:50[rsSync]******第四步:####应用主库的日志,复制数据文件####TueNov114:23:50[rsSync]replSetinitialsyncpendingTueNov114:23:50[rsSync]replSetsyncingto:10.250.7.220:27020TueNov114:23:50[rsSync]buildindexlocal.me{_id:1}TueNov114:23:50[rsSync]buildindexdone0records0.003secsTueNov114:23:50[rsSync]replSetinitialsyncdropalldatabasesTueNov114:23:50[rsSync]dropAllDatabasesExceptLocal1TueNov114:23:50[rsSync]replSetinitialsyncclonealldatabasesTueNov114:23:50[rsSync]replSetinitialsynccloningdb:testTueNov114:23:50[FileAllocator]allocatingnewdatafile/opt/mongodata/r1/test.ns,fillingwithzeroes...TueNov114:23:51[FileAllocator]doneallocatingdatafile/opt/mongodata/r1/test.ns,size:16MB,took0.8secsTueNov114:23:51[FileAllocator]allocatingnewdatafile/opt/mongodata/r1/test.0,fill...