Two features of mongoDB: master-slave replication and replica set

Source: Internet
Author: User
1. Master-slave replication 1. master-slave replication is a simple cluster technology for Database Synchronization and backup. 1.1 In the database cluster, you must clearly know who is the master server. The master server has only one. 1.2 The slave server needs to know its own data source, that is, who is responsible for the master service. 1.3 -- master is used to determine the master server, -- slave and-source are used to control slave server 1.

1. Master-slave replication 1. master-slave replication is a simple cluster technology for Database Synchronization and backup. 1.1 In the database cluster, you must clearly know who is the master server. The master server has only one. 1.2 The slave server needs to know its own data source, that is, who is responsible for the master service. 1.3 -- master is used to determine the master server, -- slave and-source are used to control slave server 1.

I. Master-slave Replication

1. Master-slave replication is a simple cluster technology for Database Synchronization and backup.

1.1 In the database cluster, you must clearly know who is the master server. The master server has only one.

1.2 The slave server needs to know its own data source, that is, who is responsible for the master service.

1.3 -- master is used to determine the master server, -- slave and-source are used to control the slave server

1. Master-slave replication cluster case

2. Other settings of master-slave Replication

-- Only copies a database from a node. By default, all databases are copied.

-- Slavedelay slave node-> set the delay (in seconds) for data synchronization from the master database)

-- Fastsync from node-> Start from database with the master database node snapshot as the node

-- Autoresync slave node-> if it is not synchronized, the database will be synchronized from the new

-- OplogSize master node-> set the oplog size (the master node operation records are stored in the local oplog)

3. dynamically add and delete slave nodes using shell

It is not hard to see that all information about the master node is stored in the sources set of the local node.

You only need to perform operations on the set to dynamically operate the master-slave relationship.

Mount the master node: only the slave Database Service is left before the operation.

Db. sources. insert ({"host": "127.0.0.1: 8888 "})

Delete the connected master node: only the slave Database Service is left before the operation.

Db. sources. remove ({"host": "127.0.0.1: 8888 "})

Ii. Replica Set Concept

1.1 The first figure shows that A is active. B and C are used for backup.

1.2 When A fails, the cluster selects B as an active database based on the weight algorithm.

1.3 The third figure will automatically become A backup database after A recovers

2. initialize the replica set

Use admin

Db. runCommand ({"replSetInitiate ":

{

"_ Id": 'child ',

"Members ":[{

"_ Id": 1,

"Host": "127.0.0.1: 1111"

},{

"_ Id": 2,

"Host": "127.0.0.1: 2222"

},{

"_ Id": 3,

"Host": "127.0.0.1: 3333"

}]

}

})

2. View replica set status

Rs. status ()

3. node and initialization advanced Parameters

Standard common nodes: participating in voting may become active nodes

Passive copy node: participates in voting, but cannot become an active node

Arbiter arbitration node: nodes that participate in voting, do not copy, or become active nodes.

4. Advanced Parameters

Priority: 0 to 1000. 0 indicates a copy node, and 1 to 1000 indicates a regular node.

ArbiterOnly: true arbitration Node

Usage

Members ":[{

"_ Id": 1,

"Host": "127.0.0.1: 1111",

ArbiterOnly: true

}]"

5. Rules set for arbitration when the priority is the same

When the priorities are the same, it will be based on the time. For example, when A is an active node and B and C is A replica set,

When A goes down, mongo selects the most recent update time in B and C as the active node.

6. read/write Splitting Operation à extended read

6.1 generally, database read operations cannot be performed on nodes that act as copies.

However, read/write splitting is necessary in read-intensive systems.

6.2 set read/write splitting

SlaveOkay: true

Unfortunately, it cannot be concealed in shell. This feature is written to mongoDB.

In the driver, it can be completed in other languages such as java and node.

7. Oplog

He is stored in the local database, and each of his documents ensures the operation of this node

If you want to recover from a fault, you can perform a more thorough oplog. You can try to set a larger value to save more operations.

Information

Change oplog size

Master database -- master -- oplogSize size

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.