> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-pro.ayaka.space/on-premises/zh-tw/she-ding/overleaf-toolkit/s3.md).

# S3

{% hint style="info" %}
本文件涵蓋 Server CE 和 Overleaf Pro 中 S3 的設定。A [獨立的指南](/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>專案歷史 blob</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://overleaf-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.
