简体   繁体   English

如何实现“共享数据库,独立模式”的多租户策略

[英]How to implement the “Shared database, separate schema” multi-tenant strategy

I have to make a web application multi-tenant enabled using Shared database separate schema approach. 我必须使用共享数据库独立模式方法使Web应用程序启用多租户。 The application is built using Java/J2EE and Oracle 10g. 该应用程序是使用Java / J2EE和Oracle 10g构建的。

I need to have one single appserver using a shared database with multiple schema, one schema per client. 我需要一个单一的appserver使用具有多个架构的共享数据库,每个客户端一个架构。

What is the best implementation approach to achieve this? 实现此目标的最佳实施方法是什么?

  • What needs to be done at the middle tier (app-server) level? 在中间层(应用程序服务器)级别需要做什么?
  • Do I need to have multiple host headers each per client? 每个客户端是否需要多个主机头?
  • How can I connect to the correct schema dynamically based on the client who is accessing the application? 如何根据正在访问应用程序的客户端动态地连接到正确的架构?

At a high level, here are some things to consider: 从高层次上讲,需要考虑以下几点:

  • You probably want to hide the tenancy considerations from day-to-day development. 您可能想要隐藏日常开发中的租赁注意事项。 Thus, you will probably want to hide it away in your infrastructure as much as possible and keep it separate from your business logic. 因此,您可能希望尽可能将其隐藏在基础结构中,并将其与业务逻辑分开。 You don't want to be always checking whether which tenant's context you are in... you just want to be in that context. 您并不想一直检查您所处的租户上下文,而只是想在那个上下文中。
  • If you are using a unit of work pattern, you will want to make sure that any unit of work (except one that is operating in a purely infrastructure context, not in a business context) executes in the context of exactly one tenant. 如果您使用的是工作单元模式,那么您将要确保任何工作单元(除了在纯基础结构上下文中而非在业务上下文中运行的工作单元)都在一个租户的上下文中执行。 If you are not using the unit of work pattern... maybe you should be. 如果您不使用工作单元模式,也许应该。 Not sure how else you are going to follow the advice in the point above (though maybe you will be able to figure out a way). 不知道您将如何遵循以上几点的建议(尽管也许您将能够找到一种方法)。
  • You probably want to put a tenant ID into the header of every messaging or HTTP request. 您可能希望将租户ID放入每个消息传递或HTTP请求的标头中。 Probably better to keep this out of the body on principle of keeping it away from business logic. 最好将其排除在主体之外,以使其脱离业务逻辑。 You can scrape this off behind the scenes and make sure that behind the scenes it gets put on any outgoing messages/requests. 您可以在后台将其抓取,并确保将其放在任何传出消息/请求的后台。
  • I am not familiar with Oracle, but in SQL Server and I believe in Postgres you can use impersonation as a way of switching tenants. 我对Oracle不熟悉,但是在SQL Server中,我相信在Postgres中,您可以使用模拟作为切换租户的方式。 That is to say, rather than parameterizing the schema in every SQL command and query, you can just have one SQL user (without an associated login) that has the schema for the associated tenant as its default schema, and then leave the schema out of your day-to-day SQL. 就是说,您不必让每个SQL命令和查询中的架构参数化,而是只让一个SQL用户(没有关联的登录名)将关联租户的架构作为其默认架构,然后将该架构排除在外您的日常SQL。 You will have to intercept calls to the database and wrap them in an impersonation call. 您将必须拦截对数据库的调用,并将其包装为模拟调用。 Like I say, I'm not exactly sure how this works out in Oracle, but that's the general idea for SQL Server. 就像我说的那样,我不确定在Oracle中如何实现此功能,但这是SQL Server的基本思想。
  • Authentication and security are a big concern here. 身份验证和安全性是这里的一大问题。 That is far beyond the scope of what I can discuss in this answer but make sure you get that right . 这远远超出了我可以在此答案中讨论的范围,但请确保您做对了

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

相关问题 具有共享数据库和鉴别器列的多租户 - Multi-Tenant with shared database and discriminator column jpapersist()函数在TABLE_PER_TENANT(multi_schema)多租户策略中给出错误 - jpa persist() function giving error in TABLE_PER_TENANT (multi_schema) multi-tenant strategy Hibernate多租户命名策略 - Hibernate multi-tenant naming strategy Spring Data JPA存储库多租户单模式技术 - Spring Data JPA repository multi-tenant single schema technique 如何在多租户(每租户数据库)感知 Spring 引导应用程序中使用固定数据库 - How do you use a fixed database in a multi-tenant (database-per-tenant) aware Spring Boot application 每个租户多租户连接提供程序的Hibernate数据库正在为单个租户创建多个数据库连接 - Hibernate database per tenant multi-tenant connection provider is creating multiple database connections for single tenant 安全地为多租户数据库创建新模式 - Safely create new schemas for multi-tenant database 使用PostgreSQL中的Schema的Hibernate和多租户数据库 - Hibernate and Multi-Tenant Database using Schemas in PostgreSQL 多租户环境中的Spring Boot + Thymeleaf + Database TemplateResolver - Spring Boot + Thymeleaf + Database TemplateResolver in a Multi-Tenant environment 具有Spring Boot和Hibernate的多租户和中央数据库 - Multi-Tenant and Central Database with Spring Boot and Hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM