FastComments.com

在本地部署 FastComments

FastComments 提供多種部署解決方案。最常見的是由我們為您託管應用程式。

不過,我們理解有些客戶不能將其資訊存放在雲端,並且要求在內部部署中託管所有資料。

本文件涵蓋該使用情境。

包含內容 Internal Link


FastComments On Prem 允許您部署我們的即時留言解決方案,包含所有的審核與管理工具, 在您自己的硬體上。

這意味著您可以掌控您的資料,且留言系統可以限制在您本地區域網路或企業網路內。


執行個體 Internal Link

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).

設定 Internal Link

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:

電子郵件設定
Copy Copy
1
2{
3 "defaultDKIM": {
4 "domainName": "mycompany.org",
5 "keySelector": "2024",
6 "privateKey": "-----BEGIN PRIVATE KEY-----\nABCDEFG\n-----END PRIVATE KEY-----"
7 },
8 "providerTransports": {
9 "yahoo.com": "specialTransport"
10 },
11 "defaultTransport": "mailgun",
12 "transports": {
13 "mailgun": {
14 "host": "smtp.mailgun.org",
15 "port": 587,
16 "secure": false,
17 "auth": {
18 "user": "admin@somewhere.com",
19 "pass": "password"
20 },
21 "tls": {
22 "ciphers": "SSLv3"
23 }
24 },
25 "specialTransport": {
26 "host": "smtp.someplace.org",
27 "port": 587,
28 "secure": false,
29 "auth": {
30 "user": "admin@example.com",
31 "pass": "password"
32 },
33 "tls": {
34 "ciphers": "SSLv3"
35 }
36 }
37 }
38}
39

在上方範例中,我們定義了一個名為 mailgun 的預設 SMTP 電子郵件傳輸。我們也定義了一個專門用於 @yahoo.com 電子郵件的特殊傳輸。在某些情境下,針對特定網域使用特定提供者或發送 IP 以調整投遞是可取的。此項為選用。

DocumentDB

連線到 DocumentDB 時,您會想要指定 MONGO_ENABLE_SSL=true MONGO_SSL_CA=/some/path.pem,以相容於預設設定。


資料庫停機與維護模式 Internal Link

FastComments 支援自動維護模式。如果資料庫當機,它仍能繼續提供熱門留言討論串。

此外,在維護模式中,所有留言會被儲存到 BACKUP_DIR。系統恢復上線後,這些留言會被處理(檢查垃圾訊息等)並儲存。

它的作法是每小時判定最熱門的前 100 個留言討論串,並將其內容快取到磁碟上。 判定前 100 名討論串是從預先計算好的狀態取得,所以這不是一個耗資源的週期性工作。

這是完全可選的,只有在設定了 CACHE_DIRBACKUP_DIR 時才會啟用。這當然會使應用節點具有狀態,但這些狀態可以在任何時候遺失,而不會導致應用錯誤運作。

注意,在維護模式中無法對留言討論串進行正確的驗證,因此只有被視為公開且安全的討論串會定期備份。

在維護模式下,許多功能將無法使用。

Widget 程式碼 Internal Link


On-Prem 的前端程式碼範例與函式庫與 SaaS 產品相同。然而,您必須指定 apiHost 並使用正確的腳本路徑:

內部部署評論程式碼
Copy Copy
1
2<script src="https://my.host.com/js/embed-v2.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5 FastCommentsUI(document.getElementById('fastcomments-widget'), {
6 tenantId: "demo",
7 apiHost: "https://my.host.com"
8 // ... 也可以傳遞 SSO 載荷等。
9 });
10</script>
11

上述是一個非常簡單的範例。我們也可以使用官方第一方的 React、Angular、Vue、Svelte 等函式庫。


API Internal Link

API 可以像一般的 SaaS 產品一樣存取,您會登入 On-Prem 儀表板來建立 API 金鑰,並使用這些金鑰來存取 API。API 端點在 on-prem 與 SaaS 產品相同。

多個網域 Internal Link

您的 On-Prem FastComments 安裝可以為多個內部網域提供留言功能,例如 app.mycorp.orghr.mycorp.org。您可以分別為這些 進行設定,但可透過建立個別的自訂規則(Customization Rules)在同一個 On-Prem 設定中託管它們,並配置它們各自的行為。

安全性 Internal Link

預設情況下,FastComments 假定評論串為公開。要增加一層安全性,建議建立一個自訂規則並勾選 Requires SSO 選項。這將導致所有與評論相關的端點需要 SSO 身份驗證。

結論

您已閱讀完 On Prem 文件的全部內容。請在下方告訴我們您有任何進一步的意見或問題 - 您 也可以透過 支援頁面 與我們聯絡。