> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/zh-tw/she-ding/overleaf-toolkit/s3.md).

# S3

{% hint style="info" %}
本文涵蓋在 Server CE 與 Overleaf Pro 中設定 S3。 [一個獨立指南](/on-premises/zh-tw/wei-hu/s3-migration.md) 可找到關於將現有資料遷移到相容 S3 儲存體的內容。
{% endhint %}

## 何時應考慮使用 S3 作為資料儲存

對於少於 1000 個席位的執行個體，我們建議使用本機磁碟儲存並搭配定期 [一致性備份](https://docs.overleaf.com/on-premises/maintenance/data-and-backups#performing-a-consistent-backup).

對於超過 1000 個席位、且本機儲存已達到其容量或吞吐量限制的較大型執行個體，我們建議使用相容 S3 的物件儲存後端，而非 NFS 之類的其他以網路為基礎的儲存解決方案。

## 相容 S3 的物件儲存選項

以下是最受歡迎的相容 S3 物件儲存選項：

* [AWS S3](https://aws.amazon.com/s3/)，為受管理式服務；若在 AWS 上執行 Overleaf CE/Server Pro，我們建議選擇 AWS S3
* [MINIO](https://min.io/)，自行架設
* [Ceph](https://ceph.io/en/)，自行架設
* 其他代管商也提供某種形式的受管理相容 S3 物件儲存；如果你已在該提供商上執行 Overleaf CE/Server Pro，或許可以使用這些服務，而不是自行架設。

## 選擇相容 S3 的物件儲存時的延遲考量

Server CE/Server Pro 執行個體與你的相容 S3 物件儲存之間的延遲，對完成遷移所需時間影響很大。延遲也會影響 Server CE/Server Pro 的檔案上傳效能，而緩慢的檔案下載也會對 PDF 編譯時間造成很大影響。我們建議將 Server CE/Server Pro 執行個體與相容 S3 物件儲存之間的地理距離降到最低。在受管理環境中，這表示要在同一個區域建立 bucket；而在內部部署方案中，則表示讓兩者位於同一校園內。

## S3 設定

我們需要四個「bucket」以及兩個受限制的使用者帳戶。

{% hint style="warning" %}
Bucket 應 **不要** 可公開存取
{% endhint %}

<table data-header-hidden><thead><tr><th width="279"></th><th width="152"></th><th width="97"></th><th></th></tr></thead><tbody><tr><td>Bucket</td><td>用法</td><td>服務</td><td>先前位於 <code>/var/lib/overleaf/data</code></td></tr><tr><td><code>overleaf-user-files</code></td><td>專案使用者檔案</td><td>filestore</td><td><code>user_files</code></td></tr><tr><td><code>overleaf-template-files</code></td><td>範本檔案</td><td>filestore</td><td><code>template_files</code></td></tr><tr><td><code>overleaf-project-blobs</code></td><td>專案歷史 blobs</td><td>歷史與唯讀檔案儲存區</td><td><code>history/overleaf-project-blobs</code></td></tr><tr><td><code>overleaf-chunks</code></td><td>歷史區塊</td><td>history</td><td><code>history/overleaf-chunks</code></td></tr></tbody></table>

你可能想／需要選擇不同的名稱，請務必在所有命令中使用自訂的 bucket。

以下將使用實際憑證的佔位符：

<table><thead><tr><th width="431">環境變數</th><th>說明</th></tr></thead><tbody><tr><td><code>OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID</code></td><td>檔案儲存服務受限制使用者的存取金鑰／使用者名稱。</td></tr><tr><td><code>OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY</code></td><td>檔案儲存服務受限制使用者的密鑰／密碼。</td></tr><tr><td><code>OVERLEAF_HISTORY_S3_ACCESS_KEY_ID</code></td><td>歷史服務受限制使用者的存取金鑰／使用者名稱。</td></tr><tr><td><code>OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY</code></td><td>歷史服務受限制使用者的密鑰／密碼。</td></tr></tbody></table>

Server CE 與 Server Pro 在每個 bucket 上只需要一小組權限：

* 建立物件
* 取得物件
* 刪除物件
* 列出 bucket

### 存取政策

以下是檔案儲存使用者政策的一個範例：

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket"
      ],
      "Resource": "arn:aws:s3:::overleaf-user-files"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::overleaf-user-files/*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
      ],
      "Resource": "arn:aws:s3:::overleaf-project-blobs/*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket"
      ],
      "Resource": "arn:aws:s3:::overleaf-template-files"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::overleaf-template-files/*"
    }
  ]
}
```

以下是歷史使用者政策的一個範例：

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket"
      ],
      "Resource": "arn:aws:s3:::overleaf-project-blobs"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::overleaf-project-blobs/*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket"
      ],
      "Resource": "arn:aws:s3:::overleaf-chunks"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::overleaf-chunks/*"
    }
  ]
}
```

### 變數總覽

#### 使用 AWS S3 時

```bash
# 啟用檔案儲存區的 S3 後端
OVERLEAF_FILESTORE_BACKEND=s3

# 專案檔案的 bucket 名稱
OVERLEAF_FILESTORE_USER_FILES_BUCKET_NAME=overleaf-user-files

# 範本檔案的 bucket 名稱
OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME=overleaf-template-files

# 檔案儲存使用者的金鑰
OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID=...

# 檔案儲存使用者的密鑰
OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY=...

# 你在建立 bucket 時所選擇的 bucket 區域。
OVERLEAF_FILESTORE_S3_REGION=""

# 啟用歷史的 S3 後端
OVERLEAF_HISTORY_BACKEND=s3

# 專案歷史 blobs 的 bucket 名稱
OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET=overleaf-project-blobs

# 歷史區塊的 bucket 名稱
OVERLEAF_HISTORY_CHUNKS_BUCKET=overleaf-chunks

# 歷史使用者的金鑰
OVERLEAF_HISTORY_S3_ACCESS_KEY_ID=...

# 歷史使用者的密鑰
OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY=...

# 你在建立 bucket 時所選擇的 bucket 區域。
OVERLEAF_HISTORY_S3_REGION=""
```

#### 使用自架選項時

```bash
# 啟用檔案儲存區的 S3 後端
OVERLEAF_FILESTORE_BACKEND=s3

# 專案檔案的 bucket 名稱
OVERLEAF_FILESTORE_USER_FILES_BUCKET_NAME=overleaf-user-files

# 範本檔案的 bucket 名稱
OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME=overleaf-template-files

# 檔案儲存使用者的金鑰
OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID=...

# 檔案儲存使用者的密鑰
OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY=...

# S3 提供商端點
OVERLEAF_FILESTORE_S3_ENDPOINT=http://10.10.10.10:9000

# bucket 的路徑樣式定址。你很可能需要將此設為 "true"。
OVERLEAF_FILESTORE_S3_PATH_STYLE="true"

# bucket 區域。你很可能不需要設定這個。
OVERLEAF_FILESTORE_S3_REGION=""

# 啟用歷史的 S3 後端
OVERLEAF_HISTORY_BACKEND=s3

# 專案歷史 blobs 的 bucket 名稱
OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET=overleaf-project-blobs

# 歷史區塊的 bucket 名稱
OVERLEAF_HISTORY_CHUNKS_BUCKET=overleaf-chunks

# 歷史使用者的金鑰
OVERLEAF_HISTORY_S3_ACCESS_KEY_ID=...

# 歷史使用者的密鑰
OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY=...

# S3 提供商端點
OVERLEAF_HISTORY_S3_ENDPOINT=http://10.10.10.10:9000

# bucket 的路徑樣式定址。你很可能需要將此設為 "true"。
OVERLEAF_HISTORY_S3_PATH_STYLE="true"

# bucket 區域。你很可能不需要設定這個。
OVERLEAF_HISTORY_S3_REGION=""
```

### MINIO 設定

{% hint style="info" %}
`MINIO_ROOT_USER` 以及 `MINIO_ROOT_PASSWORD` 是 MINIO 執行個體的 root 憑證。
{% endhint %}

請參閱 [官方文件](https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart) 以取得 `mc`.

```bash
mc alias set s3 http://10.10.10.10:9000 MINIO_ROOT_USER MINIO_ROOT_PASSWORD

# 將上一節政策的內容放入
# 對應的 JSON 檔案 policy-filestore.json 和 policy-history.json 中。

# 提醒：請相應地替換 bucket 名稱與憑證。

# 檔案儲存 bucket、使用者與政策
mc mb --ignore-existing s3/overleaf-user-files
mc mb --ignore-existing s3/overleaf-template-files
mc admin user add s3 \\
  OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID \\
  OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY
mc admin policy create s3 overleaf-filestore policy-filestore.json
mc admin policy attach s3 overleaf-filestore \\
  --user=OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID

# 歷史 bucket、使用者與政策
mc mb --ignore-existing s3/overleaf-project-blobs
mc mb --ignore-existing s3/overleaf-chunks
mc admin user add s3 \\
  OVERLEAF_HISTORY_S3_ACCESS_KEY_ID \\
  OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY
mc admin policy create s3 overleaf-history policy-history.json
mc admin policy attach s3 overleaf-history \\
  --user=OVERLEAF_HISTORY_S3_ACCESS_KEY_ID
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/zh-tw/she-ding/overleaf-toolkit/s3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
