开源Web文件管理器filebrowser

https://github.com/filebrowser/filebrowser

https://filebrowser.org/installation.html

使用版本

v2.45.0

解压

1
2
3
4
mkdir -p /data/local/filebrowser
cd /data/local/
tar -zxvf linux-amd64-filebrowser.tar.gz -C /data/local/filebrowser/
chmod +x /data/local/filebrowser/filebrowser

添加环境变量

1
2
3
4
5
6
7
8
grep -qxF 'export PATH=/data/local/filebrowser:$PATH' /etc/profile || \
echo 'export PATH=/data/local/filebrowser:$PATH' >> /etc/profile

#vim /etc/profile
#export PATH=$PATH:/data/local/mysql/bin
# 使环境变量生效

source /etc/profile

创建配置文件

vim /data/local/filebrowser/config.json

1
2
3
4
{
"database":"/data/local/filebrowser/filebrowser.db",
"log":"/data/local/filebrowser/filebrowser.log"
}

初始化配置文件

这里不建议指定 --scope upload--perm.admin 选项,因为会作为新增用户的默认配置。

1
2
3
4
5
6
# filebrowser config init [flags]    初始化配置文件。相当于生成一份基础配置。
filebrowser config init --help

# 初始化配置文件,指定监听地址和端口,指定语言。
rm -rf /data/local/filebrowser/filebrowser.db # 删除已存在的数据库
filebrowser -c /data/local/filebrowser/config.json config init --address 0.0.0.0 --port 8999 --locale zh-cn

修改配置文件

1
2
3
4
5
6
# filebrowser config set [flags]     修改已有配置。
filebrowser config set --help

# --root 设置根目录(filebrowser 能管理的文件起点)。用户登录后默认能看到并管理该目录下的文件。
# --scope 设置全局访问范围(Scope),用来限制用户能访问的路径。使用 --root 指定根目录后,scope 仅表示相对路径(默认 .),否则就是绝对路径。
filebrowser -c /data/local/filebrowser/config.json config set --root /data/local --scope /filebrowser/common

查看配置

1
2
3
4
filebrowser config --help

# filebrowser config cat [flags]
filebrowser -c /data/local/filebrowser/config.json config cat

查看用户

1
2
3
4
filebrowser users --help

# filebrowser users ls [flags]
filebrowser -c /data/local/filebrowser/config.json users ls

添加用户

1
2
3
4
5
# filebrowser users add <username> <password> [flags]
# --perm.admin 赋予该用户管理员权限,可以管理 filebrowser 的所有设置和用户。
# --scope /admin 限制用户的访问范围(Scope),只能访问 /admin 目录下的内容。优先级高于全局访问范围!!!!!!
filebrowser -c /data/local/filebrowser/config.json users add admin 123456789@abcdefg --perm.admin --scope .
filebrowser -c /data/local/filebrowser/config.json users add zhaolq 123456789@abcdefg --scope /filebrowser/common

更新用户

1
2
# 语法 filebrowser users update <id|username> [flags]
filebrowser -c /data/local/filebrowser/config.json users update zhaolq --scope /filebrowser/common

删除用户

1
2
# id为1的用户默认无法删除
filebrowser -c /path/to/config.json users rm zhaolq

启动

1
2
3
filebrowser --config /data/local/filebrowser/config.json
#
filebrowser -c /data/local/filebrowser/config.json

开机自启

vim /etc/systemd/system/filebrowser.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=File Browser
After=network.target

[Service]
# Type=forking 会导致 systemctl start service 阻塞
Type=simple
User=root
Group=root
ExecStart=/data/local/filebrowser/filebrowser --config /data/local/filebrowser/config.json
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target

systemctl 管理

1
2
3
4
systemctl daemon-reload
systemctl start filebrowser
systemctl stop filebrowser
systemctl enable filebrowser