MongoDB replication study notes 9--

1) Basic Concepts

Replication may be used to achieve scalability, sustainability / reliability and isolation.

Replication normally used to prevent hardware failure or database corruption, while providing flexibility for backup and other maintenance activities have a significant impact, resulting in little or no effect on the system only.

Replication include: master / slave replication, the master / master replication, replication pair.

2) server

Server Type:

Master: copy source data set within a specific time. The only focus is to copy nodes can be written, and all other nodes have a copy here from their data.

Secondary server: a master server has a non-member data, it could theoretically become the primary server. A node is read, while it copies data from the primary server in real time as close as possible.

Arbitration server: Arbitration is a server node does not contain data, if the copy number of the members of the initiative focus is even, it is used to provide additional active members. It does not cast the deciding vote or directly determine which node is the master server, but will participate as members of a primary, which decided to become the primary server node. Arbitration server can be used to avoid "split brain" problem.

3) in-depth study oplog

oplog (operation log) is a collection of a fixed size, holds the primary server instance to make changes to the database record, the aim redo operations on the secondary server to ensure that the database in a consistent state.

oplog generally has a fixed size.

If oplog current instance has not been created, use --oplogSize startup option can be set oplog size. Linux and Windows64-bit systems, oplogSize default setting is 5% of the available disk space, a minimum of 1GB, up to 50GB.

When calculating critical oplog of appropriate size, considering the frequency of updating all databases on the primary server. By performing db.printReplicationInfo () command to get some reference size oplog area.

4) implement a replication set

A copy set by the primary server, or a plurality of secondary servers arbitration servers.

Copy the set also provides passive and active members of the members. When the current primary server is unavailable, the passive server does not participate in the election of the new primary server; instead, they can vote against the primary server qualification of a member.

4-1) Creating a replication set

Usually used when the amplitude set is the host name. You can find the current hostname by the hostname command.

4-2) to start replica set member

$ Mkdir -p / dp / active1 / data (active)

$ mongod --dbpath /db/active1/data --port 27021 -replSet testset

$ Mkdir -p / dp / passive1 / data (passive)

$ mongod --dbpath /db/active1/data --port 27022 -replSet testset

Initialization replication set:

rs.initiate()

4-3) add a server to a replication set

rs.add("[hostname]:27021")

Use rs.status () you can monitor progress.

If you need to copy the configuration file and modify it can be used:

conf = rs.conf()

If you want to set as hidden nodes, and the priority is 0, so it will not be elected based server, the command operates as follows (with the third element, for example):

conf.members[2].hidden = true

conf.members[2].priority = 0

conf.members[2].votes = 0

The new configuration file as an argument, you can do rs.reconfig () command, rs.reconfig (conf).

4-4) Add arbitration server

$ Mkdir -p / dp / arbiter1 / data (passive)

$ mongod --dbpath /db/arbiter1/data --port 27023 -replSet testset -rest

Use rs.addArb () command to add a new quorum server:

rs.addArb("[hostname]:27023")

4-5) replication set chain

Copy Set chain in MongoDB is the default behavior

conf.chainingAllowed = false

4-6) manage the replication set

Use rs.Status () state detection example

Use rs.stepDown () to force new elections. Use this command to force the host server to exit 60 seconds; the command will force the election of a new master. rs.stepDown () command also has two optional parameters, the first is used to determine the current master server stepDownSeconds prohibited election when long dominated the server again. The second is catchUpPerid representation before the elections the new primary server should wait for long seconds before copying.

Use db.isMaster () to determine whether a member-based server.

Guess you like

Origin www.cnblogs.com/zhuozige/p/12503393.html