Ubuntu 22.04 安装 ntfy 2.32.0 指南

Ubuntu 22.04 从零安装 ntfy 2.32.0:官方 apt 仓库与 GitHub 二进制两条完整实测方案、systemd 托管、203/EXEC 与缓存目录排障实录、升级回退与卸载清理,全部命令与回显逐条实测于 2026-10-21。

ntfyntfy即时通信2026/10/21

Ubuntu 22.04 安装 ntfy 2.32.0 指南

目标:在 Ubuntu 22.04 服务器上从零安装 ntfy 2.32.0 推送通知服务并完成 systemd 托管与验证,覆盖「官方 apt 仓库安装」与「GitHub release 二进制安装」两条完整方案、方案对比、常见故障实录与卸载清理。全部命令与回显已在 Ubuntu 22.04.5 LTS 环境逐条实测通过(实测版本 ntfy 2.32.0,HTTP 监听端口 8144)。

一、环境信息

本章列出实测环境与关键可复现信息,正文所有命令与回显均来自该环境。

  • 操作系统:Ubuntu 22.04.5 LTS(/etc/os-release 实测 PRETTY_NAME="Ubuntu 22.04.5 LTS"),x86_64/amd64 架构;
  • ntfy 版本:2.32.0(上游最新稳定版,apt 仓库候选版本与 GitHub release 二进制同版本,ntfy version 2.32.0);
  • 实测时间:2026-10-21;
  • HTTP 监听端口:8144(ntfy 默认监听 :80,生产建议显式配置为自定义端口或反代终结;本文以 8144 为例,绑定前已用 ss -ltn 确认空闲);
  • 数据与配置目录(安装后自动/手动创建):
    • 二进制:apt 方案 /usr/bin/ntfy,二进制方案 /usr/local/bin/ntfy;
    • 配置:/etc/ntfy/server.yml(服务端)、/etc/ntfy/client.yml(客户端);
    • 数据:/var/lib/ntfy/(用户数据库 home)、/var/cache/ntfy/(消息缓存与附件缓存);
  • systemd 单元:ntfy.service(服务端)、ntfy-client.service(用户级订阅客户端,本篇不启用);
  • 服务用户:ntfy(系统用户,实测 uid=999)。

二、前置条件

安装前确认系统就绪,逐项验证如下。

2.1 系统与网络

需要一台可联网的 Ubuntu 22.04 服务器(amd64/arm64/armv7 均有官方发布物,本文以 amd64 为例)。验证系统版本与网络可达:

cat /etc/os-release | head -3

实测输出:

PRETTY_NAME="Ubuntu 22.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
curl -sI --max-time 20 https://archive.ntfy.sh/apt/ | head -1

实测输出:

HTTP/1.1 200 OK

2.2 基础工具

确认 curl、gnupg、ca-certificates 已安装(apt 方案下载密钥需要;GitHub 方案下载二进制需要 curl 或 wget):

apt-get install -y curl gnupg ca-certificates apt-transport-https 2>&1 | tail -2

实测输出:

Running hooks in /etc/ca-certificates/update.d...
done.

2.3 端口规划

ntfy 默认监听 :80,若 80 已被 Web 服务占用,需要规划其他端口。用 ss -ltn 探测目标端口是否空闲:

ss -ltn | grep -E ':(80|8144)\b' || echo "80/8144 均空闲"

实测输出:

80/8144 均空闲

⚠️ 注意:本文实验环境以 8144 作为 ntfy 的 HTTP 监听端口(listen-http: ":8144")。若你的服务器 8144 已被占用,换用任意空闲端口并同步修改 2.4 节与方案章中的配置即可。

三、版本选型说明

ntfy 官方提供多条安装路径(来源:官方文档 docs.ntfy.sh/docs/install),本篇覆盖其中两条在 Ubuntu 服务器上最常用的:

  • 方案 A:官方 apt 仓库(archive.ntfy.sh)——Debian/Ubuntu 官方软件仓库,apt install 一键安装并自带 systemd 单元,升级与回退方便;
  • 方案 B:GitHub release 二进制 + systemd——从 GitHub Releases 下载 tar.gz 解压安装,不依赖软件仓库,适合内网手动分发或仓库不可达的场景。

