The embodiment of the invention discloses a method and device for switching a database cluster database. The method includes: the running state of cluster monitoring database; to the main database in a cluster monitoring is not available, the database cluster in a database from the switch to the new primary database will update the database cluster; the new primary database information to the upper structure of the database cluster. By switching method and device for main database cluster provided by the embodiment of the invention, the front view layer or intermediate processing layer in the cluster to access the database of the main database, not access to the main database of original database can not provide services in the cluster, but access to the new primary database after switching, so as to ensure the service recovery in a very short period of time.
【技术实现步骤摘要】
一种数据库集群主数据库的切换方法及装置
本专利技术涉及计算机领域,尤其涉及一种数据库集群主数据库的切换方法及装置。
技术介绍
在目前,关系型数据库的应用非常广泛,例如Mysql数据库。目前,关系型数据库集群中多采用一主多从的架构。如图1所示,为一mysql数据库集群的架构示意图,其包括:主数据库master和三个从数据库,三个从数据库分别为:Slave-1、Slave-2和Slave3。例如图1中所示,Slave-1和Slave-2位于机房1,Slave3位于机房2。主数据库master分别与从数据库Slave-1、Slave-2和Slave3连接。在现实对mysql数据库的使用中,主数据库master有可能因为各种原因宕机,例如系统故障、硬件故障等,均有可能导致主数据库master宕机,从而导致整个mysql数据库集群无法使用,而现有技术中并未存在解决这一问题的有效技术手段。因此,现有技术中亟需一种能够在主数据库宕机的情况下自动切换主数据库的方法或装置。
技术实现思路
鉴于上述问题,提出了本专利技术以便提供一种克服上述问题或者至少部分地解决上述问题的一种数据库集群主 ...
【技术保护点】
一种数据库集群主数据库的切换方法,所述数据库集群为一主N从式结构,其中N为大于等于1的整数,其特征在于,所述方法包括:监测所述数据库集群的运行状态;在监测到所述数据库集群中的主数据库无法提供服务时,将所述数据库集群中的一个从数据库切换为所述数据库集群的新的主数据库;将所述新的主数据库的信息更新到所述数据库集群的上层结构。
【技术特征摘要】
1.一种数据库集群主数据库的切换方法,所述数据库集群为一主N从式结构,其中N为大于等于1的整数,其特征在于,所述方法包括:监测所述数据库集群的运行状态;在监测到所述数据库集群中的主数据库无法提供服务时,将所述数据库集群中的一个从数据库切换为所述数据库集群的新的主数据库;将所述新的主数据库的信息更新到所述数据库集群的上层结构。2.根据权利要求1所述的方法,其特征在于,所述将所述新主数据库的信息更新到所述数据库集群的上层结构,具体包括:将所述新的主数据库的信息更新到所述数据库集群对应的前端浏览层或中间处理层。3.根据权利要求1所述的方法,其特征在于,所述将所述数据库集群中的一个从数据库切换为所述数据库集群的新主数据库,具体包括:获取所述数据库集群的所有从数据库的列表;依据预设条件,在所述列表记录的所述所有从数据库中,筛选得到一个从数据库以作为新的主数据库;以及将所述数据库集群的主数据库切换到所述新的主数据库。4.根据权利要求3所述的方法,其特征在于,所述依据预设条件,在所述列表记录的所述所有从数据库中,筛选得到一个从数据库以作为新的主数据库,包括:在所述列表记录的所述所有从数据库中,选择具备生命力的从数据库以作为新的主数据库,其中,所述从数据库具备生命力是指该从数据库能够提供数据和/或业务支持。5.根据权利要求4所述的方法,其特征在于,所述选择具备生命力的从数据库以作为新的主数据库,包括:选择状态标识为alive状态的从数据库以作为新的主数据库;和/或选择延迟事务数量小于预设数量的从数据库...
【专利技术属性】
技术研发人员:杨挺,
申请(专利权)人:北京奇虎科技有限公司,奇智软件北京有限公司,
类型:发明
国别省市:北京,11
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。