# NFS 服务器访问

> 通过 NFS 在网络上导出 AgentFS
> Canonical HTML: https://tursodb.cn/zh-cn/docs/agentfs/guides/nfs/
> Upstream Source (MIT): https://docs.turso.tech/agentfs/guides/nfs
> Language: zh-CN

---
AgentFS 可以通过 NFS 暴露文件系统，从而支持从其他机器、容器或虚拟机进行远程访问。

## 启动 NFS 服务器

```bash
agentfs serve nfs my-agent
```

默认情况下，该服务器监听 `127.0.0.1:11111`。

### 绑定到所有接口

要允许远程访问：

```bash
agentfs serve nfs my-agent --bind 0.0.0.0 --port 2049
```

<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">警告</div><div class="doc-callout-body">

在 `0.0.0.0` 上暴露 NFS 会使文件系统对任何能够访问你机器的人可见。生产部署中请使用防火墙规则或 VPN。

</div></div>


## 挂载文件系统

### 从同一台机器挂载

```bash
mkdir /mnt/agentfs
mount -t nfs -o vers=3,tcp,port=11111,mountport=11111,nolock 127.0.0.1:/ /mnt/agentfs
```

### 从远程机器挂载

```bash
mount -t nfs -o vers=3,tcp,port=2049,mountport=2049,nolock server-ip:/ /mnt/agentfs
```

### 挂载选项说明

| 选项 | 描述 |
| - | - |
| `vers=3` | 使用 NFSv3 协议 |
| `tcp` | 使用 TCP 传输 |
| `port=11111` | NFS 服务器端口 |
| `mountport=11111` | 挂载协议端口 |
| `nolock` | 禁用文件锁定（单用户） |

## 卸载

```bash
umount /mnt/agentfs
```

如果挂载点忙：

```bash
umount -f /mnt/agentfs  # 强制卸载
# 或
umount -l /mnt/agentfs  # 延迟卸载
```

## 后续步骤

<div class="doc-cards">
<a class="doc-card" href="/zh-cn/docs/agentfs/guides/mcp/"><div class="doc-card-title"><span>MCP 服务器</span><span class="doc-card-arrow" aria-hidden="true">→</span></div><p class="doc-card-desc">通过 MCP 暴露 AgentFS</p></a>
<a class="doc-card" href="/zh-cn/docs/agentfs/guides/sync/"><div class="doc-card-title"><span>与 Turso Cloud 同步</span><span class="doc-card-arrow" aria-hidden="true">→</span></div><p class="doc-card-desc">备份并共享 agent 状态</p></a>
</div>
