Netkiller NoSQL Notebook
MongoDB, Cassandra, Redis, CouchBase, Hypertable...
The document was created on 2012-11-16
Copyright © 2010, 2011, 2012, 2013, 2014, 2015 Netkiller(Neo Chan). All rights reserved.
Copyright Notice
Please contact the author for reprinting. When reprinting, please be sure to indicate the original source of the article, author information and this statement.
|
|
|
Scan the QR code on WeChat to enter the Netkiller WeChat subscription account Group: 128659835 Please indicate "reader" |
2.3. Replication
Many tutorials use manual configuration of master-slave replication. I do not recommend you to start this way. Please use the scheme of modifying the /etc/mongod.conf configuration file.
Create master: mongod –port 27017 –dbpath /var/lib/mongodb –master Created from: 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 ] } >