这是 Yingpan 项目的 Go 语言重写版本,提供更高性能和更好的并发处理能力。
.
├── cmd/
│ └── server/
│ └── main.go # 主程序入口
├── internal/
│ ├── config/
│ │ └── config.go # 配置管理
│ └── models/
│ └── models.go # 数据模型
├── pkg/
│ ├── api/
│ │ └── server.go # HTTP API 服务器
│ ├── blockmanager/
│ │ ├── blockmanager.go # 块管理器核心
│ │ ├── metadata.go # 元数据管理
│ │ └── ratelimiter.go # 速率限制器
│ ├── compression/
│ │ └── compression.go # 压缩支持
│ ├── fuse/
│ │ └── vdrive.go # FUSE 虚拟驱动
│ ├── nbd/
│ │ └── server.go # NBD 服务器
│ └── webdav/
│ └── client.go # WebDAV 客户端
├── static/
│ └── index.html # Web UI
├── scripts/
│ ├── install-host-deps.sh
│ └── yingpan-mount.sh
├── go.mod # Go 模块定义
├── Dockerfile # Docker 镜像构建
├── docker-compose.yml # Docker Compose 配置
├── Makefile # 构建脚本
└── README.md # 本文件
最简单的方式!无需命令行,图形化配置和操作。
# 1. 安装 rclone
curl https://rclone.org/install.sh | sudo bash
# 2. 编译项目
make build
# 3. 启动 Web UI
./webui
# 4. 在浏览器中打开
# 访问: http://localhost:8001
Web UI 功能:
详细使用说明请参考 WEBUI_GUIDE.md
# 1. 安装 rclone
curl https://rclone.org/install.sh | sudo bash
# 2. 配置 rclone 远程存储
rclone config
# 3. 编译项目
make build
# 4. 一键启动
./quick-start.sh -remote myremote
# 或使用 quickstart 命令
./quickstart -remote myremote -size 100 -cache /mnt/ssd/cache
参数说明:
-remote <name>: rclone 远程存储名称(必需)-disk <name>: 磁盘名称(默认: disk1)-size <GB>: 磁盘大小 GB(默认: 100)-addr <ip:port>: iSCSI 服务地址(默认: 0.0.0.0:3260)-cache <dir>: 缓存目录(默认: /var/cache/yingpan)-block-size <MB>: 块大小 MB(默认: 4)-max-cache <GB>: 最大缓存大小 GB(默认: 50)客户端连接:
Windows:
Linux:
sudo iscsiadm -m discovery -t st -p <iSCSI服务地址>
sudo iscsiadm -m node -T <IQN> -p <iSCSI服务地址> --login
fdisk /dev/sdX
# 1. 安装 Go 依赖工具
sudo apt-get update
sudo apt-get install -y fuse3 libfuse3-dev nbd-client e2fsprogs
# 2. 安装 Go 1.21+
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
# 3. 编译项目
go mod download
go build -o yingpan-server ./cmd/server
# 4. 运行服务器
./yingpan-server
# 服务启动后会监听以下端口:
# - 8001: Web 界面和 API
# - 9000: S3 兼容 API
# - 9001: WebDAV 协议
或使用 Makefile:
# 查看所有可用命令
make help
# 编译
make build
# 安装
make install
{
"computer_name": "my-pc",
"admin_username": "admin",
"admin_password": "admin",
"last_dav_url": "",
"last_dav_user": "",
"last_dav_password": ""
}
配置说明:
computer_name: 计算机名称,用于标识本地机器admin_username: Web 界面和 WebDAV 的登录用户名(默认: admin)admin_password: Web 界面和 WebDAV 的登录密码(默认: admin)last_dav_url, last_dav_user, last_dav_password: 最后使用的 WebDAV 连接信息(自动保存)[
{
"disk_name": "mydisk",
"dav_url": "https://dav.example.com/",
"dav_user": "username",
"dav_password": "password",
"mount_path": "/mnt/fuse_mirror/mydisk",
"cache_dir": "/var/cache/mydisk",
"disk_size_gb": 1024,
"max_cache_gb": 100,
"block_size_mb": 4,
"remote_path": "v_disks/my-computer/mydisk/blocks",
"concurrency": 5,
"inode_ratio": 16384,
"compression": "zstd",
"compression_level": 3,
"driver_mode": "fuse",
"upload_limit_kb": 0,
"download_limit_kb": 0
}
]
启动服务后,在浏览器中访问:
http://localhost:8001
Web 界面登录:
adminadmin通过 WebDAV 访问:
http://localhost:9001http://localhost:9001/[磁盘名]/[文件路径]通过 S3 兼容 API 访问:
http://localhost:9000# 列出所有磁盘(buckets)
s3cmd ls http://localhost:9000
# 列出磁盘内容
s3cmd ls s3://mydisk --host=http://localhost:9000 --host-bucket=/
# 上传文件
s3cmd put localfile.txt s3://mydisk/path/ --host=http://localhost:9000 --host-bucket=/
# 下载文件
s3cmd get s3://mydisk/path/file.txt --host=http://localhost:9000 --host-bucket=/
在 Web 界面中:
FUSE 模式: 磁盘创建后会自动挂载到:
/mnt/fuse_mirror/[磁盘名]
NBD 模式: 磁盘创建后需要手动挂载:
sudo yingpan-mount.sh mount [磁盘名]
挂载点为:
/mnt/nbd/[磁盘名]
首次挂载会自动格式化(mkfs.ext4),可能需要几分钟时间。
像普通磁盘一样使用:
# 查看磁盘空间
df -h /mnt/v_disks/mydisk
# 创建目录
mkdir /mnt/v_disks/mydisk/mydata
# 复制文件
cp -r /path/to/data /mnt/v_disks/mydisk/mydata/
# 查看挂载状态
make status
# 挂载所有磁盘
make mount
# 卸载所有磁盘
make unmount
# 重新挂载所有磁盘
make remount
POST /api/auth/login - 用户登录
{
"username": "admin",
"password": "admin"
}
GET /api/auth/check - 检查认证状态POST /api/system/change-password - 修改管理员密码
{
"old_password": "admin",
"new_password": "newpassword"
}
GET /api/system/config - 获取系统配置POST /api/system/config - 更新系统配置GET /disks - 列出所有磁盘POST /mount - 挂载磁盘POST /unmount/:diskName - 卸载磁盘DELETE /disks/:diskName - 删除磁盘POST /disks/:diskName/cleanup - 清理磁盘POST /api/webdav/list_computers - 列出远程计算机POST /api/webdav/list_disks - 列出远程磁盘POST /api/webdav/get_disk_config - 获取远程磁盘配置POST /cache/prefetch?disk_name=xxx&path=xxx - 预热缓存POST /cache/evict?disk_name=xxx&path=xxx - 释放缓存Yingpan 提供三种访问虚拟磁盘的方式,彼此独立:
适用场景: 本地应用需要像访问本地磁盘一样访问虚拟磁盘
特点:
/mnt/v_disks/[磁盘名] 挂载点适用场景: 跨平台文件访问、Windows 资源管理器、macOS Finder
特点:
http://[服务器]:9001/[磁盘名]/[路径]Windows 挂载:
1. 打开"此电脑" -> "映射网络驱动器"
2. 输入: http://[服务器]:9001/[磁盘名]
3. 输入用户名和密码
macOS 挂载:
# 在 Finder 中按 Cmd+K
# 输入: http://[服务器]:9001/[磁盘名]
适用场景: 云存储工具、S3 客户端、程序化访问
特点:
支持的操作:
GET / - 列出所有 bucket(磁盘)GET /[bucket] - 列出 bucket 内容GET /[bucket]/[key] - 下载对象PUT /[bucket]/[key] - 上传对象DELETE /[bucket]/[key] - 删除对象HEAD /[bucket]/[key] - 获取对象元信息┌─────────────────────────────────────────┐
│ Yingpan Server │
│ ┌──────────┐ ┌──────────┐ ┌────┐ │
│ │Web UI: │ │WebDAV: │ │S3: │ │
│ │:8001 │ │:9001 │ │:9000│ │
│ └────┬─────┘ └────┬─────┘ └─┬──┘ │
│ │ │ │ │
│ └─────┬───────┴────────────┘ │
│ │ │
│ ┌────▼────┐ │
│ │Adapter │ │
│ └────┬────┘ │
└─────────────┼────────────────────────────┘
│
┌──────▼──────┐
│ /mnt/v_disks/│ ← 磁盘挂载点
└─────────────┘
│
┌──────▼──────┐
│ WebDAV 存储 │ ← 云端存储
└─────────────┘
重要说明:
检查 FUSE 模块是否加载:
lsmod | grep fuse
检查挂载点是否已占用:
mount | grep fuse
查看服务日志:
journalctl -u yingpan -f
/var/cache/[磁盘名] 下的文件)Go 版本与 Python 版本在以下方面完全兼容:
可以无缝从 Python 版本迁移到 Go 版本,数据完全互操作。
go test ./...
go vet ./...
golangci-lint run
godoc -http=:6060
欢迎提交 Issue 和 Pull Request!
MIT License