Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The realization of MongoDB Master and Slave

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "the realization of the master and slave of MongoDB". In the daily operation, I believe that many people have doubts about the realization of the master and slave of MongoDB. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "the realization of MongoDB master and slave". Next, please follow the editor to study!

Briefly introduce the way of MongoDB master-slave implementation.

Environment:

Operating system: CentOS 6.7

MongoDB: 3.4.5

Master data directory: / data/mongomaster

From the data directory: / data/mongoslave

MongoDB management commands environment variables:

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

Start the master

Mongod-dbpath=/data/mongomaster/-port 10000-master-logpath=/data/mongomaster/masterlog-logappend-forkbout to fork child process, waiting until server is ready for connections.forked process: 3114child process started successfully, parent exiting [root@bogon data] #

Start from

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

The test creates a mongo library winne collection on top of the main library to insert document data

> use mongoswitched to dbmongo > show dbsadmin 0.000GBlocal 0.003GBmaster 0.002GB > dbmongo > for

Slave library test

> show dbs2017-05-20T14:14:42.526+0800 E QUERY [thread1] Error: listDatabases failed: {"ok": 0, "errmsg": "not master and slaveOk=false", "code": 13435 "codeName": "NotMasterNoSlaveOk"}: _ getErrorWithCode@src/mongo/shell/utils.js:25:13Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1shellHelper.show@src/mongo/shell/utils.js:769:19shellHelper@src/mongo/shell/utils.js:659:15@ (shellhelp2): 1:1

What did you report wrong? Look for information or something, not master and slaveOk=false and NotMasterNoSlaveOk randomly search the key information, and it turns out that many errors are reported, saying that the master slave library does not support reading and writing by default, such as Redis does not support writing, MongoDB is more magical, can not be read directly, from the slave library simple configuration, and then take a look.

2017-05-20T14:17:40.067+0800 E QUERY [thread1] SyntaxError: illegal character @ (shell): 1:1 > rs.slaveOk () > show dbsadmin 0.000GBlocal 0.000GBmaster 0.002GBmongo 0.000GB2017-05-20T14:17:40.067+0800 E QUERY [thread1] SyntaxError: illegal character @ (shell): 1:1 > rs.slaveOk () > show dbsadmin 0.000GBlocal 0.000GBmaster 0.002GBmongo 0.000GB

Verified data synchronization

At this point, the study of "the realization of MongoDB master and slave" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report