MongoDB Master-Slave

Source: Internet
Author: User

Data storage is a very important part of the entire system, in MySQL, Redis has a master-slave architecture, to a certain extent, to ensure the security of data and high availability, and MongoDB is also the implementation of this way. Master-Slave configuration is very simple, but with the development of technology has rarely adopted a master-slave architecture, and more is the use of replica sets or cluster mode to achieve high availability.

A simple introduction to MongoDB master-slave implementation of the Way and

Environment:

Operating system: CentOS 6.7

mongodb:3.4.5

Master Data Catalog:/data/mongomaster

From the Data Catalog:/data/mongoslave

MongoDB Management Command Environment variables:

Export path= "$PATH:/home/mongodb/mongodb/mongodb-3.4.5/bin"

Start the main

Mongod--dbpath=/data/mongomaster/--port 10000--master--logpath=/data/mongomaster/masterlog--logappend--fo Rkbout to fork child process, waiting until server are ready for connections.forked Process:3114child process started SUCC essfully, parent Exiting[[email protected] data]#

Start from

Mongod--dbpath=/data/mongoslave/--logpath=/data/mongoslave/slave.log--logappend--port 10002--slave--source 192.168.1.130:10000--forkabout to fork child process, waiting until server was ready for connections.forked process:314 4child process started successfully, parent exiting

Test Create MONGO Library Winne collection insert document data on Main library

> Use mongoswitched to DB mongo> show Dbsadmin 0.000GBlocal 0.003GBmaster 0.002gb> dbmongo> for (I=0;I&L t;10000;i++) Db.mongo.insert ({"name": "Linux"}, {"Object": "Docker"}, {"Age": i}) Writeresult ({"ninserted": 1}) >

Test from Library

> Show dbs2017-05-20t14:14:42.526+0800 E QUERY [thread1] error:listdatabases failed:{"OK": 0, "errmsg": "Not mast ER and Slaveok=false "," code ": 13435," codename ":" Notmasternoslaveok "}: [Email protected]/mongo/shell/utils.js:25:13[ Email Protected]/mongo/shell/mongo.js:62:1[email protected]/mongo/shell/utils.js:769:19[email protected]/mongo/ shell/utils.js:659:15@ (SHELLHELP2): 1:1,

What happened to the error? Looking for information and so on, key information not master and Slaveok=false and Notmasternoslaveok random search, the result is a lot of this error, are said that the default from the library does not support read-write, such as Redis is not supported write, MongoDB is more magical, directly unreadable, from a simple configuration from the library, and then look.

2017-05-20t14:17:40.067+0800 E QUERY [Thread1] syntaxerror:illegal character @ (Shell):1:1> Rs.slaveok () > Show D Bsadmin 0.000GBlocal 0.000GBmaster 0.002GBmongo 0.000gb2017-05-20t14:17:40.067+0800 E QUERY [Thread1] Syntaxerro R:illegal character @ (Shell):1:1> Rs.slaveok () > Show dbsadmin 0.000GBlocal 0.000GBmaster 0.002GBmongo 0.000 GB

Verified Data Synchronization

This article is from the "Keep Dreaming" blog, please be sure to keep this source http://dreamlinux.blog.51cto.com/9079323/1942212

MongoDB Master-Slave

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.