<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # SaaS介紹和原理 ***** SaaS就是多租戶,一個應用可以分給很多用戶使用,而應用只需要維護一個。那么應用就需要做好各種資源的隔離(數據庫,文件,緩存,隊列,后臺,命令行等等)。 有兩種類型的多租戶SaaS形式: ### 1,單數據庫SaaS: 租戶共享一個數據庫,其數據使用 where tenant_id=1 子句分隔。 ![](https://img.kancloud.cn/ae/1b/ae1bfd5d0d1132a04a0bc5eb4e67eedb_733x89.png) ![](https://img.kancloud.cn/5a/dc/5adcb78fa7e087c95c0f1d82377f156e_503x429.png) 代碼原理,利用scoping插入租戶過濾: ![](https://img.kancloud.cn/91/ae/91aec1ae0afd01c64a14429937a2d837_1082x568.png) **缺點**: 所有語句都需要租戶過濾,所有數據庫都需要租戶識別(+tenant_id),不兼容第三方組件,開發繁瑣困難,同時不好維護。 ***** ### 2,多數據庫SaaS: 每個租戶都有自己的數據庫。 ![](https://img.kancloud.cn/a4/40/a440992835530f98552bdda22e824e50_1208x364.png) 代碼原理,識別租戶后,切換數據庫和相關租戶資源: ![](https://img.kancloud.cn/cd/bc/cdbc35a5d5167542210c93acd90702c6_1201x493.png) 優點:基本上相當便捷的把原來的單租戶程序變成多租戶,同時多租戶也容易轉為單租戶。很容易的利用原有技術開發,利用生態的第三方插件/包,技術上是高效便利,商業上成本低廉,就是我們需要的方案。 ***** 更多詳細,可以參考PPT:[SaaS多租戶技術是什么 – 灣區梁工 (liangdabiao.com)](https://liangdabiao.com/index.php/2021/12/17/saas%e6%98%af%e4%bb%80%e4%b9%88/) ***** ***** ***** ### 多數據庫SaaS開發要注意: ### 注意0:租戶識別 【**多數據庫租賃**】模式,是我們要探討的,關鍵在于租戶識別(Tenant identification),整個流程大概如下: 1,租戶域名--》識別租戶--》切換租戶數據庫--》切換各種資源--》運行應用--》運行相應任務命令 2,主域名--》識別管理員--》切換主數據庫--》運行管理后臺--》管理租戶 ### 注意1:隊列Queue要標識 ![](https://img.kancloud.cn/b9/07/b907b1a77e02d08ed150c10e769d011a_1114x386.png) ### 注意2:命令行要標識 ![](https://img.kancloud.cn/25/af/25afa7130b7c2268e5661a56aba29c1d_1158x239.png) 不指定租戶的情況,就是輪詢全部租戶,執行命令: ![](https://img.kancloud.cn/ab/e5/abe5c94a1cd8c0a2926b701eed1bd5ca_763x468.png) ### 注意3:上傳圖片/文件要識別和隔離 ![](https://img.kancloud.cn/b9/a7/b9a7b1fcdd741cee5aee555f3fac1819_518x592.png) ### 注意4:緩存要識別 例如redis,主要是通過加上前綴[prefix_XX]來識別和隔離緩存資源。 ### 注意5:調用外部資源要識別 例如在webhook 的url 加上 租戶的識別 tenant_id ***** ***** ## 介紹Laravel SaaS 多租戶包 :archtechx/tenancy [GitHub - archtechx/tenancy: Automatic multi-tenancy for Laravel. No code changes needed.](https://github.com/archtechx/tenancy) 文檔:https://tenancyforlaravel.com/docs/v3/introduction 簡單DEMO:https://github.com/Abbotton/saas-skeleton github有幾個類似的SaaS包,不過這個是最簡單高效,能夠實現以上所說的saas功能,所以就推薦這個,接下來都是以這個saas包來講解。 ### archtechx/tenancy 包原理: 1,租戶域名觸發多租戶事件,進入多租戶的路由和執行相關中間件middleware 2,多租戶中間件middleware 選擇合適的租戶,并且執行相關切換和任務。具體流程如下: ~~~php $this->tenancy->initialize($tenant); //初始化租戶 ~~~ * 租戶觸發事件:The`Stancl\Tenancy\Tenancy`class sets the`$tenant`as the current tenant and fires a`Tenancy Initialized`event * 事件觸發啟動任務:The`Bootstrap Tenancy`class catches the event and executes classes known as [tenancy bootstrappers](https://tenancyforlaravel.com/docs/v3/tenancy-bootstrappers). * 任務啟動租戶資源隔離:The tenancy bootstrappers make changes to the application to make it "scoped" to the current tenant. This by default includes: * Switching the database connection * Replacing`CacheManager`with a scoped cache manager * Suffixing filesystem paths * Making queues store the tenant id & initialize tenancy when being processed * 最后結束,恢復主庫: Conversely, when the`Tenancy Ended`event fires, the`Revert To Central Context`event transitions the app back into the central context. ***** ***** ## 開發SaaS的好處: * 節省成本,付費靈活 * 開發容易,把原有系統改造成saas * 維護容易,只需要維護一個程序 * 【自定義樣式 + 自定義 form 】:讓客戶低代碼實現功能,例如模板設計 * 可安裝插件,擴展功能容易 * 可以分配賬號:管理員,員工賬號 * 新技術的嘗新,減少障礙使用人工智能,大數據等新技術 * 資源隔離,數據安全,同時也方便客戶把應用轉變為私有應用。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看