版本选择:上游最新稳定版为 v2.32.0(GitHub Releases Atom 流 updated 时间 2026-10-18,查询日期 2026-10-21;官方 apt 仓库候选版本同为 2.32.0,双源一致)。本篇两方案均安装 2.32.0,与上游最新版一致。

官方 apt 仓库的版本存档覆盖面实测(apt-cache policy ntfy 可见 2.11.0 至 2.32.0 全部历史版本均可安装),需要回退旧版时直接 apt install ntfy=<版本号> 即可,详见 4.6 节。

四、方案 A:官方 apt 仓库安装(推荐)

本章用官方 Debian/Ubuntu 仓库 archive.ntfy.sh 完成「配置密钥 → 配置软件源 → 安装 → 配置 → systemd 托管 → 验证」全流程。

4.1 方案说明

自 2025 年 9 月起,官方仓库地址已迁移为 archive.ntfy.sh,旧地址 archive.heckel.io 仍可用但官方预计 2026 年初逐步淘汰(来源:docs.ntfy.sh/docs/install)。新部署一律使用新地址。仓库 GPG 指纹:55BA 774A 6F5E E674 31E4 B6B7 CFDB 962D 4F1E C4AF。

4.2 配置仓库密钥与软件源

下载密钥环到 apt keyrings 目录:

sudo mkdir -p /etc/apt/keyrings
sudo curl -fL -o /etc/apt/keyrings/ntfy.gpg https://archive.ntfy.sh/apt/keyring.gpg

实测输出(curl 进度 + 文件确认):

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2559  100  2559    0     0   1420      0  0:00:01  0:00:01 --:--:--  1420
ls -l /etc/apt/keyrings/ntfy.gpg
-rw-r--r-- 1 root root 2559 Oct 21 12:46 /etc/apt/keyrings/ntfy.gpg

写入软件源定义:

echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/ntfy.gpg] https://archive.ntfy.sh/apt stable main" | sudo tee /etc/apt/sources.list.d/ntfy.list

实测输出:

deb [arch=amd64 signed-by=/etc/apt/keyrings/ntfy.gpg] https://archive.ntfy.sh/apt stable main

刷新 apt 索引:

sudo apt-get update 2>&1 | tail -4

实测输出:

Get:5 https://archive.ntfy.sh/apt stable InRelease [10.6 kB]
Get:6 https://archive.ntfy.sh/apt stable/main amd64 Packages [4967 B]
Fetched 15.6 kB in 2s (8618 B/s)
Reading package lists...

4.3 确认可用版本并安装

安装前先看仓库提供的版本(也可据此回退):

apt-cache policy ntfy | head -8

实测输出:

ntfy:
  Installed: (none)
  Candidate: 2.32.0
  Version table:
     2.32.0 500
        500 https://archive.ntfy.sh/apt stable/main amd64 Packages
     2.31.1 500
        500 https://archive.ntfy.sh/apt stable/main amd64 Packages
     2.31.0 500
        500 https://archive.ntfy.sh/apt stable/main amd64 Packages
     2.30.0 500
        500 https://archive.ntfy.sh/apt stable/main amd64 Packages

执行安装(deb 包约 30MB,含内嵌 Web App):

sudo apt-get install -y ntfy 2>&1 | tail -5

实测输出:

Setting up ntfy (2.32.0) ...
Processing triggers for man-db (2.10.1-1) ...

验证版本与二进制路径:

ntfy --version && command -v ntfy
ntfy version 2.32.0
/usr/bin/ntfy

4.4 安装产物清单

deb 包安装了哪些文件,用 dpkg -L 核对:

dpkg -L ntfy

实测输出(节选):

