> 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-cn/pei-zhi/overleaf-toolkit/s3.md).

# S3

{% hint style="info" %}
本文档涵盖 Server CE 和 Overleaf Pro 中 S3 的设置。A [单独的指南](/on-premises/zh-cn/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 兼容对象存储之间的地理距离。在托管环境中，这意味着在同一区域中创建一个存储桶；对于本地部署方案，则应将两者部署在同一园区内。

## S3 设置

我们需要四个“存储桶”和两个受限用户账户。

{% hint style="warning" %}
存储桶应 **不要** 可公开访问
{% 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>存储桶</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>项目历史数据块</td><td>历史记录和只读文件存储</td><td><code>history/overleaf-project-blobs</code></td></tr><tr><td><code>overleaf-chunks</code></td><td>历史分块</td><td>历史记录</td><td><code>history/overleaf-chunks</code></td></tr></tbody></table>

您可能想/需要选择不同的名称，请务必在所有命令中使用自定义存储桶。

以下将使用占位符代替实际凭据：

<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 只需要每个存储桶上的少量权限：

* 创建对象
* 获取对象
* 删除对象
* 列出存储桶

### 访问策略

文件存储用户的策略可能如下所示：

```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

# 项目文件的存储桶名称
OVERLEAF_FILESTORE_USER_FILES_BUCKET_NAME=overleaf-user-files

# 模板文件的存储桶名称
OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME=overleaf-template-files

# 文件存储用户的密钥
OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID=...

# 文件存储用户的密钥
OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY=...

# 创建存储桶时所选的区域。
OVERLEAF_FILESTORE_S3_REGION=""

# 启用历史记录的 S3 后端
OVERLEAF_HISTORY_BACKEND=s3

# 项目历史数据块的存储桶名称
OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET=overleaf-project-blobs

# 历史分块的存储桶名称
OVERLEAF_HISTORY_CHUNKS_BUCKET=overleaf-chunks

# 历史记录用户的密钥
OVERLEAF_HISTORY_S3_ACCESS_KEY_ID=...

# 历史记录用户的密钥
OVERLEAF_HISTORY_S3_SECRET_ACCESS_KEY=...

# 创建存储桶时所选的区域。
OVERLEAF_HISTORY_S3_REGION=""
```

#### 使用自托管选项时

```bash
# 启用文件存储的 S3 后端
OVERLEAF_FILESTORE_BACKEND=s3

# 项目文件的存储桶名称
OVERLEAF_FILESTORE_USER_FILES_BUCKET_NAME=overleaf-user-files

# 模板文件的存储桶名称
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

# 存储桶的路径样式寻址。大概率需要将其设置为 "true"。
OVERLEAF_FILESTORE_S3_PATH_STYLE="true"

# 存储桶区域。大概率无需配置此项。
OVERLEAF_FILESTORE_S3_REGION=""

# 启用历史记录的 S3 后端
OVERLEAF_HISTORY_BACKEND=s3

# 项目历史数据块的存储桶名称
OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET=overleaf-project-blobs

# 历史分块的存储桶名称
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

# 存储桶的路径样式寻址。大概率需要将其设置为 "true"。
OVERLEAF_HISTORY_S3_PATH_STYLE="true"

# 存储桶区域。大概率无需配置此项。
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 中。

# 提醒：请相应替换存储桶名称和凭据。

# 文件存储存储桶、用户和策略
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

# 历史记录存储桶、用户和策略
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-cn/pei-zhi/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.
