# 使用 docker 部署 uptime-kuma 服务
# uptime-kuma 介绍
uptime-kuma (opens new window) 是一款轻量级的服务可用性的监测软件;
通过设置监测的目标和监测的频率,统计服务的可用情况;
可选多种探测模式,支持发送通知;
试用地址:Uptime Kuma (opens new window)
# 使用 docker-compose 部署
uptime-kuma 的版本可以在 uptime-kuma on dockerhub (opens new window) 查看;
新建 docker-compose.yml 文件;
输入以下内容:
version: "3.6"
services:
uptime-kuma:
image: louislam/uptime-kuma:1.21.2-alpine # 指定版本
container_name: uptime-kuma # container 名称
volumes:
- /home/ubuntu/uptime-kuma/:/app/data # 挂载目录,避免 container 重启后数据丢失
ports:
- 33001:3001 # 开放端口
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 设置 nginx 反向代理
server {
listen 443 ssl http2; # 开启 http2
server_name uptime-kuma.ryantech.ltd; # 配置为您需要的域名
ssl_certificate cert/uptime-kuma.ryantech.ltd.pem;
ssl_certificate_key cert/uptime-kuma.ryantech.ltd.key;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_stapling on; # 开启 ssl stapling
ssl_stapling_verify on;
ssl_trusted_certificate cert/uptime-kuma.ryantech.ltd.pem; # 和 ssl_certificate 保持一致
add_header Strict-Transport-Security "max-age=31536000"; # HSTS 设置
# 开启 gzip 压缩,降低对带宽的占用
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# 配置反向代理
location / {
proxy_redirect off;
proxy_pass http://127.0.0.1:33001; # 端口设置为 uptime-kuma container 对外开放的端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 配置 https 跳转
server {
listen 80;
server_name uptime-kuma.ryantech.ltd;
rewrite ^(.*)$ https://$host$1; # 将所有 HTTP 请求通过 rewrite 指令重定向到 HTTPS
}
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 备份和恢复
备份的方法有 2 种:
- 使用 uptime-kuma 提供的备份功能进行配置
- 备份前面挂载的宿主机的文件目录即可
第一种方法被官方列为不推荐使用……
使用第二种方法,以前面的 docker-compose.yml 为例,只需要压缩 /home/ubuntu/uptime-kuma/ 这个文件夹即可;
恢复的方法,即传输备份的文件夹到新主机上,再让 docker-compose.yml 中的文件映射到新的文件夹下,启动新的 container 即完成恢复;