
語言 🇹🇼 繁體中文
背景
開始使用
部署
架構
安裝與整合
安全性提示
在本地部署 FastComments
FastComments 提供多種部署解決方案。最常見的是由我們為您託管應用程式。
不過,我們理解有些客戶不能將其資訊存放在雲端,並且要求在內部部署中託管所有資料。
本文件涵蓋該使用情境。
包含內容 
FastComments On Prem 允許您部署我們的即時留言解決方案,包含所有的審核與管理工具, 在您自己的硬體上。
這意味著您可以掌控您的資料,且留言系統可以限制在您本地區域網路或企業網路內。
執行個體 
Required Components
For On-Prem, FastComments just consists of an application server and a database. We have simplified the deployment so that the application can serve all traffic directly without adding other components.
The application server is provided in a Docker image and can be deployed with any container management solution.
The database, MongoDB, can be self-ran or hosted by another provider like AWS DocumentDB or MongoDB Atlas.
FastComments is currently tested with MongoDB 7, however we aim to be DocumentDB compatible to ease deployment.
Instance Sizes
You will find that FastComments is fairly well optimized and doesn't require large machines for the application itself to keep low P99s.
All batch and cron jobs use streaming to limit total memory usage.
The below tables for the application server and database can assist with sizing.
Application Server Instances
| Concurrent Users | Total Cluster CPUs | Total Cluster Memory |
|---|---|---|
| 100 | 1 | 256mb |
| 1K | 2 | 512mb |
| 10K | 8 | 1gb |
| 100K | 32 | 8gb |
| 1M | 64 | 64gb |
For example, a single core serving around 100 comment threads a second usually never uses more than 250mb RSS.
Database Server Instances
Sizing the database depends on working set size, which is the amount of data you access at a given point in time, as well as concurrent requests.
FastComments is fairly kind to Mongo, in that for the hot queries it uses index hints, streaming cursors, and has concurrency limits in various areas to prevent overloading of downstream systems.
The below is a general guideline on database instance sizes. Note that this is per instance, not total resources in the cluster.
| Concurrent Users | Comments Stored | CPUs Per Instance | Memory Per Instance |
|---|---|---|---|
| 100 | 1k | 1 | 256mb |
| 1K | 5k | 2 | 512mb |
| 10K | 100k | 8 | 2gb |
| 100K | 500k | 16 | 8gb |
| 1M | 5M | 32 | 32gb |
The above tables are conservative estimates. You may find actual requirements differ based on your specific configuration (page sizes, comment volume, etc).
設定 
FastComments 使用環境變數來進行設定。以下列出所有與 On-Prem 相關且支援的變數。
| Variable | Default | Info | Required | Examples or Valid Values |
|---|---|---|---|---|
| NODE_ENV | 環境類型。 | Yes | production, dev | |
| MONGO_URI | 資料庫連線 URI。 | Yes | ||
| MONGO_ENABLE_SSL | false | 啟用使用 SSL 來連線資料庫。 | No | true, false |
| MONGO_ENABLE_SSL_VALIDATE | false | 在連線到 Mongo 時啟用對憑證與 CA 的驗證。 | No | true, false |
| MONGO_SSL_CA | Mongo SSL CA pem 檔案。 | No | /path/to/some-cert.pem | |
| ADMIN_NOTIFICATIONS_EMAIL | 接收重要系統相關通知的電子郵件地址。 | No | admin-group@bigcorp.com | |
| IP_HASH_SALT | 用於對 IP 位址進行雜湊的 Salt。 | Yes | ||
| SESSION_SECRET | 用於簽署會話的金鑰。 | Yes | ||
| SESSION_STORE_SECRET | 用於在儲存中簽署/雜湊會話的金鑰。必須不同於 SESSION_SECRET。 | Yes | ||
| HOSTNAME | 部署 FastComments(管理面板等)的主機名稱。不得包含連接埠或協定。 | Yes | example.com | |
| HOST_ADDR | 部署 FastComments(管理面板等)的可存取 URI。 | Yes | https://example.com | |
| EMAIL_CONFIG_PATH | 本機檔案系統上放置電子郵件設定(SMTP、網域/提供者對應等)的路徑。 | Yes | /my/config.json | |
| EMAIL_DEFAULT_FROM_NAME | FastComments Robot | 電子郵件 "From Name" 標頭。 | No | My Company Name |
| EMAIL_DEFAULT_FOOTER_LOGO | /images/logo-32-2020-01.png | 電子郵件頁尾 logo。 | No | https://exmaple.com/footer.png |
| EMAIL_DEFAULT_TRANSPORT | 覆寫 EMAIL_CONFIG_PATH 中的 "defaultTransport"。在將相同設定檔部署到不同環境時很有用。 | No | myTransportName | |
| ON_PREM_TENANT_ID | 您在 fastcomments.com 帳戶的 ID。用於註冊授權金鑰。 | No | ||
| ON_PREM_LICENSE_KEY | 一組 On-Prem 授權金鑰。 | No | ||
| GIPHY_API_KEY | Giphy API Key。如果未指定,應建立一個設定規則以停用 gif 選取器。 | No | ||
| GIPHY_DEFAULT_RATING | pg | 用於 giphy 的整合。也可透過元件自訂規則覆寫。 | No | g, pg, pg-13, r |
| OPENAI_SECRET_KEY | 用於 OpenAI 驅動的功能,例如可選的基於 GPT 的垃圾郵件檢測。 | No | ||
| CDN_HOST_ADDR | 資源要從何處擷取的主機名稱。預設為 HOSTNAME 的值。 | No | example.com | |
| LARGE_FILE_HOST_ADDR | 大型檔案(例如匯出)要從何處擷取的主機名稱。預設為 CDN_HOST_ADDR 的值。 | No | example.com | |
| LARGE_FILE_LOCATION_TYPE | local_disk | 大型檔案(如匯出檔)應儲存的位置。 | No | local_disk, s3 |
| FROM_EMAIL_HOST | 電子郵件應由哪個主機名稱發送。 | No | example.com | |
| COOKIE_ID | fastcomments.sid | fastcomments Cookie 的名稱。 | No | |
| COOKIE_HOSTNAME | .fastcomments.com | Cookie 的 "hostname" 欄位值。建議前面加上點(dot)。 | No | .example.com |
| S3_ACCESS_KEY | 用於使用者上傳檔案、頭像等。如果未定義則預設為本機檔案系統。 | No | ||
| S3_SECRET_KEY | 用於使用者上傳檔案、頭像等。 | No | ||
| S3_REGION | 用於使用者上傳檔案、頭像等。 | No | ||
| S3_BUCKET | 用於使用者上傳檔案、頭像等。 | No | ||
| S3_HOST | 用於使用者上傳檔案、頭像等。 | No | ||
| CACHE_DIR | 用於儲存選用的離線快取位置,以便在資料庫不可用時使用。會定期以前 100 個熱門留言串更新。 | No | ||
| BACKUP_DIR | 用於在資料庫不可用時儲存資料的位置。如果在資料庫不可用時有留言提交,會先放在此處,稍後再處理。 | No |
請注意,所有與網域相關的變數都使用 _HOST 或 _ADDR 後綴。兩者的差別為:
_HOST:example.com_ADDR:https://example.com
The EMAIL_CONFIG_PATH should contain a path to a JSON file with the following example format:

