> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bitiful.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bitiful.com/_mcp/server.

# Bitifs 进阶配置

> Bitifs 的密钥配置、开机自动挂载、多用户访问、性能参数、写入可靠性、限制与常见问题。

## 保存密钥

把密钥写进文件，就不用每次设置环境变量。

**Windows**

写进 `C:\Users\用户名\.aws\credentials`，文件没有扩展名，不要存成 `credentials.txt`：

```ini title="C:\Users\用户名.aws\credentials"
[s4]
aws_access_key_id = 你的AccessKey
aws_secret_access_key = 你的SecretKey
```

```powershell
.\bitifs.exe --profile s4 my-bucket B:
```

**macOS**

写进 `~/.aws/credentials`：

```ini title="~/.aws/credentials"
[s4]
aws_access_key_id = 你的AccessKey
aws_secret_access_key = 你的SecretKey
```

```bash
chmod 600 ~/.aws/credentials
./bitifs --profile s4 my-bucket ~/bitiful-mount
```

**Linux**

写进 `~/.aws/credentials`：

```ini title="~/.aws/credentials"
[s4]
aws_access_key_id = 你的AccessKey
aws_secret_access_key = 你的SecretKey
```

```bash
chmod 600 ~/.aws/credentials
./bitifs --profile s4 my-bucket ~/bitiful-mount
```

用 `--shared-config 文件路径` 指定其他位置的密钥文件。

## 开机自动挂载

**Windows**

用 **任务计划程序** 新建任务：触发器选 **登录时**，操作选 **启动程序**，程序填 `C:\bitifs\bitifs.exe`，参数填：

```text
--profile s4 my-bucket B:
```

在任务的 **设置** 里取消 **如果任务运行时间超过以下时间，停止任务**。关机前在弹出的窗口按 `Ctrl+C` 卸载，强制结束任务会丢失还没上传的内容。

**macOS**

先把 `bitifs` 放到 `/usr/local/bin`，再用 `launchd` 在登录时运行挂载命令，并加上 `-f`，让程序在前台运行。

```bash
/usr/local/bin/bitifs -f --profile s4 my-bucket /Users/用户名/bitiful-mount
```

**Linux**

用 systemd：

### 安装程序与密钥

```bash
sudo install -m 755 bitifs /usr/local/bin/bitifs
sudo mkdir -p /etc/bitifs /mnt/my-bucket
```

新建密钥文件：

```ini title="/etc/bitifs/credentials"
[default]
aws_access_key_id = 你的AccessKey
aws_secret_access_key = 你的SecretKey
```

```bash
sudo chmod 600 /etc/bitifs/credentials
```

### 创建服务

```ini title="/etc/systemd/system/bitifs-my-bucket.service"
[Unit]
Description=Bitifs my-bucket
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/bitifs -f --shared-config=/etc/bitifs/credentials my-bucket /mnt/my-bucket
ExecStopPost=-/bin/umount -l /mnt/my-bucket
Restart=on-failure
RestartSec=5
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target
```

`-f` 让程序在前台运行，由 systemd 管理。停止服务时会先把未上传的内容传完，所以 `TimeoutStopSec` 要留够。

### 启动

```bash
sudo systemctl daemon-reload
sudo systemctl enable --now bitifs-my-bucket
ls /mnt/my-bucket
```

## 多用户访问

**Windows**

盘符只在执行挂载的登录会话里可见，没有 `allow_other` 选项。

- 其他用户请登录后各自挂载。
- 以管理员身份运行的程序看不到普通窗口挂载的盘符，请在管理员窗口里挂载。

直接运行挂载盘里的程序，需要加 `--file-mode 0755`：

```powershell
.\bitifs.exe --profile s4 --file-mode 0755 my-bucket B:
```

**macOS**

默认只有执行挂载的用户能访问。要让其他用户和服务访问：

```bash
./bitifs --profile s4 -o allow_other --file-mode=0666 --dir-mode=0777 my-bucket ~/bitiful-mount
```

`--uid`、`--gid` 设置文件显示的属主，`--file-mode`、`--dir-mode` 设置显示的权限。

**Linux**

默认只有执行挂载的用户能访问。要让其他用户和服务（例如 Nginx、Docker）访问：

```bash
./bitifs --profile s4 -o allow_other --file-mode=0666 --dir-mode=0777 my-bucket /mnt/my-bucket
```

普通用户使用 `allow_other` 前，要在 `/etc/fuse.conf` 里启用 `user_allow_other`。

`--uid`、`--gid` 设置文件显示的属主，`--file-mode`、`--dir-mode` 设置显示的权限。

## 常用参数

| 参数                     | 默认                 | 说明                          |
| ---------------------- | ------------------ | --------------------------- |
| `--profile`            | `default`          | 使用密钥文件里的哪一组密钥               |
| `-f`                   | 后台运行               | 在前台运行，日志输出到屏幕。Windows 始终在前台 |
| `--log-file`           | 系统日志               | 日志文件路径。前台运行时默认输出到屏幕         |
| `--memory-limit`       | 1000               | 数据缓存最多使用的内存（MB）             |
| `--cache`              | 关闭                 | 数据缓存的磁盘目录，需要先创建             |
| `--stat-cache-ttl`     | 1m                 | 文件信息和目录列表的缓存时间              |
| `--max-flushers`       | 16                 | 上传的并发请求数                    |
| `--max-parallel-parts` | 8                  | 大分片上传的并发数                   |
| `--read-ahead-large`   | 102400             | 连续读取时的预读大小（KB）              |
| `--part-sizes`         | 5:1000,25:1000,125 | 分片大小（MB）与数量                 |
| `--fsync-on-close`     | 关闭                 | 关闭文件时等待上传完成                 |
| `--no-preload-dir`     | 关闭                 | 打开单个文件时不预先列目录，减少列表请求        |
| `--cheap`              | 关闭                 | 牺牲一些性能，减少请求次数               |