/etc
/etc/ntfy
/etc/ntfy/client.yml
/etc/ntfy/server.yml
/lib
/lib/systemd
/lib/systemd/system
/lib/systemd/system/ntfy-client.service
/lib/systemd/system/ntfy.service
/lib/systemd/user
/lib/systemd/user/ntfy-client.service
/usr
/usr/bin
/usr/bin/ntfy
/usr/share
/usr/share/ntfy
/usr/share/ntfy/logo.png
/var
/var/cache
/var/cache/ntfy
/var/cache/ntfy/attachments
/var/lib
/var/lib/ntfy

关键产物:

产物路径说明
二进制/usr/bin/ntfy静态编译单文件
服务端配置/etc/ntfy/server.yml约 550 行注释齐全的默认配置
客户端配置/etc/ntfy/client.ymlCLI 订阅客户端配置
systemd 单元/lib/systemd/system/ntfy.service服务端(默认 disabled)
用户级单元/lib/systemd/user/ntfy-client.service订阅客户端
数据目录/var/lib/ntfy、/var/cache/ntfy/attachments包预创建,属主 ntfy
服务用户ntfy(系统用户)useradd --system 同款权限模型

服务用户与初始服务状态验证:

id ntfy
uid=999(ntfy) gid=1000(ntfy) groups=1000(ntfy)
systemctl status ntfy --no-pager | head -4
○ ntfy.service - ntfy server
     Loaded: loaded (/lib/systemd/system/ntfy.service; disabled; vendor preset: enabled)
     Active: inactive (dead)

💡 说明:apt 安装后服务默认 disabled + inactive,不会自动启动——先改配置再启用是好习惯(下一步先改监听端口)。

4.5 配置监听端口

编辑 /etc/ntfy/server.yml,把默认监听 :80 改为 8144(避开 80 端口的常见占用,也符合最小权限暴露原则)。找到第 22 行注释项并改为实际值:

sudo sed -i 's|^# listen-http: ":80"|listen-http: ":8144"|' /etc/ntfy/server.yml
grep -n '^listen-http' /etc/ntfy/server.yml

实测输出:

22:listen-http: ":8144"

⚠️ 注意:server.yml 默认全部选项处于注释状态(ntfy 用内置默认值运行)。仅取消注释需要改的项,其余保持注释,便于后续版本升级时 diff 配置。

4.6 systemd 托管与开机自启

启用并启动服务(enable --now 可一步完成):

sudo systemctl enable ntfy

实测输出:

Created symlink /etc/systemd/system/multi-user.target.wants/ntfy.service → /lib/systemd/system/ntfy.service.
sudo systemctl start ntfy

(无输出即启动成功。)验证服务状态与监听:

systemctl is-active ntfy
active
ss -ltn | grep 8144
LISTEN 0      4096               *:8144            *:*

4.7 验证服务与首条消息

健康检查端点:

curl -s http://127.0.0.1:8144/v1/health
{"healthy":true,"role":"active"}

首页(内嵌 Web App):

curl -sI http://127.0.0.1:8144/ | head -2
HTTP/1.1 200 OK
Date: Wed, 21 Oct 2026 13:14:08 GMT

发布第一条消息(向 mytopic 主题 POST 正文):

curl -s -d 'Backup done, 3 files uploaded' http://127.0.0.1:8144/mytopic
{"id":"UEnmhAzlJyHS","time":1792588448,"expires":1792631648,"event":"message","topic":"mytopic","message":"Backup done, 3 files uploaded"}

返回 JSON 含 id/time/topic/message 即发布成功;浏览器打开 http://<服务器IP>:8144/ 可见 Web App 并能订阅 mytopic 收到这条消息。

4.8 版本升级与回退(apt 方案)

升级到仓库最新版:

sudo apt-get update && sudo apt-get install --only-upgrade ntfy

回退到指定历史版本(仓库全版本存档,示例回退 2.31.1):

sudo apt-get install ntfy=2.31.1

回退后同样 sudo systemctl restart ntfy 生效;配置文件 /etc/ntfy/server.yml 属于 conffile,包升级不会覆盖你的修改。

五、方案 B:GitHub release 二进制安装 + systemd 托管

