## 痛点
服务器备份完成了、网站被攻击了、Docker 容器挂了——这些消息你希望第一时间知道。微信通知需要企业微信或公众号,钉钉需要建机器人,邮件通知不够即时。
Gotify 是一个极简的自建推送服务,服务端 + 手机 App,不需要任何第三方平台。
## 部署
```yaml
services:
gotify:
image: gotify/server:latest
container_name: gotify
restart: unless-stopped
ports:
- "8088:80"
volumes:
- ./data:/app/data
environment:
- GOTIFY_DEFAULTUSER_PASS=your_admin_password
- TZ=Asia/Shanghai
```
启动后访问 `http://IP:8088`,默认用户名 `admin`,密码为上面设置的值。
## 手机端
在 App Store 或 Google Play 搜索 "Gotify" 安装。打开后填入服务器地址和管理员账号密码即可连接。
## 创建应用和 Token
在 Web 界面创建应用(比如叫 "Server Monitor"),会生成一个 Token。推送消息只需要这个 Token:
```bash
# 发送一条测试消息
curl "https://push.yourdomain.com/message?token=YOUR_TOKEN" \
-F "title=测试通知" \
-F "message=Gotify 配置成功!" \
-F "priority=5"
```
priority 范围 0-10,数字越大通知越醒目。
## 实战场景
**1. 监控备份结果**
```bash
#!/bin/bash
# backup.sh
if rsync -av /data /backup/; then
curl "https://push.domain.com/message?token=xxx" \
-F "title=备份成功" -F "message=数据已备份到远程" -F "priority=5"
else
curl "https://push.domain.com/message?token=xxx" \
-F "title=⚠️ 备份失败" -F "message=请检查磁盘空间" -F "priority=10"
fi
```
**2. 监控 Docker 容器状态**
```bash
#!/bin/bash
# check_container.sh
if ! docker inspect -f '{{.State.Running}}' nginx | grep -q true; then
curl "https://push.domain.com/message?token=xxx" \
-F "title=⚠️ Nginx 挂了" \
-F "message=容器已停止,请检查" \
-F "priority=10"
fi
```
**3. 配合 Uptime Kuma**
Uptime Kuma 原生支持 Gotify 通知。在"通知方式"中选择 Gotify,填入服务器地址和 Token 即可。
## 进阶:使用优先级
- priority < 3:信息类通知,不打扰
- priority 3-6:一般提醒
- priority 7-9:重要告警,手机会响铃
- priority 10:紧急,即使勿扰模式也会通知
Gotify 是我使用频率最高的自建服务之一,服务器有任何风吹草动,手机第一时间知道。