search
HomeDatabaseMysql TutorialMongoDB 复制集自动故障切换

选举在复制集的操作中扮演着非常重要当作用,选举的要话费时间当,在选举的过程中,复制集是没有主节点的,无法接受客户端的读请

一  复制集的高可用性简介

复制集通过故障自动切换来实现高可用性,当主节点出现故障当时候,从节点可以通过选举成为主节点,而这个过程在大多数当情况下是自动进行的,不需要手动当干预。在某些情况下,故障自动切换需要数据回滚。

复制集部署的方式(复制集成员数量、物理因素,如带宽 复制集成员当地理位置等)可能会影响自动切换当效率。为了提高自动切换的效率,我们应该将复制集的大多数成员放到一个核心的数据中心来进行管理,在复制集里多放几个从节点,当主节点失效的时候,保证有可用的从节点可以用,而且还也可以因网络故障发生,隔离大多数复制集成员的通信。

自动故障切换主要包括两大过程:选举 和 回滚

选举在复制集的操作中扮演着非常重要当作用,选举的要话费时间当,在选举的过程中,复制集是没有主节点的,,无法接受客户端的读请求,所以MongoDB尽量避免选举的进行。

选举的发生:当主节点不可用的时候;复制集初始化(initiating)的时候

二  影响选举的因素

1.心跳(Heartbeats)

心跳:复制集成员每隔两秒互相发送一次心跳请求包(其是就是ping对方),如果在10秒钟内没有收到对方成员的回复,就认为它出现了故障。

2.优先级比较

成员的优先级会影响到选举的过程,成员们会优先将自己的票投给优先级高的成员。

拥有0优先级的成员不会被选为主库,因为他们不会被投票,没有被选举权。

只要当前的主库拥有最高的优先级且在10秒钟内的操作日志条目内容是最新的,那就不会进行选举。

如果一个高优先级的成员且其操作也进入当前的primary,设置的选举以高优先级节点提供一个机会来成为主库。

3.操作时间:操作时间指的是一个成员最后一次执行操作日志时的日志条目时间。如果一个成员比其他的操作时间都最新(most recent)的话,就有可能被选为主库

4.连通性:复制集中的一个成员只有和大多数成员保持联通,得到大多数人的投票才可以成为主节点,否则会自动降级成为从节点。

例如:对于一个拥有三个成员的复制集,每个成员都可以投票,那么只有其中的两个人可以保持联通的话,复制集就可以进行一次选举。如果其中两个变的不可用,剩下的那个节点如果是从节点的话,那么它仍然还是一个从节点,因为它不能和其他的成员保持连通。同样的道理如果该节点是主节点的话,会自动的降级成为从节点,因为它不能和别的成员保持连通,失去了成为主节点的资格.这样的话该复制集就变成只读了。

5.网络分区:由于网络分区,如果一个主节点不可用的话,其余从节点又不能大多数的连通的话,复制集就无法进行选举。所以尽量将大部分复制集成员放到一个数据中心中,而将一小部分放到另外一个。

更多详情见请继续阅读下一页的精彩内容:

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

推荐阅读:

Java实现MongoDB中自增长字段

CentOS编译安装MongoDB

CentOS 编译安装 MongoDB与mongoDB的php扩展

CentOS 6 使用 yum 安装MongoDB及服务器端配置

Ubuntu 13.04下安装MongoDB2.4.3

如何在MongoDB中建立新数据库和集合

MongoDB入门必读(概念与实战并重)

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment