CN108415951B - 一种数据库控制方法和*** - Google Patents

一种数据库控制方法和*** Download PDF

Info

Publication number
CN108415951B
CN108415951B CN201810107411.9A CN201810107411A CN108415951B CN 108415951 B CN108415951 B CN 108415951B CN 201810107411 A CN201810107411 A CN 201810107411A CN 108415951 B CN108415951 B CN 108415951B
Authority
CN
China
Prior art keywords
binlog
database
server
load balancing
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810107411.9A
Other languages
English (en)
Other versions
CN108415951A (zh
Inventor
刘杰
史伟
闵宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Eflycloud Computing Co Ltd
Original Assignee
Guangdong Eflycloud Computing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Eflycloud Computing Co Ltd filed Critical Guangdong Eflycloud Computing Co Ltd
Priority to CN201810107411.9A priority Critical patent/CN108415951B/zh
Publication of CN108415951A publication Critical patent/CN108415951A/zh
Application granted granted Critical
Publication of CN108415951B publication Critical patent/CN108415951B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了一种数据库控制方法和***。方法包括基于负载均衡的方式访问数据库集群;连接数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。***包括由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,所述负载均衡服务器基于负载均衡的方式访问所述数据库集群;所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。本发明通过负载均衡实现数据库集群的访问,通过binlog日志和快照保证数据库集群的安全性。

Description

一种数据库控制方法和***
技术领域
本发明涉及数据库技术领域,尤其涉及一种数据库控制方法和***。
背景技术
MySQL是当前应用最为广泛的开源数据库,该数据库本身提供了binlog的事务日志,并提供了一种主从的方式来进行数据的热备,但是这种热备方式存在非常多的弊端
1.容易裂脑,当主数据库由于宕机,导致从数据库上线之后,没有一个良好的机制来进行数据的重新同步
2.缺乏自动切换的机制
3.默认提供的互为主从方案只能支持两台数据库服务器。
发明内容
为了解决上述问题,本发明提供一种数据库控制方法和***。
本发明采用的技术方案一方面为一种数据库控制方法,适用于MySQL数据库集群,包括:基于负载均衡的方式访问数据库集群;连接数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
优选地,还包括:连接数据库集群的所有数据库并获取对应binlog日志,基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,存储所述binlog日志。
优选地,还包括:在预设的周期内,生成与binlog日志匹配的数据库的快照。
本发明采用的技术方案一方面为一种数据库控制***,适用于上述方法,包括:由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,所述负载均衡服务器基于负载均衡的方式访问所述数据库集群;所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
优选地,所述MySQL数据库用于当出现异常时,从所述binlog服务器获取快照,并根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
优选地,所述负载均衡服务器用于连接数据库集群的所有数据库并基于负载均衡单一访问对应MySQL数据库。
优选地,所述MySQL数据库用于当出现异常时,清除本地数据库的数据,从所述binlog服务器获取并将快照恢复到本地数据库,根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
优选地,所述负载均衡服务器还用于基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,将所述binlog日志传输至所述binlog服务器以进行存储。
本发明的有益效果为通过负载均衡实现数据库集群的访问,通过binlog日志和快照保证数据库集群的安全性。
附图说明
图1所示为基于本发明实施例的数据库集群***的示意图。
具体实施方式
以下结合实施例对本发明进行说明。
基于发明的实施例,一种数据库控制方法,适用于MySQL数据库集群,包括:基于负载均衡的方式访问数据库集群;连接数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
方法还包括:连接数据库集群的所有数据库并获取对应binlog日志,基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,存储所述binlog日志。
方法还包括:在预设的周期内,生成与binlog日志匹配的数据库的快照。
基于发明的实施例,一种数据库控制***,适用于上述方法,包括:由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,所述负载均衡服务器基于负载均衡的方式访问所述数据库集群;所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照。
所述MySQL数据库用于当出现异常时,从所述binlog服务器获取快照,并根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
所述负载均衡服务器用于连接数据库集群的所有数据库并基于负载均衡单一访问对应MySQL数据库。
所述MySQL数据库用于当出现异常时,清除本地数据库的数据,从所述binlog服务器获取并将快照恢复到本地数据库,根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
所述负载均衡服务器还用于基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,将所述binlog日志传输至所述binlog服务器以进行存储。
实施例的进一步改进,如图1所示的数据库集群***,包括binlog服务器、负载均衡服务器和MySQL数据库集群,其中,
所述负载均衡服务器连接全部的MySQL数据库;
binlog服务器连接全部的MySQL数据库;
binlog服务器从MySQL数据库读取binlog日志,获取到binlog(即binlog日志的简称)后,将binlog中的serverID标识(用于区分MySQL数据库)修改为一个固定值A,并将binlog的文件信息(用于表明文件类型)和偏移信息(用于描述存储地址)按照一定的存储规则进行修改以便于存储;
binlog服务器将修改后的binlog日志存储,其中,如果binlog服务器同时在两台以上的MySQL数据库上获取到了binlog,则发出一个警告信息,并对比多份binlog中的主键和唯一键信息是否有冲突,如果有冲突,则再发出一个警告信息,并忽略其中有冲突的binlog信息(用途是保证不出现重复的存储,实现逐一从MySQL数据库读取binlog日志的目的);
设立一个时长T(作为算法/流程的基本要求,避免陷入死循环),在时长T的周期内,binlog服务器从MySQL集群数据库中生成一个MySQL数据库的快照,并在快照中记录该快照所对应的binlog文件信息和偏移信息(进行快照和对应binlog日志的匹配);
当MySQL数据库出现宕机启动之后,自动从binlog服务器获取一个最新的MySQL数据库快照;
清除MySQL数据库的本地数据库的所有信息;
将快照恢复到本地数据库中,并根据快照中的binlog偏移信息从biblog服务器上同步新的数据;
同步完成之后,将自身数据库上线。
发明设立了一个公共的负载均衡服务(使用者通过该负载均衡服务器访问MySQL数据库),并通过负载均衡保证了在多台MYSQL数据库的情况下,在同一个时间段内只有唯一确定的一台MySQL数据库处于服务状态,并设立了一个binlog服务器通过负载均衡服务器和MYSQL数据库进行互为主从的连接,由此绕开了MySQL的互为主从只能在两台服务器/数据库之间进行的逻辑限制,实现了数据库的多热备份的功能;所有的binlog都存储在唯一的binlog服务器上,避免了服务的数据库宕机恢复之后,复杂的数据同步问题,只需要从binlog服务器同步就ok。
以上所述,只是本发明的较佳实施例而已,本发明并不局限于上述实施方式,只要其以相同的手段达到本发明的技术效果,都应属于本发明的保护范围。在本发明的保护范围内其技术方案和/或实施方式可以有各种不同的修改和变化。

Claims (3)

1.一种数据库控制***,其特征在于,包括:
由MySQL数据库组成的数据库集群、负载均衡服务器和binlog服务器,其中,
所述负载均衡服务器基于负载均衡的方式访问所述数据库集群,所述负载均衡服务器还用于基于预设的存储规则修改binlog日志的serverID标识、文件信息和偏移信息,将所述binlog日志传输至所述binlog服务器以进行存储;
所述binlog服务器从所述数据库集群的所有数据库获取对应binlog日志,生成与binlog日志匹配的数据库的快照;
所述MySQL数据库用于当出现异常时,从所述binlog服务器获取快照,并根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线;
所述binlog服务器用于从MySQL数据库读取binlog日志,获取到binlog后,将binlog中的serverID标识修改为一个固定值A,并将binlog的文件信息和偏移信息按照预设的存储规则进行修改以便于存储,其中,若binlog服务器同时在两台以上的MySQL数据库上获取到了binlog,则发出一个警告信息,并对比多份binlog中的主键和唯一键信息是否有冲突,若有冲突,则再发出一个警告信息,并忽略有冲突的binlog信息。
2.根据权利要求1所述的一种数据库控制***,其特征在于,所述负载均衡服务器用于连接数据库集群的所有数据库并基于负载均衡单一访问对应MySQL数据库。
3.根据权利要求2所述的一种数据库控制***,其特征在于,所述MySQL数据库用于当出现异常时,清除本地数据库的数据,从所述binlog服务器获取并将快照恢复到本地数据库,根据快照匹配的binlog日志从所述binlog服务器同步数据,同步完成后重新上线。
CN201810107411.9A 2018-02-02 2018-02-02 一种数据库控制方法和*** Active CN108415951B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810107411.9A CN108415951B (zh) 2018-02-02 2018-02-02 一种数据库控制方法和***

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810107411.9A CN108415951B (zh) 2018-02-02 2018-02-02 一种数据库控制方法和***

Publications (2)

Publication Number Publication Date
CN108415951A CN108415951A (zh) 2018-08-17
CN108415951B true CN108415951B (zh) 2022-01-11

Family

ID=63126819

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810107411.9A Active CN108415951B (zh) 2018-02-02 2018-02-02 一种数据库控制方法和***

Country Status (1)

Country Link
CN (1) CN108415951B (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108984660A (zh) * 2018-06-28 2018-12-11 中译语通科技股份有限公司 一种MySQL数据库主从同步数据去重方法
CN110287273A (zh) * 2019-07-03 2019-09-27 成都路行通信息技术有限公司 基于监听MySQL数据库binlog变化实现数据同步的方法和***

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101252603A (zh) * 2008-04-11 2008-08-27 清华大学 基于存储区域网络san的集群分布式锁管理方法
CN104023082A (zh) * 2014-06-23 2014-09-03 浪潮电子信息产业股份有限公司 一种集群负载均衡的实现方法
CN106570007A (zh) * 2015-10-09 2017-04-19 阿里巴巴集团控股有限公司 用于分布式缓存***数据同步的方法和设备
CN106815097A (zh) * 2017-01-18 2017-06-09 北京许继电气有限公司 数据库容灾***和方法

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2377649C (en) * 2002-03-20 2009-02-03 Ibm Canada Limited-Ibm Canada Limitee Dynamic cluster database architecture
CN101562784B (zh) * 2008-04-14 2012-06-06 华为技术有限公司 报文分发方法、设备及***
US7809833B2 (en) * 2008-07-15 2010-10-05 International Business Machines Corporation Asymmetric dynamic server clustering with inter-cluster workload balancing
CN102065137B (zh) * 2010-12-21 2013-08-14 山东浪潮齐鲁软件产业股份有限公司 一种网络数据库表数据应用程序同步的方法
CN102546741B (zh) * 2011-08-31 2014-08-13 苏州华谷电子科技有限公司 云计算***
CN104834724B (zh) * 2015-05-12 2018-12-18 广东睿江云计算股份有限公司 一种数据库同步方法和装置
US20170235716A1 (en) * 2016-02-12 2017-08-17 International Business Machines Corporation Context driven artifact service management

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101252603A (zh) * 2008-04-11 2008-08-27 清华大学 基于存储区域网络san的集群分布式锁管理方法
CN104023082A (zh) * 2014-06-23 2014-09-03 浪潮电子信息产业股份有限公司 一种集群负载均衡的实现方法
CN106570007A (zh) * 2015-10-09 2017-04-19 阿里巴巴集团控股有限公司 用于分布式缓存***数据同步的方法和设备
CN106815097A (zh) * 2017-01-18 2017-06-09 北京许继电气有限公司 数据库容灾***和方法

Also Published As

Publication number Publication date
CN108415951A (zh) 2018-08-17

Similar Documents

Publication Publication Date Title
CN106302806B (zh) 一种数据同步方法、***、同步获取方法及相关装置
CN107832138B (zh) 一种扁平化的高可用namenode模型的实现方法
US9753954B2 (en) Data node fencing in a distributed file system
CN104252500B (zh) 一种数据库管理平台的故障修复方法和装置
CN101196840B (zh) 配置数据镜像的***和方法
KR20180101941A (ko) 소스 데이터베이스 관리시스템에서 변경되는 데이터를 실시간으로 목표 데이터베이스 관리시스템에 복제하는 장치 및 그 방법
CN112506702B (zh) 数据中心容灾方法、装置、设备及存储介质
US9251230B2 (en) Exchanging locations of an out of synchronization indicator and a change recording indicator via pointers
CN109361525B (zh) 重启分布式部署多服务的方法、装置、控制终端及介质
CN102096615A (zh) 远程增量备份方法及***
CN109408280A (zh) 数据备份方法、装置及***
CN108415951B (zh) 一种数据库控制方法和***
CN103634388B (zh) 处理存储服务器中控制器重启的方法和相关设备及通信***
CN105550230B (zh) 分布式存储***节点故障的侦测方法和装置
CN113190620B (zh) Redis集群之间数据的同步方法、装置、设备及存储介质
CN110958287B (zh) 操作对象数据同步方法、装置及***
EP3896571B1 (en) Data backup method, apparatus and system
CN105323271B (zh) 一种云计算***以及云计算***的处理方法和装置
CN105007172A (zh) 一种hdfs高可用性方案的实现方法
KR101919670B1 (ko) 분산형 제어 시스템용 제어 기기
CN107888430B (zh) 虚拟机管理操作同步方法及装置
JP5685213B2 (ja) 差分レプリケーションシステム、マスターデータベース装置、及びスレーブデータベース装置
CN115114112A (zh) 数据同步方法及装置
CN114756410A (zh) 一种双机热备***的数据恢复方法、装置及介质
CN116737764A (zh) 数据同步的方法和装置、电子设备和存储介质

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant