MongoDB 2.6.4 主从同步

WBOY
發布: 2016-06-07 16:43:59
原創
1069 人瀏覽過

MongoDB单机主从模式 1:启动master [linuxidc@linuxidc04 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/linuxidc/mongo

MongoDB单机主从模式

1:启动master

[linuxidc@linuxidc04 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/linuxidc/mongodb-linux-x86_64-2.6.4/data --port 10000 --master
2014-09-05T15:11:50.115+0800 [initandlisten] MongoDB starting : pid=23623 port=10000 dbpath=/home/linuxidc/mongodb-linux-x86_64-2.6.4/data master=1 64-bit host=linuxidc04
2014-09-05T15:11:50.116+0800 [initandlisten] db version v2.6.4
2014-09-05T15:11:50.116+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T15:11:50.117+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-05T15:11:50.117+0800 [initandlisten] allocator: tcmalloc
2014-09-05T15:11:50.117+0800 [initandlisten] options: { master: true, net: { port: 10000 }, storage: { dbPath: "/home/linuxidc/mongodb-linux-x86_64-2.6.4/data" } }
2014-09-05T15:11:50.127+0800 [initandlisten] journal dir=/home/linuxidc/mongodb-linux-x86_64-2.6.4/data/journal
2014-09-05T15:11:50.127+0800 [initandlisten] recover : no journal files present, no recovery needed
2014-09-05T15:11:50.298+0800 [initandlisten] waiting for connections on port 10000

2:启动slave

[linuxidc@linuxidc04 ~]$ mongod --dbpath /home/linuxidc/mongodb-linux-x86_64-2.6.4/data2 --port 10001 --slave --source localhost:10000
2014-09-05T15:12:48.411+0800 [initandlisten] MongoDB starting : pid=23636 port=10001 dbpath=/home/linuxidc/mongodb-linux-x86_64-2.6.4/data2 slave=1 64-bit host=linuxidc04
2014-09-05T15:12:48.412+0800 [initandlisten] db version v2.6.4
2014-09-05T15:12:48.412+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T15:12:48.412+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-05T15:12:48.412+0800 [initandlisten] allocator: tcmalloc
2014-09-05T15:12:48.413+0800 [initandlisten] options: { net: { port: 10001 }, slave: true, source: "localhost:10000", storage: { dbPath: "/home/linuxidc/mongodb-linux-x86_64-2.6.4/data2" } }
2014-09-05T15:12:48.417+0800 [initandlisten] journal dir=/home/linuxidc/mongodb-linux-x86_64-2.6.4/data2/journal
2014-09-05T15:12:48.417+0800 [initandlisten] recover : no journal files present, no recovery needed
2014-09-05T15:12:48.434+0800 [initandlisten] waiting for connections on port 10001
2014-09-05T15:12:49.438+0800 [replslave] repl: syncing from host:localhost:10000

2014-09-05T15:13:48.454+0800 [clientcursormon] mem (MB) res:51 virt:584
2014-09-05T15:13:48.454+0800 [clientcursormon]  mapped (incl journal view):320
2014-09-05T15:13:48.454+0800 [clientcursormon]  connections:0
2014-09-05T15:14:04.315+0800 [replslave] repl:   checkpoint applied 285 operations
2014-09-05T15:14:04.316+0800 [replslave] repl:   syncedTo: Sep  5 15:13:54 540962b2:1

3:显示数据

[linuxidc@linuxidc04 ~]$ mongo localhost:10000
MongoDB shell version: 2.6.4
connecting to: localhost:10000/test
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
>

[linuxidc@linuxidc04 mongodb-linux-x86_64-2.6.4]$ mongo localhost:10001       
MongoDB shell version: 2.6.4
connecting to: localhost:10001/test
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }

4:主写数据

> db.master.insert({uid:1004})
WriteResult({ "nInserted" : 1 })
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
{ "_id" : ObjectId("5409638c0a6617467df195ec"), "uid" : 1004 }
>

从查询数据

[linuxidc@linuxidc04 ~]$ cd mongodb-linux-x86_64-2.6.4
[linuxidc@linuxidc04 mongodb-linux-x86_64-2.6.4]$ mongo localhost:10001       
MongoDB shell version: 2.6.4
connecting to: localhost:10001/test
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
{ "_id" : ObjectId("5409638c0a6617467df195ec"), "uid" : 1004 }
>

--------------------------------------分割线 --------------------------------------

CentOS编译安装MongoDB

CentOS 编译安装 MongoDB与mongoDB的php扩展

CentOS 6 使用 yum 安装MongoDB及服务器端配置

Ubuntu 13.04下安装MongoDB2.4.3

MongoDB入门必读(概念与实战并重)

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

--------------------------------------分割线 --------------------------------------

从机日志

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板