完整列表见 `bitifs --help`（Windows 为 `.\bitifs.exe --help`）。

### 调优示例

内存较小的机器：

**Windows**

```powershell
.\bitifs.exe --memory-limit 300 --read-ahead-large 20480 my-bucket B:
```

**macOS**

```bash
./bitifs --memory-limit 300 --read-ahead-large 20480 my-bucket ~/bitiful-mount
```

**Linux**

```bash
./bitifs --memory-limit 300 --read-ahead-large 20480 my-bucket ~/bitiful-mount
```

大带宽上传大文件：

**Windows**

```powershell
.\bitifs.exe --memory-limit 4000 --max-flushers 32 --max-parallel-parts 32 --part-sizes 25 my-bucket B:
```

**macOS**

```bash
./bitifs --memory-limit 4000 --max-flushers 32 --max-parallel-parts 32 --part-sizes 25 my-bucket ~/bitiful-mount
```

**Linux**

```bash
./bitifs --memory-limit 4000 --max-flushers 32 --max-parallel-parts 32 --part-sizes 25 my-bucket ~/bitiful-mount
```

固定 25 MB 分片时，单个文件最大约 250 GB。

## 写入何时生效

写入先进入内存，再异步上传，所以命令返回不代表已经传完。需要确认时：

- macOS、Linux 对单个文件执行 `sync 文件路径`，Windows 执行 `type B:\目录\.fsyncdir`，等这个目录上传完才返回（提示找不到文件是正常的）；也可以在程序里调用 `fsync`；
- 挂载时加 `--fsync-on-close`，关闭文件时等待上传完成，速度会慢一些；
- 正常卸载，会等待全部上传完成。

上传失败会自动重试。**不要** 直接强制结束进程或断电，未上传的内容会丢失。

其他机器或控制台修改的内容，在缓存时间（默认 1 分钟）之后才能看到。需要更快时调小 `--stat-cache-ttl`，请求数会随之增加。

## 限制

- 适合浏览、备份、媒体文件和顺序读写。不要在上面运行数据库或虚拟机磁盘。
- 不支持硬链接。文件锁只在本机有效，多台机器同时写同一个文件，以最后完成的为准。
- `chmod`、`chown` 和修改时间不会保存，显示的权限由挂载参数决定。
- 修改大文件的一部分会重新上传相关分片，频繁的小块改写效率很低。
- 重命名目录时，其中的文件会逐个移动，文件很多时需要时间。
- 默认分片设置下，单个文件最大约 1 TB。

## 费用

每次读写和列目录都会产生 [请求](https://docs.bitiful.com/prices/detail/requests-prices.md) 和 [流量](https://docs.bitiful.com/prices/detail/transfer-prices.md)。让杀毒软件、索引和备份程序排除挂载目录，避免反复扫描。批量迁移请用 [Rclone](https://docs.bitiful.com/clients/rclone.md) 或 [s5cmd](https://docs.bitiful.com/clients/aws-cli.md#s5cmd)，速度更快、请求更少。

## 常见问题

<details>
<summary>挂载成功，但列目录提示 Permission denied 或拒绝访问</summary>

密钥、桶名或权限不对。检查密钥是否多了空格、桶名是否正确、子账户是否有列表权限。只授权了目录时，写成 `my-bucket:目录名`。

</details>

<details>
<summary>提示 stat 挂载点 no such file or directory</summary>

macOS、Linux 的挂载点要先用 `mkdir -p` 创建。Windows 相反，目录挂载点必须不存在。

</details>

<details>
<summary>提示找不到 fuse、fusermount3 或 macFUSE</summary>

没有安装 WinFsp、macFUSE 或 fuse3。macOS 安装后还需要在系统设置里允许系统扩展并重启。

</details>

<details>
<summary>Transport endpoint is not connected</summary>

程序已经退出，但挂载点没有清理。执行 `fusermount3 -uz 挂载点`（Linux）或 `umount -f 挂载点`（macOS），再重新挂载。

</details>

<details>
<summary>其他用户或 Docker 容器看不到文件</summary>

macOS、Linux 没有加 `-o allow_other`；Windows 的盘符只在挂载它的登录会话里可见。见 [多用户访问](https://docs.bitiful.com/bitiful-s4/intro.md#多用户访问)。

</details>

<details>
<summary>读取较慢或内存占用高</summary>

见 [调优示例](https://docs.bitiful.com/bitiful-s4/intro.md#调优示例)。同时打开很多大文件时，适当调大 `--memory-limit` 或调小 `--read-ahead-large`。

</details>

<details>
<summary>如何查看日志</summary>

加 `-f` 在前台运行（Windows 默认就是前台），或用 `--log-file` 写到文件。排查请求问题时再加 `--debug-s3`。

</details>
