In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MongoDB Replica Set is a master-slave replication and highly available scheme officially recommended by MongoDB, which is used to replace the original Master-Slave master-slave replication scheme. Replicat Set has an automatic switching function. When the Primary is down, one of the Secondary in the Replica Set can automatically switch to Primary to achieve high availability, unlike MySQL, which does not require the use of third-party software.
At present, many game companies have begun to use MongoDB as the database, our company online version is 2.4.6.
The principle of one MongoDB Replica Set
Replication is mainly used for backup, disaster recovery, and read-write separation. A Replica Set is a set of mongod instances. Primary in Replica Set receives all write operations, and Secondaries copies operations from Primary and applies them to its own data set.
There are three member roles in a Replica Set: Primary,Secondary and Arbiter.
Primary receives all writes from the client, and there is one and only one Primary in a Replica Set. If Primary goes down, Replica Set automatically elects a Secondary to become Primary. Primary records all operations of its data sets to oplog.
Secondary Secondary copies the oplog from Primary and then applies the operations in oplog to its own data sets. There is asynchronous replication between Secondary and Primary, that is, the data in Secondary may not be up-to-date. By default, Secondary is not readable or writable, but you can set up the run client to read from Secondary.
Arbiter Arbiter does not need to maintain its own data sets, but participates in a vote to choose which Secondary can be upgraded to Primary when the Primary is dead. When the number of members in the Replica Set is even, you need to add an Arbiter to vote for which can be upgraded to Primary. Arbiter has very low requirements for hardware. You cannot run Arbiter on a Primary or Secondary host.
A Replica Set can have up to 12 members, but only 7 members can vote as Primary at the same time. If the number of members exceeds 12, you need to use Master-Slave master-slave replication.
Deploying a Replica Set requires at least three members, one Arbiter, one Secondary and one Primary or one Primary and two Secondary.
Secondary can be configured for the following special purposes:
a. It is prevented from becoming Primary in the election and is used only as backup data. This is achieved by setting the priority priority to 0.
b. Prevent the application from reading from it by setting the priority priority to 0 and setting hidden to true.
A hidden member also copies Primary's data, but it is not visible to the client application.
c. Retain the historical mirror data for data rollback. For example, if you delete the data by mistake, you can use the data recovery in the Delayed Replica Set member.
Delayed members means that delay members delay copying oplog from Primary
II. MongoDB Replica Set deployment architecture
Replica Set Elections replica set election
Replica Set votes to determine which member can be upgraded to Primary. An election occurs after initializing a Replica Set, or at any time when Primary is not available. It should be noted that voting for the Primary takes a certain amount of time to complete, during which time the entire Replica Set cannot be written, so try to avoid revoting.
The factors and conditions that affect the election are:
Heartbeats heartbeat detection
A member in a Replica Set sends a heartbeat to another member every 2 seconds, and if there is no response within 10 seconds, the member is marked as unavailable by the other member.
Priortiy Comparisons comparison priority
Setting the priority priority of members will affect the voting. The higher the priority, the easier it is to be elected as Primary. If the priority is set to 0, the member will never be elected as Primary, nor does it require other members to vote for it.
Optime
Optime is the timestamp of the last time a member of Replica Set applied an operation from oplog to data sets. A member will not become a Primary unless it has the latest timestamp than other visible members.
Connections
If a member of a Replica Set wants to be a Primary, it must be able to connect to most of the members of the Replica Set who have the right to vote.
Network Partitions
In order to prevent the entire Replica Set from being unable to elect a new Primary,Replica Set to become read-only when the Primary goes down, you need to place most of the member instances of the Replica Set in a data center.
Reference documentation
Http://docs.mongodb.org/v2.4/replication/
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.