简体   繁体   English

MySQL db跨位置同步

[英]MySQL db sync across locations

I have a web app which stores data using MySQL. 我有一个Web应用程序,使用MySQL存储数据。 The web app is internal (not available via the internet). 网络应用程序是内部的(无法通过互联网使用)。

I now have to deploy this application across 3 (and possibly more) locations (branch offices). 现在,我必须在3个(可能还有更多)位置(分支机构)中部署此应用程序。 They need to be able to sync the data (entries created at one location be available at the other branch locations). 他们需要能够同步数据(在一个位置创建的条目在其他分支位置可用)。

Requirements 要求

  • local instances of web app + mysql database Web应用程序+ mysql数据库的本地实例
  • each location reads and writes locally / is on own network 每个位置都在本地读写/在自己的网络上
  • database is synced one per day (possibly through a script via SSH) so that each location has the same data. 每天同步一次数据库(可能通过SSH通过脚本进行同步),以便每个位置具有相同的数据。

The only way that I was able to figure this out (so far) is to create UUID (unique identifiers) and to encode each row with a source bit (for originating location) and sync bit (new=0, synced=1) then to write a script where I SSH to each location nightly and add rows that = my source and synced=0 to each location... I realize this is brute and not very elegant/reliable but I am not sure what else to do. 我到目前为止(到目前为止)能够弄清楚的唯一方法是创建UUID(唯一标识符),并使用源位(用于始发位置)和同步位(new = 0,synced = 1)对每一行进行编码,然后编写一个脚本,每晚我在该位置SSH到每个位置,并添加=我的源代码并已同步= 0到每个位置的行...我意识到这是蛮横的,不是很优雅/可靠,但是我不确定该怎么做。

The client is afraid that if internet connection fails he wants to be able for the app to function locally, but still have a sync between other branches (via a nightly script or otherwise). 客户担心,如果互联网连接失败,他希望该应用程序能够在本地运行,但仍然在其他分支机构之间保持同步(通过夜间脚本或其他方式)。 As I said, there are already a total of 3 locations and possibly more coming in later this year. 就像我说的那样,已经有3个地点,今年晚些时候可能还会有更多地点。

Any advice on architecture would be appreciated. 关于架构的任何建议将不胜感激。

PS. PS。 I am not connecting the database to internet because of security concerns. 出于安全考虑,我没有将数据库连接到Internet。 But am open to all suggestions. 但是我愿意接受所有建议。

Thanks. 谢谢。

You client is potentially costing themselves a lot of money in extra hardware, development, and maintenance costs with such an architecture decision. 您的客户可能会因这种架构决定而在额外的硬件,开发和维护成本上花费大量金钱。 Unless they have mission critical data entry needs it might be a bit of a crazy expectation to replicate the hardware stack in all branch locations. 除非他们有关键任务数据输入需求,否则在所有分支机构中复制硬件堆栈可能会有一个疯狂的期望。

That being said, they will still need to move data across the open internet to replicate data from server to server, unless of course they have their own VPN within which you will be setting this up. 话虽如此,他们仍然需要在开放的Internet上移动数据以在服务器之间复制数据,除非他们当然拥有自己的VPN,您将在其中进行设置。 trying to have some daily process to migrate/merge data should be a red flag in your mind and a total non-starter. 尝试每天进行一些迁移/合并数据的过程应该是您的一个危险信号,并且完全不适合您。 It is a very complex problem. 这是一个非常复杂的问题。 What you are likely going to need is some sort of master-master database replication cluster. 您可能需要的是某种主-主数据库复制群集。 Luckily MySQL provides you with the ability to do this. 幸运的是,MySQL为您提供了执行此操作的能力。 Unluckily, it can be complex to set up and get it just right, probably something that might be a bit of a challenge for you if you are having to ask this question here. 不幸的是,设置和正确安装它可能很复杂,如果您在这里不得不问这个问题,可能对您来说是一个挑战。

As far as database security, there is no reason whatsoever that you should be concerned about having MySQL databases hosted on the internet, so long as you are taking the proper precautions to protect the server. 就数据库安全性而言,只要您采取了适当的预防措施来保护服务器,就没有理由担心将MySQL数据库托管在Internet上。 The would probably start at the network level with allowing access only to port 3306 (and 22 for SSH access) and only to the IP address(es) of the web application server(s). 这可能始于网络级别,仅允许访问端口3306(对于SSH访问为22),并且仅允许访问Web应用程序服务器的IP地址。 That would also include setting up MySQL user accounts to only accept traffic from the specific known hosts you will be accessing from. 这还包括设置MySQL用户帐户,使其仅接受来自您将访问的特定已知主机的流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM