目录
article
[TITLE]
云存储集成指南:Google Cloud 与 Microsoft Azure 配置教程
[DESCRIPTION]
本文详细介绍在 Odoo 中使用云存储,将聊天记录和邮件附件存储到 Google Cloud 或 Microsoft Azure 的完整步骤,包括服务账号创建、存储桶/容器配置、CORS 设置、角色分配以及在 Odoo 中的相应配置,帮助避免数据库服务器负担并提升存储容量。
[KEYWORDS]
云存储, Odoo, Google Cloud, Microsoft Azure, 服务账号, 存储桶, 容器, CORS, 角色分配, 附件大小限制
[TRANSLATED_CONTENT]
---
# 云存储
云存储集成允许将 `chatter <../../productivity/discuss/chatter>` 和邮件附件存储在 `Google Cloud <cloud-storage/google>` 或 `Microsoft Azure <cloud-storage/microsoft>` 平台上,而不是数据库服务器上。
该模块可用于防止大型文件上传到数据库服务器或从数据库服务器下载,或当数据库需要更多数据存储时使用。
:::: note
::: title
注意
:::
- 由 Odoo 生成的文件(例如销售订单)以及 Documents/Sign 应用的文件始终存储在数据库服务器上。
- 数据库的存储上限取决于其托管方案:
- Odoo Online:100 GB
- Odoo.sh:
- 共享托管:512 GB
- 专用托管:4 TB
- 本地部署:受现有基础设施限制。
::::
## Google Cloud {#cloud-storage/google}
首先,注册并登录 [Google Cloud](https://cloud.google.com)。
### 服务账号 {#cloud-storage/google/service}
1. 在 Google Cloud 控制台的导航侧栏中,进入 `IAM & Admin → Service Accounts → Create service account`。
2. 为 **服务账号名称** 填写内容,点击 **Create and continue**,随后 **Done**。

3. 记录服务账号的 **Email**,后续在 `cloud storage bucket configuration <cloud-storage/google/bucket>` 时会用到。
4. 点击 `fa-ellipsis-v`(**操作**)按钮,选择 **Manage keys**。

5. 前往 **Add key → Create new key**,选择 **JSON** 作为 **Key type**,点击 **Create**。安全保存下载的 JSON 密钥文件,后续在 `configuring Odoo <cloud-storage/google/odoo>` 时会用到。

### 云存储桶 {#cloud-storage/google/bucket}
1. 在 Google Cloud 控制台的导航侧栏中,进入 `Cloud Storage → Buckets → Create`。
2. 按照 [桶命名指南](https://cloud.google.com/storage/docs/buckets?_gl=1*h4hwrv*_ga*MTcwNDM2NDE1Ny4xNzQzNzUxOTEy*_ga_WH2QY8WWF5*MTc0Mzc2NDMyOS4zLjEuMTc0Mzc2NDMyOS42MC4wLjA.#naming) 输入桶名称,并记录下来,后续在 `configuring Odoo <cloud-storage/google/odoo>` 时会用到。
3. 按需配置桶属性,完成后点击 **Create**。

4. 点击 `fa-ellipsis-v`(**更多操作**)按钮,选择 **Edit access**。

5. 点击 **Add principal**,在 **New principals** 字段中粘贴服务账号的 Email。
6. 在 **Cloud Storage** 部分,将 **Role** 设为 **Storage Admin**,然后 **Save**。

### Odoo 配置 {#cloud-storage/google/odoo}
1. `Install <general/install>` **Cloud Storage Google** 模块。
2. 打开 **Settings** 应用,在导航侧栏选择 **Cloud Storage**。
3. 将 **Google Cloud Storage** 设为 **新附件的云存储提供商**。
4. 输入前面创建的 **Google Bucket Name**。
5. 在 **Google Service Account Key** 旁点击 **Upload your file**,选择已下载的 JSON 文件。
6. 为要存储到 Google Cloud 的附件设置 **Minimum File Size (bytes)**(最小文件大小)。
## Microsoft Azure {#cloud-storage/microsoft}
首先,注册并登录 [Microsoft Azure](https://azure.microsoft.com)。
### 应用注册 {#cloud-storage/microsoft/app}
1. 在 Azure 门户搜索 **App registrations** 服务并打开。
2. 点击 **New registration**,填写 **Name**,在 **Supported account types** 中选择 **Accounts in any organizational directory (Any Microsoft Entra ID tenant – Multitenant)**,然后 **Register**。

3. 记录 **Application (client) ID** 与 **Directory (tenant) ID**,后续在 `configuring Odoo <cloud-storage/microsoft/odoo>` 时会用到。
4. 在 **Client credentials** 旁点击 **Add a certificate or secret**,选择 **New client secret**,然后 **Add**。
:::: important
::: title
重要
:::
为安全起见,将 **Expires** 设为 **180 天(6 个月)** 或更短的期限。在密钥过期前,需要创建新密钥并在 `Odoo’s configuration <cloud-storage/microsoft/odoo>` 中更新。
:::
5. 复制客户端密钥的 **Value**,安全保存,后续在 `configuring Odoo <cloud-storage/microsoft/odoo>` 时使用。

### 存储账户 {#cloud-storage/microsoft/storage}
1. 搜索 **Storage accounts** 服务,打开后点击 **Create**。
2. 在 **Resource group** 字段下点击 **Create new**,填写 **Name**,确认 **OK**。
3. 输入唯一的 **Storage account name**,并记录下来,后续在 `configuring Odoo <cloud-storage/microsoft/odoo>` 时会用到。
4. 按需配置存储账户,完成后点击 **Review + create**,随后 **Create**。

#### 容器 {#cloud-storage/microsoft/container}
1. 打开刚创建的存储账户资源(可通过搜索名称),在导航侧栏的 **Data storage** 下选择 **Containers**。
2. 输入 **Name**,记录下来(后续在 `configuring Odoo <cloud-storage/microsoft/odoo>` 中使用),点击 **Create**。

#### 资源共享 {#cloud-storage/microsoft/resource}
1. 在存储账户的导航侧栏 **Settings** 中选择 **Resource sharing (CORS)**。
2. 创建第一条 CORS Blob Service 规则:
- **Allowed origins**:[*]
- **Allowed methods**:[GET]
- **Allowed headers**:[Content-Type]
- **Exposed headers**:[Content-Type]
- **Max age**:[0]
3. 创建第二条规则并 **Save**:
- **Allowed origins**:[*]
- **Allowed methods**:[PUT]
- **Allowed headers**:[content-type,x-ms-blob-type]
- **Exposed headers**:[content-type,x-ms-blob-type]
- **Max age**:[0]

#### 角色分配 {#cloud-storage/microsoft/role}
1. 在存储账户的导航侧栏选择 **Access control (IAM)**,点击 **Add** → **Add role assignment**。
2. 搜索 **Storage Blobs Data Contributor**,点击 **Next**。
:::: note
::: title
注意
:::
若需移除不必要的 **delete** 权限,可创建 **custom role <cloud-storage/microsoft/custom>** 并使用该自定义角色。
:::
3. 点击 **Select members**,输入前面已注册的 **application** 名称,选择后 **Select**。
4. 连续点击 **Review + assign** 两次完成分配。

##### 自定义角色 {#cloud-storage/microsoft/custom}
:::: note
::: title
注意
:::
此步骤为 **可选**。移除 **delete** 权限可防止拥有凭证的用户误删云端文件。
::::
1. 打开订阅资源(可通过搜索名称),在导航侧栏选择 **Access control (IAM)**,点击 **Add** → **Add custom role**。
2. 选择 **JSON** 选项卡,点击 **Edit**。复制下方代码,将 **[subscription-id]** 填入 **assignableScopes**,如需更改角色名称,将 **[Custom role]** 替换为自定义名称,完成后 **Save**。
```json
{
"properties": {
"roleName": "Custom role",
"description": "",
"assignableScopes": [
"/subscriptions/subscription-id"
],
"permissions": [
{
"actions": ["Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey/action"],
"notActions": [],
"dataActions": ["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read", "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/add/action"],
"notDataActions": []
}
]
}
}Odoo 配置 {#cloud-storage/microsoft/odoo}
Install <general/install>Cloud Storage Azure 模块。- 打开 Settings 应用,在导航侧栏选择 Cloud Storage。
- 将 Azure Cloud Azure 设为 新附件的云存储提供商。
- 分别填写以下信息:
- Azure Account Name:前面创建的 storage account name
- Azure Container Name:前面创建的 container name
- Azure Tenant ID:目录(租户)ID
- Azure Client ID:应用(客户端)ID
- Azure Client Secret:客户端密钥的值
- 为存储到 Microsoft Azure 的附件设置 Minimum File Size (bytes)(最小文件大小)。
[SUMMARY]
# 云存储集成
## Google Cloud
### 注册 Google Cloud 账户
### 服务账号
#### 创建服务账号
#### 记录 Email
#### 管理密钥(生成 JSON)
### 存储桶
#### 创建存储桶并命名
#### 配置访问(添加主体、授予 Storage Admin)
### Odoo 配置
#### 安装 Cloud Storage Google 模块
#### 在 Settings 中选择 Google Cloud Storage 作为提供商
#### 填写 Bucket 名称、上传 JSON 密钥、设置最小文件大小
## Microsoft Azure
### 注册 Microsoft Azure 账户
### 应用注册
#### 创建应用并命名
#### 记录 Application (client) ID 与 Directory (tenant) ID
#### 添加客户端密钥(设置有效期)
### 存储账户
#### 创建存储账户并命名
#### 配置 CORS 规则(GET 与 PUT)
#### 角色分配(Storage Blobs Data Contributor)
### 容器
#### 创建容器并命名
### 可选自定义角色
#### 删除权限的自定义角色 JSON 示例
### Odoo 配置
#### 安装 Cloud Storage Azure 模块
#### 在 Settings 中选择 Azure 作为提供商
#### 填写账户名、容器名、租户 ID、客户端 ID、客户端密钥、最小文件大小