Skip to content

本篇为 juicefs 在 Windows Server 系统上的安装,并使用。再通过 WinSW 将 juicefs 注册为 Windows 系统服务。

juicefs 下载

windows 需要采用 winfsp-fuse 挂在网络磁盘,因此需要先安装 winfsp。

dfs-install-software

安装 winfsp 后,再启动 juicefs。

dfs-windows-install-winfsp-step2

juicefs 为 go 语言实现,默认下载的 juicefs 解压有仅一个文件和几个 LICENSE 声明文件。

dfs-windows-unzip-juicefs

juicefs 初始化文件系统

shell
juicefs mount redis://localhost:6379/1 H: -v --writeback
juicefs mount redis://<username>:<password>@localhost:6379/1 H: -v --writeback

juicefs format --storage file --bucket /Users/zhenqin/study/juicefs/local sqlite3:///Users/zhenqin/study/juicefs/data/myjfs.db myjfs

juicefs format --storage file --bucket D:/dfs/jfs sqlite3://D:/dfs/data/myjfs.db myjfs
juicefs mount sqlite3://D:/dfs/data/myjfs.db H: -v --writeback

部分参数含义:

  • -storage 默认file,文件系统,支持:oss 等
  • --bucket 本地实际文件存储地址,默认为 C:/jfs/data

其他支持的参数,可通过 juicefs format --help 查看。

juicefs 挂在为本地文件系统

为了让文件系统可以在后台保持挂载,你可以在挂载时指定 -d 或 --background 选项,即让客户端在守护进程中挂载文件系统:

shell
juicefs mount sqlite3://myjfs.db ~/jfs -d

windows 执行, 则在磁盘挂在了 H 盘。

shell
juicefs mount sqlite3://D:/dfs/data/myjfs.db H: -v --writeback

dfs-windows-mount-juicefs

最后执行以下命令可以将挂载点 ~/jfs 卸载:

shell
juicefs umount ~/jfs

采用 mysql 作为元数据存储

安装 mysql后,创建数据库:

sql
CREATE DATABASE `jfs` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin

创建一个 jfs 的用户,并赋予其访问权限:

sql
GRANT SELECT, INSERT, UPDATE, REFERENCES, DELETE, CREATE, DROP, ALTER, INDEX, TRIGGER, CREATE VIEW, SHOW VIEW, EXECUTE, ALTER ROUTINE, CREATE ROUTINE, CREATE TEMPORARY TABLES, LOCK TABLES, EVENT ON `jfs`.* TO 'jfs'@'%';

GRANT GRANT OPTION ON `jfs`.* TO 'jfs'@'%';

启动参数:

shell
juicefs format --storage file --bucket D:/path/dfs/jfs mysql://user:password@(ip:port)/jfs myfs
juicefs mount mysql://user:password@(ip:port)/jfs H: -v --writeback

juicefs-windows-use-mysql

添加配额

shell
juicefs quota set $METAURL --path /test --capacity 0 --inodes 0

PRO:

shell
juicefs format --storage file --bucket D:/dfs/jfs mysql://jfs:ps@(192.168.252.37:3566)/jfs myjfs
juicefs mount mysql://jfs:ps@(192.168.252.37:3566)/jfs H: -v --writeback
juicefs gateway mysql://jfs:ps@(192.168.252.37:3566)/jfs 0.0.0.0:9000

Redis 尝试(Redis 需要 4.0 以上):

shell
juicefs format --storage file --bucket D:/dfs/jfs redis://localhost:6379/1 myjfs

juicefs mount -o allow_other,writeback_cache mysql://jfs:ps@(192.168.252.37:3566)/jfs H: -v --writeback

etcd:

shell
juicefs format --storage file --bucket D:/dfs/jfs etcd://192.168.252.204:2379/jfs myj'f's
juicefs mount -o allow_other,writeback_cache etcd://192.168.252.204:2379/jfs H: -v --writeback

回收站

