简体   繁体   中英

MySQL db sync across locations

I have a web app which stores data using 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). 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
  • 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.

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.

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.

Any advice on architecture would be appreciated.

PS. I am not connecting the database to internet because of security concerns. 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. 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. 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. 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). That would also include setting up MySQL user accounts to only accept traffic from the specific known hosts you will be accessing from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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