本文面向使用 systemd 的 Debian/Ubuntu 主机。qBittorrent Enhanced Edition(qBEE)项目的发布页提供 nox 静态包;不要把它与 userdocs/qbittorrent-nox-static 的独立项目混为一谈。示例固定为 qBEE release-5.2.4.10,升级时先阅读新发布说明并替换版本和校验值。
前置条件#
准备可 sudo 的账户、已挂载且有足够空间的数据盘,并确认下载内容符合当地法律及服务条款。WebUI 默认只应由可信网络访问;以下服务由当前用户运行。
1
2
3
|
sudo apt update
sudo apt install --yes ca-certificates curl unzip
mkdir -p -m 0750 ~/.config/qbittorrent ~/qbittorrent/downloads
|
将 ~/qbittorrent/downloads 替换为实际下载目录。若目录位于独立挂载点,确认该挂载点会在服务启动前可用。
下载并校验固定版本#
先查看架构;该发布的静态 nox 包名称与架构相关。下面只支持 x86_64 和 aarch64,其他架构请在官方发布页选择准确的资产名,不能猜测 URL。
以下示例为 x86_64。GitHub Release API 为该资产公布的 SHA-256 是 c4bb425ffbf356bc8ef49049c6cfa94ff223c8918f5678393c75424c8b98b854;下载前后均应在官方发布页或 API 中重新确认资产名、标签和哈希。curl --fail 会在 HTTP 错误时失败,临时目录避免直接解压到系统路径。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
set -eu
VERSION='release-5.2.4.10'
ASSET='qbittorrent-enhanced-nox_x86_64-linux-musl_static.zip'
SHA256='c4bb425ffbf356bc8ef49049c6cfa94ff223c8918f5678393c75424c8b98b854'
URL="https://github.com/c0re100/qBittorrent-Enhanced-Edition/releases/download/${VERSION}/${ASSET}"
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
curl --fail --location --output "$TMPDIR/$ASSET" "$URL"
printf '%s %s\n' "$SHA256" "$TMPDIR/$ASSET" | sha256sum --check --strict
unzip -q "$TMPDIR/$ASSET" -d "$TMPDIR/extract"
test -x "$TMPDIR/extract/qbittorrent-nox"
sudo install -m 0755 "$TMPDIR/extract/qbittorrent-nox" /usr/local/bin/qbittorrent-nox
/usr/local/bin/qbittorrent-nox --version
|
对于 aarch64,将 ASSET 改为 qbittorrent-enhanced-nox_aarch64-linux-musl_static.zip,并从同一官方发布资产的 digest 字段取得对应 SHA-256 后再运行。不要以未验证的第三方镜像或 latest URL 替换固定版本。
创建 systemd 用户服务#
写入前可备份已有 unit。UMask=0077 使新建配置和下载文件仅当前用户可读;qBittorrent 正常接收 systemd 的停止信号,因此不需要自定义 ExecStop 或 $MAINPID。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
mkdir -p ~/.config/systemd/user
test ! -e ~/.config/systemd/user/qbittorrent.service || \
cp -a ~/.config/systemd/user/qbittorrent.service{,.bak}
tee ~/.config/systemd/user/qbittorrent.service >/dev/null <<'EOF'
[Unit]
Description=qBittorrent Enhanced Edition headless service
Wants=network-online.target
After=network-online.target
[Service]
Type=exec
UMask=0077
WorkingDirectory=%h/qbittorrent
ExecStart=/usr/local/bin/qbittorrent-nox --webui-port=8080
Restart=on-failure
RestartSec=5s
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ReadWritePaths=%h/.config/qbittorrent %h/qbittorrent
[Install]
WantedBy=default.target
EOF
systemd-analyze --user verify ~/.config/systemd/user/qbittorrent.service
systemctl --user daemon-reload
systemctl --user enable --now qbittorrent.service
systemctl --user status qbittorrent.service --no-pager
|
qBittorrent 会在 ~/.config/qbittorrent 保存配置,下载目录为 ~/qbittorrent/downloads。若 systemd-analyze 不存在,至少人工检查 [Unit]、[Service] 和 [Install] 三个段落后再启动。需要退出登录后仍运行时,可按主机策略执行 loginctl enable-linger "$USER"。
首次登录、验证与日志#
服务启动后,从可信网络访问 http://SERVER_IP:8080。不要假定初始密码:近期 qBittorrent 会在首次启动日志中输出临时 WebUI 密码。先用下列命令读取它,登录后立即在 WebUI 修改密码,并在设置中将下载保存路径改为 ~/qbittorrent/downloads。
1
2
3
|
systemctl --user status qbittorrent.service --no-pager
systemctl --user is-active qbittorrent.service
sudo ss -ltnp | grep ':8080'
|
若 8080 不应对公网开放,在云防火墙和主机防火墙中只允许管理网段,或仅用 SSH 端口转发:
1
|
ssh -L 8080:127.0.0.1:8080 USER@SERVER_IP
|
日志持续查看使用 journalctl --user -u qbittorrent.service -f。服务无法启动时,先检查二进制架构、ReadWritePaths 中的目录及当前用户权限,不要直接切换为 root。
更新、回滚与卸载#
更新前备份配置与重要任务数据,并记录当前二进制版本。下载新版本后,按上文在临时目录校验资产;仅在校验通过后替换二进制并重启。保留旧二进制可形成快速回滚。
1
2
3
4
5
|
systemctl --user stop qbittorrent.service
sudo cp -a /usr/local/bin/qbittorrent-nox /usr/local/bin/qbittorrent-nox.previous
# 按“下载并校验固定版本”步骤安装已验证的新二进制。
systemctl --user start qbittorrent.service
journalctl --user -u qbittorrent.service -n 50 --no-pager
|
若新版本异常,停止服务,将 qbittorrent-nox.previous 安装回 /usr/local/bin/qbittorrent-nox,再启动服务。卸载不会自动删除下载或配置:确认备份后再执行。
1
2
3
4
5
|
systemctl --user disable --now qbittorrent.service
rm -f ~/.config/systemd/user/qbittorrent.service
systemctl --user daemon-reload
sudo rm -f /usr/local/bin/qbittorrent-nox
# 确认不再需要配置和下载数据后,才手动删除 ~/.config/qbittorrent 与 ~/qbittorrent/downloads。
|
可选:完成后上传到 rclone#
在 WebUI 的“下载完成时运行外部程序”中可配置 rclone。先以当前用户完成 rclone remote 配置、测试 rclone copy,并记录日志。下例的 move 会在确认远端上传成功后删除本地源文件,属于破坏性操作;未验证前请改用 copy。
1
2
3
|
rclone move "%F" "REMOTE_NAME:PATH/%N" \
--create-empty-src-dirs --transfers=4 --checkers=4 \
--log-file="$HOME/.config/qbittorrent/rclone.log" --log-level=INFO
|
REMOTE_NAME 和 PATH 必须替换为实际 remote 与路径。不要将 remote 凭据、令牌或日志目录放在 /root,也不要让服务账户拥有不必要的远端写权限。
可选:Nginx 反向代理与 TLS#
优先使用 VPN、SSH 隧道或仅允许管理网段的防火墙规则。若必须通过 Nginx 发布,Nginx 仅代理到本机端口;不要同时混用 HTTP-01 的 certbot --nginx 和 Cloudflare DNS-01 的 certbot certonly 流程。二选一并先阅读 Certbot 对应插件文档。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name qb.example.com;
ssl_certificate /etc/letsencrypt/live/qb.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/qb.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
|
部署前运行 sudo nginx -t,成功后才 sudo systemctl reload nginx。DNS-01 凭据文件须为 root 所有且模式 0600,使用最小权限 API token;切勿将令牌写入站点配置或文章。