
ntfy 安装部署全指南从 Linux 二进制、系统服务到 Docker 与 Kubernetes 的完整实践【免费下载链接】ntfySend push notifications to your phone or desktop using PUT/POST项目地址: https://gitcode.com/GitHub_Trending/nt/ntfy本篇技术指南以 ntfy 官方安装文档docs/install.md为主体系统讲解如何在 Linux、macOS、Windows 上安装 ntfy 的 CLI 与服务端并深入覆盖 systemd/OpenRC 服务化、Debian/RPM 软件源、Docker/docker-compose、KubernetesDeployment/StatefulSet/Pod、Kustomize 与 Helm 等容器化部署方案。读完本文你将掌握 ntfy 从下载即用到生产级自托管的每一类安装路径理解其二进制、配置文件与系统服务的对应关系并能在自己的服务器上独立完成部署与启动。前提说明以下步骤仅适用于自托管 ntfy 服务器或使用 ntfy CLI的场景。如果你只是想通过公共的 ntfy.sh 服务发送消息无需安装任何东西直接用curl即可。安装前的整体认知ntfy 服务器以静态链接的单一二进制形式发布同时提供 tarball、deb/rpm 包以及 Docker 镜像等多种形态官方支持amd64、armv6、armv7 与 arm64四种架构。安装的整体思路非常简单用下述任一方式安装 ntfy可选编辑/etc/ntfy/server.yml配置服务器仅 Linux详见配置文档与仓库中的示例 server.yml可选为非 root 用户创建/编辑~/.config/ntfy/client.ymlmacOS 非 root 用户为~/Library/Application Support/ntfy/client.yml为 root 用户创建/etc/ntfy/client.yml参考示例 client.yml。装好后用ntfy serve启动服务器deb/rpm 包安装时用systemctl start ntfy用ntfy publish发消息用ntfy subscribe订阅主题详见CLI 订阅指南。ntfy 的 CLI 命令通过 main.go 中的cmd.New()注册到urfave/cli框架服务端命令serve的完整参数定义可在 cmd/serve.go 中查看——所有配置项既支持 YAML 文件也支持NTFY_*环境变量与命令行参数三种方式。Linux 二进制安装所有 Linux 二进制与 deb/rpm 包均发布在 releases 页面。下面先介绍下载即运行的临时方案——它适合快速体验但不会注册成开机自启的系统服务。下载并运行临时方案按架构选择对应的 tarball 下载、解压、拷贝并启动。以下以x86_64/amd64为例版本号以你实际下载的 release 为准wget https://github.com/binwiederhier/ntfy/releases/download/v2.27.0/ntfy_2.27.0_linux_amd64.tar.gz tar zxvf ntfy_2.27.0_linux_amd64.tar.gz sudo cp -a ntfy_2.27.0_linux_amd64/ntfy /usr/local/bin/ntfy sudo mkdir /etc/ntfy sudo cp ntfy_2.27.0_linux_amd64/{client,server}/*.yml /etc/ntfy sudo ntfy servearmv6、armv7/armhf、arm64 架构的操作完全一致只需替换包名其中armv6/armv7/arm64 拷贝到/usr/bin/ntfyamd64 拷贝到/usr/local/bin/ntfy架构tarball 名称二进制目标路径x86_64/amd64ntfy_ver_linux_amd64.tar.gz/usr/local/bin/ntfyarmv6ntfy_ver_linux_armv6.tar.gz/usr/bin/ntfyarmv7/armhfntfy_ver_linux_armv7.tar.gz/usr/bin/ntfyarm64ntfy_ver_linux_arm64.tar.gz/usr/bin/ntfy安装为系统服务永久方案如果发行版没有提供 ntfy 软件包需要手动完成服务化安装。首先创建专用的系统用户和组useradd --system --home-dir /var/lib/ntfy --shell /bin/false --comment User for the simple HTTP-based pub-sub notification service ntfy之后根据你的 init 系统选择 systemd 或 OpenRC 路线。systemd 系统把 tarball 内自带的 service 单元文件安装到/etc/systemd/system/amd64 路径示例其他架构替换目录名sudo mv ntfy_2.27.0_linux_amd64/server/ntfy.service /etc/systemd/system/ sudo chmod 644 /etc/systemd/system/ntfy.service然后让 systemd 感知新服务并启动sudo systemctl daemon-reload sudo systemctl start ntfy仓库中的 server/ntfy.service 就是该单元文件的源码可以看到它包含大量加固与运维细节以Userntfy/Groupntfy降权运行ExecStart/usr/bin/ntfy serve --no-log-dates通过ExecReload/bin/kill --signal HUP $MAINPID支持systemctl reload ntfy热重载配置AmbientCapabilitiesCAP_NET_BIND_SERVICE允许非 root 进程绑定 80/443 等特权端口LimitNOFILE10000提高文件描述符上限并启用了PrivateDevices、ProtectKernelTunables、RestrictRealtime等 systemd 安全特性。OpenRC 系统Gentoo/Alpine 等安装 tarball 内自带的 OpenRC 服务脚本sudo mv ntfy_2.27.0_linux_amd64/server/ntfy.openrc /etc/init.d/ntfy sudo chmod 755 /etc/init.d/ntfy启动并加入默认运行级别开机自启sudo rc-service ntfy start sudo rc-update add ntfy default仓库中的 server/ntfy.openrc 展示了该脚本的实现以command_userntfy:ntfy降权运行capabilities^cap_net_bind_service绑定特权端口rc_ulimit-n 2048提高文件描述符上限start_pre()会自动检查并创建/var/log/ntfy.log、/run/ntfy/、/var/lib/ntfy/、/var/cache/ntfy/等目录并实现reload()通过 SIGHUP 信号重载配置。Debian / Ubuntu 仓库安装注意自 2025 年 9 月起官方 ntfy.sh Debian/Ubuntu 仓库已迁移至 archive.ntfy.sh旧仓库 archive.heckel.io 短期内仍可用但预计会在 2026 年初逐步下线。通过官方 APT 仓库安装仓库指纹为55BA 774A 6F5E E674 31E4 B6B7 CFDB 962D 4F1E C4AFamd64 示例如下sudo mkdir -p /etc/apt/keyrings sudo curl -L -o /etc/apt/keyrings/ntfy.gpg https://archive.ntfy.sh/apt/keyring.gpg sudo apt install apt-transport-https echo deb [archamd64 signed-by/etc/apt/keyrings/ntfy.gpg] https://archive.ntfy.sh/apt stable main \ | sudo tee /etc/apt/sources.list.d/ntfy.list sudo apt update sudo apt install ntfy sudo systemctl enable ntfy sudo systemctl start ntfyarmv7/armhf 与 arm64 用户只需把arch分别改为armhf、arm64其余命令一致。也可以直接下载.deb文件手动安装wget https://github.com/binwiederhier/ntfy/releases/download/v2.27.0/ntfy_2.27.0_linux_amd64.deb sudo dpkg -i ntfy_*.deb sudo systemctl enable ntfy sudo systemctl start ntfy软件包安装后会自动完成大量环境准备工作仓库中的 scripts/postinst.sh 会创建ntfy用户/组、对/var/cache/ntfy与/var/lib/ntfy设置正确的属主与权限、解析/etc/ntfy/server.yml中的cache-file并chown ntfy:ntfy最后重启ntfy.service与ntfy-client.service。这也是server.yml注释中反复强调Debian/RPM 包用户请使用/var/cache/ntfy/cache.db与/var/lib/ntfy/user.db以避免权限问题的原因——包安装脚本会预先创建这些目录。Fedora / RHEL / CentOSRPM直接用rpm安装对应架构的 RPM 包并启用服务sudo rpm -ivh https://github.com/binwiederhier/ntfy/releases/download/v2.27.0/ntfy_2.27.0_linux_amd64.rpm sudo systemctl enable ntfy sudo systemctl start ntfyarmv6、armv7/armhf、arm64 用户替换为对应的ntfy_ver_linux_armv6.rpm/ntfy_ver_linux_armv7.rpm/ntfy_ver_linux_arm64.rpm即可。Arch LinuxAUR社区维护ntfy 已打包为 AUR 包ntfysh-bin用 AUR 助手如paru、yay安装并保持更新paru -S ntfysh-bin或手动从 AUR 快照构建curl https://aur.archlinux.org/cgit/aur.git/snapshot/ntfysh-bin.tar.gz | tar xzv cd ntfysh-bin makepkg -siNixOS / Nix社区维护ntfy 在 nixpkgs 中打包为ntfy-sh。可以把它加入配置文件后执行nixos-rebuild也可以直接装进当前用户环境nix-env -iA ntfy-shNixOS 还支持通过services.ntfy-sh.enable选项以声明式方式配置 ntfy 服务器。FreeBSD社区维护ntfy 已移植到 FreeBSD ports 集合sysutils/go-ntfy通过pkg安装pkg install go-ntfymacOS 安装macOS 上仅支持 ntfy CLIntfy publish与ntfy subscribe服务器暂不支持如需开发用途可自行编译参见构建说明。下载 Darwin 通用 tarball 后放入PATHcurl -L https://github.com/binwiederhier/ntfy/releases/download/v2.27.0/ntfy_2.27.0_darwin_all.tar.gz ntfy_2.27.0_darwin_all.tar.gz tar zxvf ntfy_2.27.0_darwin_all.tar.gz sudo cp -a ntfy_2.27.0_darwin_all/ntfy /usr/local/bin/ntfy mkdir ~/Library/Application\ Support/ntfy cp ntfy_2.27.0_darwin_all/client/client.yml ~/Library/Application\ Support/ntfy/client.yml ntfy --helpmacOS 上的配置文件查找规则以 root 运行时读取/etc/ntfy/client.yml其他用户读取~/Library/Application Support/ntfy/client.ymltarball 内附示例文件。这一路径选择逻辑对应仓库中的 client/config_darwin.go 等平台化实现。Homebrew 安装社区维护通过 HomebrewLinux 与 macOS 均可安装 ntfy CLI仅ntfy publish/ntfy subscribebrew install ntfyWindows 安装ntfy 的服务器与 CLI 在 Windows 上完整支持既可以直接运行也可以注册为 Windows 服务。安装方式二选一下载最新 ZIP 包解压把ntfy.exe放入%Path%中的任意目录或用 Scoop 安装scoop install ntfy。安装后可执行ntfy.exe -h查看帮助。默认配置文件位置服务器为%ProgramData%\ntfy\server.yml如C:\ProgramData\ntfy\server.yml客户端为%AppData%\ntfy\client.yml——可能需要手动创建目录与配置文件。将服务器注册为 Windows 服务在管理员命令行中执行按需调整ntfy.exe路径sc create ntfy binPathC:\path\to\ntfy.exe serve startauto sc start ntfyDocker 部署ntfy 官方镜像binwiederhier/ntfy支持 amd64、armv6、armv7 与 arm64 四种架构。服务器在容器内通过80 端口提供 Web UI 与 API因此需要映射该端口若要使用持久化的消息缓存还需把卷挂载到/var/cache/ntfy要改其他配置则挂载/etc/ntfy以编辑/etc/ntfy/server.yml。注意镜像内不包含/etc/ntfy/server.yml。如需使用配置文件请在镜像外手动创建并挂载如-v /etc/ntfy:/etc/ntfy可以仓库中的 server/server.yml 为模板。这一点与 Dockerfile 的实现吻合——该镜像基于alpine仅COPY ntfy /usr/bin并设置EXPOSE 80/tcp与ENTRYPOINT [ntfy]并没有内置配置文件。基础用法无缓存、无额外配置docker run -p 80:80 -it binwiederhier/ntfy serve带持久化缓存以命令行参数配置docker run \ -v /var/cache/ntfy:/var/cache/ntfy \ -p 80:80 \ -it \ binwiederhier/ntfy \ serve \ --cache-file /var/cache/ntfy/cache.db自定义配置、时区与非 root 用户通过/etc/ntfy/server.yml配置详见配置文档docker run \ -v /etc/ntfy:/etc/ntfy \ -e TZUTC \ -p 80:80 \ -u UID:GID \ -it \ binwiederhier/ntfy \ servedocker-compose 部署非 root 用户 健康检查services: ntfy: image: binwiederhier/ntfy container_name: ntfy command: - serve environment: - TZUTC # optional: set desired timezone user: UID:GID # optional: replace with your own user/group or uid/gid volumes: - /var/cache/ntfy:/var/cache/ntfy - /etc/ntfy:/etc/ntfy ports: - 80:80 healthcheck: # optional: remember to adapt the host:port to your environment test: [CMD-SHELL, wget -q --tries1 http://localhost:80/v1/health -O - | grep -Eo \healthy\\\s*:\\s*true || exit 1] interval: 60s timeout: 10s retries: 3 start_period: 40s restart: unless-stopped init: true # needed, if healthcheck is used. Prevents zombie processes仓库根目录还提供了开箱即用的 docker-compose.yml含 TZ 环境变量、卷挂载与restart: unless-stopped可直接参考。使用非 root 用户运行容器时务必把server.yml、user.db、cache.db以及附件目录的属主chown为容器内运行的同一个 uid/gid。自定义镜像如果你希望减少运行时命令行参数、且不想单独交付配置文件可以构建一个定制镜像FROM binwiederhier/ntfy COPY server.yml /etc/ntfy/server.yml ENTRYPOINT [ntfy, serve]该镜像可推送到任意容器仓库独立分发运行时只需映射端口。Kubernetes 部署Kubernetes 下的部署与 Docker 高度相似只需一份精简的 Deployment/Pod 定义。官方文档提供了三种可组合的形态无缓存文件的 Deployment、带持久化缓存的 StatefulSet、以及独立无人值守的 Pod。Deployment ServiceapiVersion: apps/v1 kind: Deployment metadata: name: ntfy spec: selector: matchLabels: app: ntfy template: metadata: labels: app: ntfy spec: containers: - name: ntfy image: binwiederhier/ntfy args: [serve] resources: limits: memory: 128Mi cpu: 500m ports: - containerPort: 80 name: http volumeMounts: - name: config mountPath: /etc/ntfy readOnly: true volumes: - name: config configMap: name: ntfy --- # Basic service for port 80 apiVersion: v1 kind: Service metadata: name: ntfy spec: selector: app: ntfy ports: - port: 80 targetPort: 80StatefulSet持久化缓存apiVersion: apps/v1 kind: StatefulSet metadata: name: ntfy spec: selector: matchLabels: app: ntfy serviceName: ntfy template: metadata: labels: app: ntfy spec: containers: - name: ntfy image: binwiederhier/ntfy args: [serve, --cache-file, /var/cache/ntfy/cache.db] ports: - containerPort: 80 name: http volumeMounts: - name: config mountPath: /etc/ntfy readOnly: true - name: cache mountPath: /var/cache/ntfy volumes: - name: config configMap: name: ntfy volumeClaimTemplates: - metadata: name: cache spec: accessModes: [ ReadWriteOnce ] resources: requests: storage: 1Gi独立 PodapiVersion: v1 kind: Pod metadata: labels: app: ntfy spec: containers: - name: ntfy image: binwiederhier/ntfy args: [serve] resources: limits: memory: 128Mi cpu: 500m ports: - containerPort: 80 name: http volumeMounts: - name: config mountPath: /etc/ntfy readOnly: true volumes: - name: config configMap: name: ntfy配置注入配置以 ConfigMap 承载两种创建方式# resource definition apiVersion: v1 kind: ConfigMap metadata: name: ntfy data: server.yml: | base-url: https://ntfy.sh# from-file从本地 server.yml 生成 kubectl create configmap ntfy --from-fileserver.ymlKustomize 部署Kustomize 方式通过kustomization.yaml统一管理 configmap 与各类资源。整体流程新建文件夹ntfy放入以下文件kustomization.yaml管理所有 configmap 与资源、ntfy-deployment.yamlDeployment 定义、ntfy-pvc.yaml持久卷声明、ntfy-svc.yaml集群内服务暴露、ntfy-ingress.yamlIngress 对外暴露、server.yaml服务器配置把kustomization.yaml中的TESTNAMESPACE替换为目标命名空间把ntfy-ingress.yaml中的ntfy.test替换为期望的 DNS 域名应用配置到当前 context 的集群kubectl apply -k /ntfy各文件核心内容如下节选要点完整清单见官方文档对应章节。kustomization.yaml—— 使用configMapGenerator把原始server.yml解析为 configmap配合 Reloader 之类工具可实现配置热加载并指定整体命名空间apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ntfy-deployment.yaml # deployment definition - ntfy-svc.yaml # service connecting pods to cluster network - ntfy-pvc.yaml # pvc used to store cache and attachment - ntfy-ingress.yaml # ingress definition configMapGenerator: # will parse config from raw config to configmap,it allows for dynamic reload of application if additional app is deployed - name: server-config files: - server.yml namespace: TESTNAMESPACE # select namespace for whole applicationntfy-deployment.yaml—— 单副本 Deployment通过subPath挂载server.yml缓存卷挂到 PVC同时演示了用环境变量覆盖配置NTFY_DEBUG、NTFY_LOG_LEVEL、NTFY_BASE_URL等这些环境变量与 cmd/serve.go 中EnvVars: []string{NTFY_*}的定义一一对应apiVersion: apps/v1 kind: Deployment metadata: name: ntfy-deployment labels: app: ntfy-deployment spec: revisionHistoryLimit: 1 replicas: 1 selector: matchLabels: app: ntfy-pod template: metadata: labels: app: ntfy-pod spec: containers: - name: ntfy image: binwiederhier/ntfy:v1.28.0 # set deployed version args: [serve] env: #example of adjustments made in environmental variables - name: TZ # set timezone value: XXXXXXX - name: NTFY_DEBUG # enable/disable debug value: false - name: NTFY_LOG_LEVEL # adjust log level value: INFO - name: NTFY_BASE_URL # add base url value: XXXXXXXXXX ports: - containerPort: 80 name: http-ntfy resources: limits: memory: 300Mi cpu: 200m requests: cpu: 150m memory: 150Mi volumeMounts: - mountPath: /etc/ntfy/server.yml subPath: server.yml name: config-volume # generated via configMapGenerator from kustomization file - mountPath: /var/cache/ntfy name: cache-volume # cache volume mounted to persistent volume volumes: - name: config-volume configMap: # uses configmap generator to parse server.yml to configmap name: server-config - name: cache-volume persistentVolumeClaim: # stores /cache/ntfy in defined pv claimName: ntfy-pvcntfy-pvc.yaml—— 缓存持久卷apiVersion: v1 kind: PersistentVolumeClaim metadata: name: ntfy-pvc spec: accessModes: - ReadWriteOnce storageClassName: local-path # adjust storage if needed resources: requests: storage: 1Gintfy-svc.yaml—— 集群内服务apiVersion: v1 kind: Service metadata: name: ntfy-svc spec: type: ClusterIP selector: app: ntfy-pod ports: - name: http-ntfy-out protocol: TCP port: 80 targetPort: http-ntfyntfy-ingress.yaml—— 通过 Ingress 对外暴露apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ntfy-ingress spec: rules: - host: ntfy.test #select own http: paths: - path: / pathType: Prefix backend: service: name: ntfy-svc port: number: 80server.yml—— Kustomize 场景下的最小服务器配置缓存与附件落盘到 PVC 挂载的/var/cache/ntfycache-file: /var/cache/ntfy/cache.db attachment-cache-dir: /var/cache/ntfy/attachmentsHelm 部署社区维护如果偏好 Helm可以使用第三方HelmForge chart打包了官方binwiederhier/ntfy镜像提供持久化存储、Service、Ingress、可选的 Prometheus metrics 等。该 chart并非 ntfy 开发者维护且 HelmForge 项目较年轻、社区较小部署前请务必审阅 chart 内容并自行承担风险。helm repo add helmforge https://repo.helmforge.dev helm repo update helm install ntfy helmforge/ntfy也可以直接从 OCI registry 安装helm install ntfy oci://ghcr.io/helmforgedev/helm/ntfy重要限制ntfy 默认的 SQLite 存储是单写者模型因此请以单实例方式运行该 chart不要当作可水平扩展的部署可配置项的完整列表见 chart 文档。部署后的基本运维与验证无论采用哪种方式启动后的第一件事都是验证服务状态。ntfy serve命令的核心参数均可在 cmd/serve.go 中查到定义与默认值包括参数环境变量默认值说明--base-url/-BNTFY_BASE_URL无对外可见的 base URL附件下载、邮件、iOS 推送等功能的必选项--listen-http/-lNTFY_LISTEN_HTTP:80HTTP 监听地址格式[ip]:port--listen-https/-LNTFY_LISTEN_HTTPS无HTTPS 监听地址需同时配置 key/cert--cache-file/-CNTFY_CACHE_FILE无SQLite 消息缓存文件--cache-duration/-bNTFY_CACHE_DURATION12h消息缓存时长支撑since参数--behind-proxy/-PNTFY_BEHIND_PROXYfalse位于反向代理后时从转发头解析真实访客 IP--database-urlNTFY_DATABASE_URL无PostgreSQL 连接串设置后取代 SQLite 存储并隐式启用鉴权关于配置有几点值得特别留意均可在 server/server.yml 的注释与 cmd/serve.go 的启动校验逻辑中得到印证base-url一旦设置就必须是合法 URL 且不能带路径不支持子路径托管且必须与upstream-base-url不同设置database-url后cache-file、auth-file、web-push-file不能再设置启用附件attachment-cache-dir、邮件smtp-sender-addr等功能时base-url是硬性前置条件deb/rpm 包用户建议把缓存与用户库分别放在/var/cache/ntfy/cache.db与/var/lib/ntfy/user.db避免权限问题。验证服务健康可以请求GET /v1/healthDocker healthcheck 示例正是基于该端点随后即可用curl向ntfy.sh或自建服务器发布消息、用ntfy subscribe订阅主题。至此从单机二进制到容器集群ntfy 的完整部署路径你已经全部掌握。【免费下载链接】ntfySend push notifications to your phone or desktop using PUT/POST项目地址: https://gitcode.com/GitHub_Trending/nt/ntfy创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考