Coin163

首页 > MongoDB 主从配置

MongoDB 主从配置

相关标签: netkiller, mongodb, nosql,

相关推荐:MongoDB主从配置是否可行

Hi,主 4G RAM, 100G SSD从2G RAM, 100G SSD.网站流量不大,读写都是由主机,从机仅仅是为了冗余备份。问题: 这样能保证强一致性性吗?PHP写操作要不要加fsync = truethanks

Netkiller NoSQL 手札MongoDB, Cassandra, Redis, CouchBase, Hypertable...Mr. Neo Chan, 陈景峰(BG7NYT)中国广东省深圳市龙华新区民治街道溪山美地518131+86 13113668890<netkiller@msn.com>文档始创于2012-11-16版权 © 2010, 2011, 2012, 2013, 2014, 2015 Netkiller(Neo Chan). All rights reserved.版权声明转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。文档出处:http://netkiller.github.iohttp://netkiller.sourceforge.net微信扫描二维码进入 Netkiller 微信订阅号群:128659835 请注明“读者”

2.3. Replication很多教程上面采用手工配置主从复制,我不建议你这样启动,请采用修改/etc/mongod.conf配置文件的方案。创建主:mongod –port 27017 –dbpath /var/lib/mongodb –master 创建从:mongod –port 27017 –dbpath /var/lib/mongodb –slave –source master_ip_address:27017

2.3.1. Mastersed -i "s/#master = true/master = true/" /etc/mongod.confsystemctl restart

mongod

2.3.2. Slavesed -i "s/#slave = true/slave = true/" /etc/mongod.confsed -i "s/#source = arg/source = mongodb.master.example.com/" /etc/mongod.confsystemctl restart

mongod

2.3.3. 测试进入 Master

[root@localhost ~]# mongoMongoDB shell version: 2.6.11connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, see http://docs.mongodb.org/Questions? Try the support group http://groups.google.com/group/mongodb-userServer has startup warnings:2015-11-14T15:51:21.215+0800 [initandlisten]2015-11-14T15:51:21.215+0800 [initandlisten] ** WARNING: Readahead for /var/lib/mongodb is set to 4096KB2015-11-14T15:51:21.215+0800 [initandlisten] **

We suggest setting it to 256KB (512 sectors)

相关推荐:MongoDB 主从复制配置

MongoDB 主从复制配置原文出处:http://blog.chenlb.com/2010/03/mongodb-master-slave.htmlMongoDB 主从复制与 Mysql 类似。在主服务器上加--master 选项启动。bin/mongod --dbpath=/home/mongodb/db --master --oplogSize 64--oplogSize 指定操

or less2015-11-14T15:51:21.215+0800 [initandlisten] **

http://dochub.mongodb.org/core/readahead>>> db.foo.save({'name':'neo','address':{'city':'shenzhen','post':518000},'phone':[13113668890,13322993040]})WriteResult({ "nInserted" : 1 })> db.foo.find();{ "_id" : ObjectId("5646e881a11081d5998bf70c"), "name" : "neo", "address" : { "city" : "shenzhen", "post" : 518000 }, "phone" : [ 13113668890, 13322993040 ] }>

进入 Slave

[root@localhost ~]# mongoMongoDB shell version: 2.6.11connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, see http://docs.mongodb.org/Questions? Try the support group http://groups.google.com/group/mongodb-userServer has startup warnings:2015-11-14T15:51:23.668+0800 [initandlisten]2015-11-14T15:51:23.668+0800 [initandlisten] ** WARNING: Readahead for /var/lib/mongodb is set to 4096KB2015-11-14T15:51:23.668+0800 [initandlisten] **

We suggest setting it to 256KB (512 sectors) or less2015-11-14T15:51:23.668+0800 [initandlisten] **

http://dochub.mongodb.org/core/readahead> db.foo.find();{ "_id" : ObjectId("5646e881a11081d5998bf70c"), "name" : "neo", "address" : { "city" : "shenzhen", "post" : 518000 }, "phone" : [ 13113668890, 13322993040 ] }>

Netkiller NoSQL 手札MongoDB, Cassandra, Redis, CouchBase, Hypertable...Mr.?Neo?Chan,?陈景峰(BG7NYT)中国广东省深圳市龙华新区民治街道溪山美地518131+86?13113668890...

------分隔线----------------------------