Netkiller NoSQL 手札
MongoDB, Cassandra, Redis, CouchBase, Hypertable...
文档始创于2012-11-16
版权 © 2010, 2011, 2012, 2013, 2014, 2015 Netkiller(Neo Chan). All rights reserved.
版权声明
转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。
|
|
|
微信扫描二维码进入 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
sed -i "s/#slave = true/slave = true/" /etc/mongod.conf sed -i "s/#source = arg/source = mongodb.master.example.com/" /etc/mongod.conf systemctl restart mongod
进入 Master
[root@localhost ~]# mongo MongoDB shell version: 2.6.11 connecting to: test Welcome 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-user Server 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 4096KB 2015-11-14T15:51:21.215+0800 [initandlisten] ** We suggest setting it to 256KB (512 sectors) or less 2015-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 ~]# mongo MongoDB shell version: 2.6.11 connecting to: test Welcome 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-user Server 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 4096KB 2015-11-14T15:51:23.668+0800 [initandlisten] ** We suggest setting it to 256KB (512 sectors) or less 2015-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 ] } >