本章用 GitHub Releases 的 tar.gz 完成「下载校验 → 解压安装 → 配置 → 用户与单元文件 → systemd 托管 → 验证」全流程。适合仓库不可达、需要固定版本分发、或不想引入第三方软件源的服务器。

5.1 下载与校验

下载官方发布包(v2.32.0 amd64):

wget https://github.com/binwiederhier/ntfy/releases/download/v2.32.0/ntfy_2.32.0_linux_amd64.tar.gz

实测输出(节选):

--2026-10-21 21:14:10--  https://github.com/binwiederhier/ntfy/releases/download/v2.32.0/ntfy_2.32.0_linux_amd64.tar.gz
HTTP request sent, awaiting response... 200 OK
Length: 32405463 (31M) [application/octet-stream]
Saving to: 'ntfy_2.32.0_linux_amd64.tar.gz'
ntfy_2.32.0_linux_amd64.tar.gz     100%[=================================================>]  30.90M  13.2MB/s  in 2.3s

校验 SHA-256(官方 Releases 页公布各文件校验值,本机实测值如下):

sha256sum ntfy_2.32.0_linux_amd64.tar.gz
681819773a69079c0efdd64c096cc2149d9290243feb3e31dd3ef04a2c85f1ed  ntfy_2.32.0_linux_amd64.tar.gz

