# 网络文件存储

网络文件存储 (NAS) 通过网络提供集中的文件级存储。Alluxio 可以连接到 NAS 系统，使其作为底层文件系统 (UFS) 可用。

本指南涵盖了将 Alluxio 连接到 NAS 的两种主要方法：

1. **通过 NFS 协议（推荐）**：Alluxio 使用其内置的 NFS 客户端通过网络直接连接到 NAS 服务器。这是推荐的方法，因为它避免了在每个节点上管理系统级挂载的需要。
2. **通过主机路径（本地挂载）**：将 NAS 卷挂载到每个 Alluxio 节点的本地文件系统上。Alluxio 将其视为本地目录进行交互。

## 方法 1：通过 NFS 协议连接到 NAS（推荐）

此方法使用 Alluxio 的内部 NFS v3 客户端直接连接到 NAS 服务器。它不需要在主机节点上挂载 NAS。

### 先决条件

在开始之前，请确保您已准备好以下信息：

| 参数                       | 描述                                 | 示例              |
| ------------------------ | ---------------------------------- | --------------- |
| `<NAS_SERVER_IP>`        | NAS 服务器的 IP 地址。                    | `192.168.1.100` |
| `<NAS_EXPORT_PATH>`      | NAS 服务器上导出目录的绝对路径。                 | `/exports/data` |
| `<NAS_SERVER_AUTHORITY>` | 您定义的用于在 Alluxio 中标识此 NAS 服务器的唯一名称。 | `my-nas-server` |

### 1. 配置和挂载

您可以使用 `nas://` UFS 方案挂载 NFS 共享。

**挂载选项：**

| 属性                       | 描述                             | 默认值        |
| ------------------------ | ------------------------------ | ---------- |
| `fs.nas.ipAddress`       | **（必需）** NAS 服务器的 IP 地址。       |            |
| `fs.nas.service.version` | NFS 协议版本。**目前仅支持“3”。**         | "3"        |
| `fs.nas.uid`             | Alluxio 将用于访问 NFS 共享上文件的用户 ID。 | "0" (root) |
| `fs.nas.gid`             | Alluxio 将用于访问 NFS 共享上文件的组 ID。  | "0" (root) |

**使用 Kubernetes Operator：**

使用所需的挂载选项创建 `UnderFileSystem` 资源。

```yaml
# ufs.yaml
apiVersion: k8s-operator.alluxio.com/v1
kind: UnderFileSystem
metadata:
  name: alluxio-nas-nfs
  namespace: alx-ns
spec:
  alluxioCluster: alluxio-cluster
  path: nas://<NAS_SERVER_AUTHORITY>/<NAS_EXPORT_PATH>/
  mountPath: /nas-nfs
  mountOptions:
    fs.nas.ipAddress: <NAS_SERVER_IP>
    fs.nas.uid: "0"
    fs.nas.gid: "0"
    fs.nas.service.version: "3"
```

**使用命令行 (CLI)：**

```shell
bin/alluxio mount add --path /nas \
  --ufs-uri "nas://<NAS_SERVER_AUTHORITY>/<NAS_EXPORT_PATH>/" \
  --option fs.nas.ipAddress=<NAS_SERVER_IP> \
  --option fs.nas.uid=0 \
  --option fs.nas.gid=0 \
  --option fs.nas.service.version=3
```

> **注意**：挂载导出的根目录时，请在 UFS URI 中包含尾部斜杠（例如 `/exports/data/`）。`NAS_SERVER_AUTHORITY` 是 Alluxio 用于区分不同 NAS 挂载的逻辑名称，不必是真实的主机名。

### 2. 高级配置

您可以在 `alluxio-site.properties` 中调整以下参数，或将其作为挂载选项 (`--option key=value`) 提供以优化性能。

| 属性                                                                   | 描述                                                | 默认值   |
| -------------------------------------------------------------------- | ------------------------------------------------- | ----- |
| `alluxio.underfs.nas.inputstream.max.buffer.size`                    | 从 NAS 读取数据时输入流的最大缓冲区大小。较大的缓冲区可以提高顺序读取性能，但会消耗更多内存。 | `8MB` |
| `alluxio.underfs.nas.liststatus.iterable.max.byte.size.per.response` | 目录列表操作的单个响应的最大大小。这有助于在列出包含大量文件的目录时防止内存问题。         | `4MB` |

***

## 方法 2：将 NAS 挂载为本地文件系统（主机路径）

在此方法中，您将 NAS 共享挂载到所有 Alluxio 节点上的一致本地路径。然后，Alluxio 挂载此本地路径。

### 先决条件

* 可通过网络访问共享的 NAS 服务器。
* NAS 共享挂载在每个 Alluxio 节点上的**相同本地路径**（例如 `/mnt/nas-share`）。
* 您对运行 Alluxio 进程的用户具有此本地挂载点的读/写权限。

### 1. 在节点上本地挂载 NAS

在配置 Alluxio 之前，您必须首先将 NAS 共享挂载到每个 Alluxio 节点上的本地目录。执行此操作的步骤取决于您的 NAS 和操作系统。确保所有节点上的挂载点都相同。

### 2. 在 Alluxio 中挂载

一旦 NAS 作为本地目录可用，您就可以将其挂载到 Alluxio 中。UFS URI 将使用 `file:///` 方案。

**使用 Kubernetes Operator：**

如果使用 Alluxio Operator，则必须将主机路径暴露给 Alluxio Pod，然后创建 `UnderFileSystem` 资源。

1. **在 `AlluxioCluster` 中暴露主机路径：**

   <pre class="language-yaml"><code class="lang-yaml"><strong># alluxio-cluster.yaml
   </strong>apiVersion: k8s-operator.alluxio.com/v1
   kind: AlluxioCluster
   spec:
     hostPaths:
       # This makes the node's /mnt/nas-share available inside the pod at /ufs/nas
       worker:
         /mnt/nas-share: /ufs/nas
       coordinator:
         /mnt/nas-share: /ufs/nas
       fuse:
         /mnt/nas-share: /ufs/nas
   </code></pre>
2. **创建 `UnderFileSystem` 挂载：**

   ```yaml
   # ufs.yaml
   apiVersion: k8s-operator.alluxio.com/v1
   kind: UnderFileSystem
   metadata:
     name: alluxio-nas-local
     namespace: alx-ns
   spec:
     alluxioCluster: alluxio-cluster
     # Path inside the pod
     path: file:///ufs/nas
     # Desired path in Alluxio's namespace
     mountPath: /nas
   ```

**使用命令行 (CLI)：**

如果 NAS 挂载在 Alluxio 服务器上的 `/mnt/nas-share`，请使用以下命令：

```shell
bin/alluxio mount add --path /nas/ --ufs-uri file:///mnt/nas-share
```

## 权限和身份

* **方法 1 (NFS 协议)**：文件权限由挂载选项中提供的 `uid` 和 `gid` 决定。Alluxio 以此用户/组的身份在 NFS 服务器上执行所有文件操作。确保指定的 `uid`/`gid` 在 NFS 导出上具有正确的权限。
* **方法 2 (主机路径)**：文件权限由运行 Alluxio 进程的用户决定。该用户必须在本地 NAS 挂载点上具有必要的读/写权限。


---

# Agent Instructions: 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:

```
GET https://documentation.alluxio.io/ee-ai-cn/ufs/nas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