在上方範例中,我們定義了一個名為 mailgun 的預設 SMTP 電子郵件傳輸。我們也定義了一個專門用於 @yahoo.com 電子郵件的特殊傳輸。在某些情境下,針對特定網域使用特定提供者或發送 IP 以調整投遞是可取的。此項為選用。
DocumentDB
連線到 DocumentDB 時,您會想要指定 MONGO_ENABLE_SSL=true MONGO_SSL_CA=/some/path.pem,以相容於預設設定。
資料庫停機與維護模式 
FastComments 支援自動維護模式。如果資料庫當機,它仍能繼續提供熱門留言討論串。
此外,在維護模式中,所有留言會被儲存到 BACKUP_DIR。系統恢復上線後,這些留言會被處理(檢查垃圾訊息等)並儲存。
它的作法是每小時判定最熱門的前 100 個留言討論串,並將其內容快取到磁碟上。 判定前 100 名討論串是從預先計算好的狀態取得,所以這不是一個耗資源的週期性工作。
這是完全可選的,只有在設定了 CACHE_DIR 和 BACKUP_DIR 時才會啟用。這當然會使應用節點具有狀態,但這些狀態可以在任何時候遺失,而不會導致應用錯誤運作。
注意,在維護模式中無法對留言討論串進行正確的驗證,因此只有被視為公開且安全的討論串會定期備份。
在維護模式下,許多功能將無法使用。
鎖定 
像任何分散式系統一樣,FastComments 需要某種方式來鎖定資源和程序。可以透過 /locks-in-progress 端點監控這些鎖定。
這可以用來找出系統為何停滯或負載過高。如果例如 SRE 想要了解系統為何出現高 CPU 負載,他們可以 檢查此端點以取得出問題的 cron 名稱。
Widget 程式碼 
On-Prem 的前端程式碼範例與函式庫與 SaaS 產品相同。然而,您必須指定 apiHost 並使用正確的腳本路徑:

上述是一個非常簡單的範例。我們也可以使用官方第一方的 React、Angular、Vue、Svelte 等函式庫。
結論
您已閱讀完 On Prem 文件的全部內容。請在下方告訴我們您有任何進一步的意見或問題 - 您 也可以透過 支援頁面 與我們聯絡。