简体   繁体   English

在多个站点之间共享表

[英]Sharing tables across multiple sites

this is more of an architecture question which I can't solve this properly as I don't have enough experience with such architecture... I'm currently running the solution with Python and SqlAlchemy , but the question is generic and the answer doesn't have to address those technologies. 这更多是一个体系结构问题 ,由于我对这种体系结构没有足够的经验,因此我无法正确解决此问题 ...我目前正在使用PythonSqlAlchemy运行该解决方案,但问题是通用的,答案没有不必解决这些技术。

I will try to explain it on an example of public library. 我将尝试以公共图书馆为例进行解释。 So imagine having a public library, with server holding tables with all the books, scans (large binary images), users. 因此,假设有一个公共图书馆,其中服务器保存着所有书籍,扫描表(大的二进制图像)和用户的表。 I've already made a client and server parts which work great, but locally for a single library. 我已经制作了一个客户端和服务器部分,它们工作得很好,但是对于单个库来说却是本地的。

Now I would like to have this of server and clients for another public library (and later more public libraries to come). 现在,我想为另一个公共图书馆(以及以后的更多公共图书馆)使用服务器和客户端。 Having a local server for each library is desired as there is much data to be transferred to and from local server. 每个库都需要有一个本地服务器,因为有很多数据要与本地服务器进行传输。

The complication comes from the requirement to be able to share users (with their member cards) between libraries - if user comes and registers at library A, he should be able to go to library B without the need for new registration. 复杂性来自能够在库之间共享用户(及其会员卡)的要求-如果用户来库A注册并注册,则他应该能够去库B而无需新注册。 There's no need for being able to see other user data in the library he wasn't registered in the first place, just hist member account (id, login and password). 不需要能够查看他最初没有注册的库中的其他用户数据,只需查看历史成员帐户(ID,登录名和密码)即可。

The simple solution would be: 简单的解决方案是:

  • having large data on local server 在本地服务器上有大数据
  • having users on cloud (some public server on internet) 使用户在云上(Internet上的一些公共服务器)

The problem is that there are queries (for statistics, views, and so on), which run on local server and need accessing users, so I can't have users on a different server and database, because I couldn't then do select + join on such an architecture. 问题在于,存在一些查询(用于统计信息,视图等),这些查询在本地服务器上运行并且需要访问用户,因此我无法在其他服务器和数据库上拥有用户,因为那时我无法选择+加入这样的架构。

The solution which is left behind by previous developer and which other developers think is wrong, is to have the users table set up as replicated table ( MariaDB + Galera ), so it would end up having users table the same on cloud and each library site, so the previous code would work as if everything is just local, while sharing the users on the background with other libraries. 以前的开发人员遗留下来且其他开发人员认为是错误的解决方案是将用户表设置为复制表MariaDB + Galera ),因此最终将使用户表在云和每个库站点上都相同,因此前面的代码将像一切都在本地一样工作,同时与其他库在后台共享用户。

One of the problems with this is that the current version of our database (MariaDB) doesn't support (or has broken) partial replication (only some tables or some databases), so it would need patching of the MariaDB and distributing this patched version of database server to cloud and other sites, which stinks of various problems now and in the future, when new version of MariaDB will come out. 问题之一是我们数据库的当前版本(MariaDB)不支持(或已损坏)部分复制(仅某些表或某些数据库),因此需要修补MariaDB并分发此修补版本数据库服务器到云和其他站点的访问,这会在现在和将来出现各种问题时,发布新版本的MariaDB。

What would be the proper way of sharing these users between sites, while retaining the ability to do local selects and joins with the user table? 在保留在用户表中进行本地选择和联接的能力的同时,在站点之间共享这些用户的正确方法是什么?

(Maybe there's a known design / architecture pattern for this, but I just don't know what to search for as I'm new to this.) (也许有一个已知的设计/架构模式,但是我不知道要搜索什么,因为我对此并不陌生。)

Thanks, Miro 谢谢,Miro

schema - sharing table between sites 模式-站点之间的共享表

Start with a single-source-of truth for the user registrations. 从单一来源的用户注册开始。 That is one server (or Galera cluster, for HA) somewhere (in HQ, in Cloud, wherever). 那是某处(在总部,在云中,在任何地方)的一台服务器(或HA的Galera群集)。 Login queries remotely access that server. 登录查询可远程访问该服务器。

Think about any place you log in -- you are going to some central cite. 考虑一下您登录的任何地方-您将获得一些中央提示。 My point is, that is the way everyone does it because it is fast, reliable, efficient, etc, with today's networks. 我的意思是,这是每个人都这样做的方式,因为对于当今的网络,它是快速,可靠,高效的。

Next, what about images, etc? 接下来,图像等呢? If they are shared across your sites, you may as well do them the same way. 如果它们在您的站点之间共享,那么您也可以采用相同的方式进行共享。 Look at any search engine for the last two decades -- images (etc) are fetched from a single site. 看看过去二十年来的任何搜索引擎-图像(等)都是从单个站点获取的。 (Actually a small number of sites, for redundancy, etc). (实际上是少数站点,用于冗余等)。 Even the biggest web providers have no more than perhaps a dozen datacenters to service the entire world. 即使是最大的网络提供商,也可能只有不超过十二个数据中心可以为整个世界服务。

After that, you need to decide on Cloud vs dedicated (or even run your own datacenter). 之后,您需要确定云计算还是专用(甚至是运行自己的数据中心)。

For HA, Cloud providers do a lot. 对于高可用性,云提供商做了很多事情。 For do-it-yourself, there are various replication scenarios, Galera being one of the best (today). 对于自己动手,有多种复制方案,Galera是当今最好的复制方案之一。 For true HA, you need two copies of your data geographically separated -- to protect from hurricanes, fires, floods, earthquakes, etc. Consider a WAN deployment of Galera, or some asynchronouse replication (possibly even between two Galera clusters. 对于真正的HA,您需要在地理位置上分开的数据的两个副本-免受飓风,火灾,洪水,地震等的影响。请考虑Galera的WAN部署或某些异步复制(甚至可能在两个Galera群集之间进行)。

Another choice is whether the Users and Images tables need to be on separate servers. 另一个选择是“用户”表和“图像”表是否需要在单独的服务器上。 Only if the traffic and size are high do you need to consider separating them. 仅在流量和流量很大时,才需要考虑将它们分开。 For a huge Image library, you may need a large number of servers, at which point, they should probably living on servers with the sole purpose of delivering images -- no Users, no HTML pages, etc. Even the "meta" info about images could be elsewhere in MySQL; 对于庞大的图片库,您可能需要大量的服务器,这时,它们可能应仅出于传递图片的目的而驻留在服务器上-没有用户,没有HTML页面等。即使是有关“元”信息图像可能在MySQL的其他地方; the Images are in files and just a web server tuned to deliver images runs. 图像位于文件中,仅调整了网络服务器以运行图像。 (I can think of multiple 'big guys' that do it this way.) (我可以想到有很多这样做的“大人物”。)

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

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