MongoDB master-slave synchronization and Backup Recovery

Source: Internet
Author: User

Master-slave synchronization:

1. Create a database directory

Mkdir/mongodb/masterdb

Mkdir/mongodb/slavedb_1

Mkdir/mongodb/slavedb2.

2. Start the Master/Slave servers respectively.
Start the master server to listen to port 10000

./Bin/mongod-dbpath/mongodb/masterdb/-- port10000 -- master
You can also use master-> slave settings to start two slave servers with ports 10001 and 10002 respectively.

./Bin/mongod-dbpath/mongodb/slavedb_1 -- source localhost: 10000 -- slave -- port 10001

./Bin/mongod-dbpath/mongodb/slavedb2-source localhost: 10000 -- slave -- port 10002

# After startup, you will see a log showing the copied content from the master server.

Related Parameters:./mongod -- help
-- Autoresync when the slave server data is not the latest, the master server requests data synchronization.
-- Slavedelay synchronization delay, in seconds


3. Test Master/Slave
A. Create a database on the master server

./Bin/mongo -- port 10001

Show dbs

# Only the system database is in it. If you insert data, the system prompts not master.

Use testdb

Db. blog. save ({title: "newarticle "})

B. view the synchronized data on the slave server

./Bin/mongo -- port 10001

MongoDB shell version: 1.6.0

Connecting to: 127.0.0.1: 10001/test

> Show dbs

Admin

Local

Testdb

> Use testdb

Switched to db testdb

> Db. blog. find ()

{"_ Id": ObjectId ("4c776ccce7af0727ce4b6234"), "title": "newarticle"} # the synchronized data is tested successfully.

  • 1
  • 2
  • Next Page

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.