MongoDB主从复制小实验
MongoDB主从复制小实验操作环境描述:WIN8 64位操作系统,内装虚拟机为CentOS 5.5 32位系统。操作描述:跟其他关系型数据库类似,在主库进行数据操作,将数据同步到从节点,从节点可以配置多个。在本次试验中,master节点为主节点,我们在master节点中的对数据的插入、修改、删除操作都会同步到slave1和slave2节点。以下为实验步骤:(1)建立数据目录,数据目录用来存放过程中的数据。[plain][root@h3 dbs]# pwd/var/lib/mongo/dbs[root@h3 dbs]# lsmaster slave1 slave2[root@h3 dbs]#(2)启动master节点:[plain]启动master[root@h3 dbs]# mongod --dbpath /var/lib/mongo/dbs/master --port 10000 --master --rest --nojournalFri Aug 2 14:10:25.498 [initandlisten] MongoDB starting : pid=19491 port=10000 dbpath=/var/lib/mongo/dbs/master master=1 32-bit host=h3Fri Aug 2 14:10:25.498 [initandlisten]Fri Aug 2 14:10:25.498 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.Fri Aug 2 14:10:25.498 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).Fri Aug 2 14:10:25.498 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.Fri Aug 2 14:10:25.499 [initandlisten] ** See http://dochub.mongodb.org/core/32bitFri Aug 2 14:10:25.499 [initandlisten]Fri Aug 2 14:10:25.500 [initandlisten] db version v2.4.5Fri Aug 2 14:10:25.500 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602bFri Aug 2 14:10:25.500 [initandlisten] build info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49Fri Aug 2 14:10:25.500 [initandlisten] allocator: systemFri Aug 2 14:10:25.500 [initandlisten] options: { dbpath: "/var/lib/mongo/dbs/master", master: true, nojournal: true, port: 10000, rest: true }Fri Aug 2 14:10:25.540 [FileAllocator] allocating new datafile /var/lib/mongo/dbs/master/local.ns, filling with zeroes...Fri Aug 2 14:10:25.542 [FileAllocator] creating directory /var/lib/mongo/dbs/master/_tmpFri Aug 2 14:10:26.094 [FileAllocator] done allocating datafile /var/lib/mongo/dbs/master/local.ns, size: 16MB, took 0.545 secsFri Aug 2 14:10:26.094 [FileAllocator] allocating new datafile /var/lib/mongo/dbs/master/local.0, filling with zeroes...Fri Aug 2 14:10:26.763 [FileAllocator] done allocating datafile /var/lib/mongo/dbs/master/local.0, size: 16MB, took 0.667 secsFri Aug 2 14:10:26.785 [initandlisten] command local.$cmd command: { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 reslen:37 12 45msFri Aug 2 14:10:26.796 [initandlisten] ******Fri Aug 2 14:10:26.796 [initandlisten] creating replication oplog of size: 50MB...Fri Aug 2 14:10:26.799 [FileAllocator] allocating new datafile /var/lib/mongo/dbs/master/local.1, filling with zeroes...Fri Aug 2 14:10:30.116 [FileAllocator] done allocating datafile /var/lib/mongo/dbs/master/local.1, size: 64MB, took 3.314 secsFri Aug 2 14:10:30.243 [initandlisten] ******Fri Aug 2 14:10:30.245 [initandlisten] waiting for connections on port 10000Fri Aug 2 14:10:30.247 [websvr] admin web console waiting for connections on port 11000Fri Aug 2 14:16:52.604 [initandlisten] connection accepted from 127.0.0.1:33749 #1 (1 connection now open)Fri Aug 2 14:16:53.885 [slaveTracking] build index local.slaves { _id: 1 }Fri Aug 2 14:16:53.894 [slaveTracking] build index done. scanned 0 total records. 0.008 secs(3)启动slave1节点:[plain][root@h3 ~]# mongod -dbpath /var/lib/mongo/dbs/slave1 --port 10001 --slave --rest --nojournal --source localhost:10000Fri Aug 2 14:16:50.050 [initandlisten] MongoDB starting : pid=19513 port=10001 dbpath=/var/lib/mongo/dbs/slave1 slave=1 32-bit host=h3Fri Aug 2 14:16:50.051 [initandlisten]Fri Aug 2 14:16:50.052 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.Fri Aug 2 14:16:50.053 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).Fri Aug 2 14:16:50.053 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.Fri Aug 2 14:16:50.054 [initandlisten] ** See http://dochub.mongodb.org/core/32bitFri Aug 2 14:16:50.055 [initandlisten]Fri Aug 2 14:16:50.055 [initandlisten] db version v2.4.5Fri Aug 2 14:16:50.056 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602bFri Aug 2 14:16:50.056 [initandlisten] build info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49Fri Aug 2 14:16:50.057 [initandlisten] allocator: systemFri Aug 2 14:16:50.058 [initandlisten] options: { dbpath: "/var/lib/mongo/dbs/slave1", nojournal: true, port: 10001, rest: true, slave: true, source: "localhost: 10000" }Fri Aug 2 14:16:50.080 [FileAllocator] allocating new datafile /var/lib/mongo/dbs/slave1/local.ns, filling with zeroes...Fri Aug 2 14:16:50.081 [FileAllocator] creating directory /var/lib/mongo/dbs/slave1/_tmpFri Aug 2 14:16:50.520 [FileAllocator] done allocating datafile /var/lib/mongo/dbs/slave1/local.ns, size: 16MB, took 0.412 secsFri Aug 2 14:16:50.521 [FileAllocator] allocating new datafile /var/lib/mongo/dbs/slave1/local.0, filling with zeroes...Fri Aug 2 14:16:51.512 [FileAllocator] done allocating datafile /var/lib/mongo/dbs/slave1/local.0, size: 16MB, took 0.989 secsFri Aug 2 14:16:51.520 [initandlisten] command local.$cmd command: { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 reslen:37 14 41msFri Aug 2 14:16:51.524 [websvr] admin web console waiting for connections on port 11001Fri Aug 2 14:16:51.525 [initandlisten] waiting for connections on port 10001Fri Aug 2 14:16:52.577 [replslave] build index local.sources { _id: 1 }Fri Aug 2 14:16:52.583 [replslave] build index done. scanned 0 total records. 0.004 secsFri Aug 2 14:16:52.595 [replslave] repl: syncing from host:localhost:10000Fri Aug 2 14:16:52.657 [replslave] build index local.me { _id: 1 }Fri Aug 2 14:16:52.662 [replslave] build index done. scanned 0 total records. 0.004 secsFri Aug 2 14:19上一个:redis数据库学习笔记
下一个:使用mongofiles操作GridFS
- 更多mongodb疑问解答:
- 【急】MongoDB写入错误~~~~
- Mongodb NOSql 数据库问题,是否可以插入带接口的类
- java操作mongodb
- Spring data MongoDB 更新整个内嵌文档时报错???????
- node.js连接mongodb更新
- MongoDB Java驱动 WriteConcern.SAFE非常浪费资源
- 求科普,hibernate怎样操作mongodb?
- 问一下mongodb怎么用hibernate整合
- mongodb查询的数据过多
- 使用JAVA创建MongoDB的问题
- Mongodb事务管理问题?
- mongodb利用java进行模糊查询
- spring 抽象类 注入值为空(spring3+mongodb+morphia)
- 【急】MongoDB写入错误~~~~
- Mongodb NOSql 数据库问题,是否可以插入带接口的类