⚠️ 注意:GitHub 直连慢或不通时,为 wget/curl 配置 HTTP 代理再下载(如 wget -x http://<代理地址> <URL>),校验值不变。

5.2 解压与安装二进制

解压并查看包内容:

tar zxvf ntfy_2.32.0_linux_amd64.tar.gz

实测输出:

ntfy_2.32.0_linux_amd64/LICENSE
ntfy_2.32.0_linux_amd64/README.md
ntfy_2.32.0_linux_amd64/client/client.yml
ntfy_2.32.0_linux_amd64/client/ntfy-client.service
ntfy_2.32.0_linux_amd64/client/user/ntfy-client.service
ntfy_2.32.0_linux_amd64/server/ntfy.service
ntfy_2.32.0_linux_amd64/server/server.yml
ntfy_2.32.0_linux_amd64/ntfy
ls -l ntfy_2.32.0_linux_amd64/ntfy
-rwxr-xr-x 1 1001 1001 75984088 Oct 18 12:44 ntfy_2.32.0_linux_amd64/ntfy

安装二进制到 /usr/local/bin(区别于 apt 方案的 /usr/bin,便于辨别来源):

sudo cp -a ntfy_2.32.0_linux_amd64/ntfy /usr/local/bin/ntfy
ntfy --version
ntfy version 2.32.0

5.3 安装配置文件与服务用户

创建配置目录并放入服务端/客户端默认配置:

sudo mkdir /etc/ntfy
sudo cp ntfy_2.32.0_linux_amd64/server/server.yml ntfy_2.32.0_linux_amd64/client/client.yml /etc/ntfy/
ls -l /etc/ntfy/
total 64
-rw-r--r-- 1 root root  2406 Oct 21 13:15 client.yml
-rw-r--r-- 1 root root 28935 Oct 21 13:15 server.yml

创建 ntfy 系统服务用户(与官方文档一致的参数):

sudo useradd --system --home-dir /var/lib/ntfy --shell /bin/false --comment "User for the simple HTTP-based pub-sub notification service" ntfy
id ntfy
uid=999(ntfy) gid=999(ntfy) groups=999(ntfy)

5.4 安装 systemd 单元文件

查看包内自带单元文件内容:

cat ntfy_2.32.0_linux_amd64/server/ntfy.service
[Unit]
Description=ntfy server
After=network.target

[Service]
User=ntfy
Group=ntfy
ExecStart=/usr/bin/ntfy serve --no-log-dates
ExecReload=/bin/kill --signal HUP $MAINPID
Restart=on-failure
AmbientCapabilities=CAP_NET_BIND_SERVICE
LimitNOFILE=10000
PrivateDevices=true
ProtectClock=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
RestrictRealtime=true
ProtectHostname=true

# These will be added in a future update.
# ProtectSystem=full
# PrivateTmp=true


[Install]
WantedBy=multi-user.target

安装到 systemd 并赋权:

sudo mv ntfy_2.32.0_linux_amd64/server/ntfy.service /etc/systemd/system/ntfy.service
sudo chmod 644 /etc/systemd/system/ntfy.service
sudo systemctl daemon-reload

⚠️ 注意:单元文件的 ExecStart=/usr/bin/ntfy 与本方案二进制实际路径 /usr/local/bin/ntfy 不一致(该单元文件按 deb/rpm 包布局写死 /usr/bin)。直接启动会报 status=203/EXEC 失败,见 5.5 节排障实录;必须先修正路径:

sudo sed -i 's|ExecStart=/usr/bin/ntfy|ExecStart=/usr/local/bin/ntfy|' /etc/systemd/system/ntfy.service
grep '^ExecStart' /etc/systemd/system/ntfy.service
ExecStart=/usr/local/bin/ntfy serve --no-log-dates

5.5 启动失败排障实录(203/EXEC 与目录缺失)

以下是按上述步骤部署时真实发生的两类启动失败,照抄处理即可。

故障一:ExecStart 路径不匹配。未修正路径直接启动:

sudo systemctl enable ntfy && sudo systemctl start ntfy
systemctl status ntfy --no-pager | head -6

实测输出:

Created symlink /etc/systemd/system/multi-user.target.wants/ntfy.service → /etc/systemd/system/ntfy.service.
× ntfy.service - ntfy server
     Loaded: loaded (/etc/systemd/system/ntfy.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2026-10-21 13:15:37 UTC; 687ms ago
    Process: 4216 ExecStart=/usr/bin/ntfy serve --no-log-dates (code=exited, status=203/EXEC)
   Main PID: 4216 (code=exited, status=203/EXEC)

定位:status=203/EXEC 表示 systemd 找不到或无法执行 ExecStart 指定的程序——本方案二进制在 /usr/local/bin/ntfy,单元文件写的是 /usr/bin/ntfy。解决:按 5.4 节修正 ExecStart 路径后:

sudo systemctl daemon-reload
sudo systemctl reset-failed ntfy
sudo systemctl start ntfy

故障二:数据目录缺失。启动后若在配置中启用 cache-file/auth-file(见 5.6 节),而目录不存在,服务会 FATAL 退出:

systemctl status ntfy --no-pager | head -4
journalctl -u ntfy --no-pager -n 3 | tail -3

实测输出:

× ntfy.service - ntfy server
     Loaded: loaded (/etc/systemd/system/ntfy.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2026-10-21 13:23:15 UTC; 9s ago
FATAL cache database directory /var/cache/ntfy does not exist or is not accessible (exit_code=1)
user database directory /var/lib/ntfy does not exist or is not accessible

定位:useradd --home-dir 并不会创建 home 目录,且二进制方案没有 deb 包的预建目录逻辑(deb 包会预创建 /var/cache/ntfy 与 /var/lib/ntfy)。解决:手动创建目录并交给 ntfy 用户:

sudo mkdir -p /var/lib/ntfy /var/cache/ntfy/attachments
sudo chown -R ntfy:ntfy /var/lib/ntfy /var/cache/ntfy
sudo systemctl reset-failed ntfy
sudo systemctl restart ntfy

验证恢复:

systemctl is-active ntfy
active

5.6 配置监听端口

与方案 A 相同,编辑 /etc/ntfy/server.yml:

sudo sed -i 's|^# listen-http: ":80"|listen-http: ":8144"|' /etc/ntfy/server.yml
grep -n '^listen-http' /etc/ntfy/server.yml
22:listen-http: ":8144"
sudo systemctl restart ntfy

5.7 验证

systemctl is-active ntfy && ss -ltn | grep 8144
active
LISTEN 0      4096               *:8144            *:*
curl -s http://127.0.0.1:8144/v1/health
{"healthy":true,"role":"active"}
curl -s -d 'hello from binary install' http://127.0.0.1:8144/mytopic
{"id":"Oc4axT2mNRpH","time":1792589653,"expires":1792632853,"event":"message","topic":"mytopic","message":"hello from binary install"}

💡 说明:enable 自启在 5.5 节故障一处理时已执行(systemctl enable ntfy 创建了软链);若你跳过了该步,执行 sudo systemctl enable ntfy 补上开机自启。

六、方案对比与选择建议

两条方案都能达到同样的运行效果,差异在维护方式:

维度方案 A:apt 仓库方案 B:二进制 + systemd
版本2.32.0(仓库候选版)2.32.0(GitHub release)
是否需联网是(archive.ntfy.sh)下载时需(GitHub),之后离线可部署
安装方式apt install ntfytar.gz 解压 + 手动装单元
systemd 单元来源包自带(/lib/systemd/system/ntfy.service),ExecStart 路径正确包内 tar 自带(需改 ExecStart 路径)
数据目录包预创建 /var/cache/ntfy、/var/lib/ntfy需手动创建并 chown
升级/回退apt upgrade / apt install ntfy=<ver> 一条命令重新下载 tar 覆盖二进制
卸载apt purge ntfy 干净移除(含用户/配置)手动删二进制、单元、目录、用户

选择建议:可联网的 Ubuntu 服务器优先方案 A(升级、回退、卸载全部包管理化,且目录与单元开箱即用);内网隔离、仓库不可达或需要把固定版本包内置入镜像/分发流程时用方案 B(记住 5.5 节的两个坑)。

七、配置说明(两方案通用)

安装完成后至少核对三类配置,均在 /etc/ntfy/server.yml(每处修改后 sudo systemctl restart ntfy 生效)。

监听端口(必改项,默认 :80):

listen-http: ":8144"
  • 默认值 :80;格式 [<ip>]:<port>;设为 - 可禁用 HTTP 仅留 HTTPS(listen-https);
  • 实测改为 :8144 后 ss -ltn | grep 8144 可见 LISTEN *:8144。

对外访问地址(可选,附件/iOS 推送/邮件等功能必需):

base-url: "http://ntfy.example.com:8144"
  • 默认无;启用附件、邮件转发、iOS 及时推送时必须配置;填客户端实际访问的 URL。

消息缓存(持久化)(可选,默认仅内存缓冲、重启丢消息):

cache-file: /var/cache/ntfy/cache.db
cache-duration: "12h"
  • 默认 cache-file 未启用(消息仅内存);启用后消息落 SQLite,重启不丢且支持 since=/poll=1 回放;cache-duration 默认 12h;
  • ⚠️ 二进制方案启用前先建目录并 chown ntfy:ntfy(见 5.5 节故障二);deb 方案的 /var/cache/ntfy 已预创建。

认证与访问控制(可选,默认匿名全开):

auth-file: /var/lib/ntfy/user.db
auth-default-access: deny-all
  • 默认 auth-file 未启用(任何人可发布/订阅任意主题);auth-default-access 默认 read-write;改 deny-all 后需用 ntfy user/ntfy access/ntfy token 建用户、授权、发令牌;
  • 启用方式与「建用户 → 授权 → 发令牌 → 带 token 发布」的全流程实测见本专栏《ntfy 2.32.0 配置参数详解》。

服务管理常用命令(systemd,每条针对单一单元):

systemctl status ntfy        # 查看状态
sudo systemctl restart ntfy  # 改配置后重启
sudo systemctl stop ntfy     # 停止
journalctl -u ntfy -f        # 跟踪日志

实测 journalctl 日志样例(重启后启动成功段):

Oct 21 13:37:05 12c75995d5e1 systemd[1]: Stopped ntfy server.
Oct 21 13:37:05 12c75995d5e1 systemd[1]: Started ntfy server.
Oct 21 13:37:05 12c75995d5e1 ntfy[4988]: INFO Listening on :8144[http], ntfy 2.32.0, log level is INFO (tag=startup)

八、常见问题(FAQ)

Q1:启动报 status=203/EXEC 怎么办? 二进制方案最常见:单元文件 ExecStart=/usr/bin/ntfy 与实际二进制路径不符。确认 command -v ntfy 的输出,把单元文件 ExecStart= 改为该路径,sudo systemctl daemon-reload 后再 start(完整实录见 5.5 节故障一)。

Q2:启动报 FATAL cache database directory ... does not exist 或 user database directory ... does not exist? 启用了 cache-file/auth-file 但目录不存在或属主不对。sudo mkdir -p /var/lib/ntfy /var/cache/ntfy/attachments && sudo chown -R ntfy:ntfy /var/lib/ntfy /var/cache/ntfy 后重启(见 5.5 节故障二)。

Q3:80 端口被占用,ntfy 起不来? ntfy 默认监听 :80,与 Web 服务冲突时改 listen-http 为其他端口(如 8144)再重启;或保持 80 之外的监听、由 Nginx/Caddy 反代对外。改端口是本篇默认动作(4.5/5.6 节)。

Q4:apt 安装后服务没有自动启动? 正常行为:deb 包安装后服务为 disabled/inactive,官方把「先配置再启用」留给管理员。完成配置后 sudo systemctl enable ntfy && sudo systemctl start ntfy。

Q5:手机 App 连不上自建服务器? App 里服务器地址要含协议与端口(如 http://<服务器IP>:8144),且防火墙放行该端口;iOS 用户还需服务端配置 upstream-base-url: "https://ntfy.sh" 才能及时推送(iOS 系统限制,经官方 APNS 中转唤醒,见《ntfy 2.32.0 介绍与选型指南》3.3 节)。

Q6:如何只安装 CLI 客户端不跑服务端? ntfy CLI 与服务端同二进制。装完包后不 enable 服务端单元即可;CLI 用 ntfy publish/ntfy subscribe 对任意服务器(含 https://ntfy.sh)收发,配置读 /etc/ntfy/client.yml。

九、卸载与清理

9.1 方案 A(apt)卸载

停用服务并卸载包(--purge 连配置一起删):

sudo systemctl disable --now ntfy

实测输出:

Removed "/etc/systemd/system/multi-user.target.wants/ntfy.service".
sudo apt-get purge -y ntfy 2>&1 | tail -3

实测输出:

(Reading database ... 7564 files and directories currently installed.)
Purging configuration files for ntfy (2.32.0) ...
dpkg: warning: while removing ntfy, directory '/lib/systemd/user' not empty so not removed

💡 说明:该 warning 属正常——/lib/systemd/user 是系统公共目录,包只删自己那部分。残留的用户级单元 ntfy-client.service 如需清理:sudo rm /lib/systemd/user/ntfy-client.service && sudo systemctl daemon-reload。

删除软件源与密钥(不再使用时):

sudo rm -f /etc/apt/sources.list.d/ntfy.list /etc/apt/keyrings/ntfy.gpg

验证卸载干净:

id ntfy; ls /etc/ntfy; command -v ntfy || echo "ntfy binary removed"

实测输出:

id: 'ntfy': no such user
ls: cannot access '/etc/ntfy': No such file or directory
ntfy binary removed

9.2 方案 B(二进制)卸载

逐项删除安装产物(每条独立执行):

sudo systemctl disable --now ntfy          # 停用并移除自启
sudo rm -f /etc/systemd/system/ntfy.service  # 删单元文件
sudo systemctl daemon-reload                 # 重载 systemd
sudo rm -f /usr/local/bin/ntfy               # 删二进制
sudo rm -rf /etc/ntfy                        # 删配置
sudo rm -rf /var/lib/ntfy /var/cache/ntfy    # 删数据与缓存
sudo userdel ntfy                            # 删服务用户

验证:

systemctl status ntfy --no-pager | head -2; command -v ntfy || echo "binary removed"; id ntfy 2>&1

实测输出:

Unit ntfy.service could not be found.
binary removed
id: 'ntfy': no such user

十、参考链接