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

MongoDB Master/Slaver configuration

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

Share

Shulou(Shulou.com)06/01 Report--

Get started with MongoDB

This article mainly introduces the configuration of MongoDB Master/Slaver

First create Mongo Master/home/hrj/mongodb-linux-i686-static-1.6.5/bin/mongod-- master-- dbpath / home/hrj/mongodb_data-- auth-- maxConns 50-- port 6688

Secondly, create Mongo Slaver/home/hrj/mongodb-linux-i686-static-1.6.5/bin/mongod-- slave-- source myna5.sds.cnb.yahoo.com:6688-- auth-- maxConns 50-- auth-- port 6689-- fastsync-- autoresync-- dbpath / home/hrj/mongodb_slave_data to create Master, Slaver account ~ / mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.1Vol 6689 # create an account on Slaver

> use local

Switched to db local

> db.addUser ('hrj','xxx')

{

"_ id": ObjectId ("4d6f6527013fcbcc74575c20")

"user": "hrj"

"readOnly": false

"pwd": "b27edaa5a8858aa3d46b60698fce1359"

}

~ / mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.0.1 6688 # create an account on Master

MongoDB shell version: 1.6.5

Connecting to: 127.0.0.1:6688/test

> use local

Switched to db local

> db.addUser ('hrj','xxx')

{

"_ id": ObjectId ("4d6f6527013fcbcc74575c20")

"user": "hrj"

"readOnly": false

"pwd": "b27edaa5a8858aa3d46b60698fce1359"

}

> use test # add account authentication

Switched to db local

> db.auth ('hrj','xxx') loads data into Master to test whether Slaver is synchronized normally # Master

~ / mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.0.1 purl 6688

MongoDB shell version: 1.6.5

Connecting to: 127.0.0.1:6688/test

> db.foo.save ({'mongodb':'hello world'}) # Import data

> db.foo.find () # query data

{"_ id": ObjectId ("4d6f72c6d807e8561b0f3db5"), "mongodb": "hello world"}

# Slaver

~ / mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.0.1pur6689

MongoDB shell version: 1.6.5

Connecting to: 127.0.0.1:6689/test

> db.foo.find () # query Slaver synchronization data

{"_ id": ObjectId ("4d6f72c6d807e8561b0f3db5"), "mongodb": "hello world"}

> db.foo.save ({'mongodb':'hello world test 1'}) # Slaver imports data, prompting "not master"

Not master

So far, Master/Slaver has been debugged successfully. Here is a brief mention of the Master/Slaver special parameters:

Master

-- master master mode

-oplogSize arg size limit (in MB) for oplog

Slave

-- slave slave mode

-- source arg source specifies the master location

-- only arg specifies to back up a certain database separately

-- slavedelay arg specifies the delay time with Master (seconds)

-- autoresync automatically reconnects when Slave data is out of date

Special recommendation:

It is very likely that after the Master server Down is dropped, you need to replace the Master server with the Slave server. At this time, you need to do the following:

Stop the Slave process (mongod) when you delete local.* from the Slave data directory and start Slave in-- master mode, Slave can run as a Master.

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