回收站默认开启,文件被删除后的保留时间默认配置为 1 天,可以有效防止数据被误删除时造成的数据丢失风险。

不过回收站开启以后也可能带来一些副作用,如果应用需要经常删除文件或者频繁覆盖写文件,会导致对象存储使用量远大于文件系统用量。这本质上是因为 JuiceFS 客户端会将对象存储上被删除的文件或者覆盖写时产生的需要垃圾回收的数据块持续保留一段时间。因此,在部署 JuiceFS 至生产环境时就应该考虑好合适的回收站配置,回收站保留时间可以通过以下方式配置(如果将 --trash-days 设置为 0 则表示关闭回收站特性):

新建文件系统:通过 juicefs format <META> --trash-days <value> 选项设置

已有文件系统:通过 juicefs config <META> --trash-days <value> 选项修改

注册为 Windows 系统服务

采用 WinSW 将 juicefs 注册为 Windows 系统服务,方便管理。

下载 WinSW,解压到 juicefs.exe 同目录,重命名 WinSW-x64.exe 为 juicefs-install.exe。

并创建:juicefs-install.xml 文件,内容如下:

xml
<service>
  <!-- ID of the service. It should be unique across the Windows system-->
  <id>juicefs</id>
  <!-- Display name of the service -->
  <name>JuiceFS Service</name>
  <!-- Service description -->
  <description>JuiceFS分布式文件系统服务</description>

  <startmode>Automatic</startmode>
  <!-- Path to the executable, which should be started -->
  <executable>%BASE%\juicefs.exe</executable>
  <arguments>mount mysql://user:password@(host:port)/jfs H: -v --writeback</arguments>
  <autoRefresh>true</autoRefresh>
</service>

以管理员身份执行cmd,切换到exe所在目录,执行如下命令即可安装为windows 系统服务。

shell
juicefs-install.exe install

除 install 之外,还有如下命令:

  • install 安装服务
  • uninstall 卸载服务
  • start 启动服务
  • stop 停止服务
  • restart 重启服务
  • status 查看服务状态

注册为服务后,管理服务:

  1. 首先启动mysql;
  2. 以管理员身份运行command,跳转到 D:\exlive3\dfs 目录下,手动启动;
  3. DFS 已经安装为 windows 系统服务,可到系统管理》服务,找到 juicefs 启动或重启服务;
  4. 或者管理员身份运行command:sc query/start/stop/restart juicefs

Q&A 问题记录

经过切换多个元数据库,redis、mysql、sqllite3、etcd 等,创建的 FS 均无法正常读取,因此问题在于 juicefs-winfsp 环节。

读取文件时,juicefs mount 的输出日志:

shell
2025/01/14 18:42:28.493485 juicefs[8996] <WARNING>: GET chunks/0/24/24577_0_2207744: open D:\dfs\jfs\livefs\chunks\0\24\24577_0_2207744: The system cannot find the path specified.; retrying [cached_store.go:710]
2025/01/14 18:42:28.494427 juicefs[8996] <DEBUG>: GET chunks/0/24/24577_0_2207744 (req_id: "", err: open D:\dfs\jfs\livefs\chunks\0\24\24577_0_2207744: The system cannot find the path specified., cost: 0s) [cached_store.go:669]
2025/01/14 18:42:28.495400 juicefs[8996] <WARNING>: fail to read sliceId 24577 (off:0, size:32768, clen: 2207744, inode: 6147): get chunks/0/24/24577_0_2207744: open D:\dfs\jfs\livefs\chunks\0\24\24577_0_2207744: The system cannot find the path specified. [reader.go:809]
2025/01/14 18:42:28.495400 juicefs[8996] <WARNING>: fail to read sliceId 24577 (off:32768, size:2174976, clen: 2207744, inode: 6147): get chunks/0/24/24577_0_2207744: open D:\dfs\jfs\livefs\chunks\0\24\24577_0_2207744: The system cannot find the path specified. [reader.go:809]