Umami是干什么的
Umami 是一个开源免费,可自托管,用途类似 Google Analytics。网站数据收集访问量(PV、UV)、流量来源等基本信息,试用了一段时间,觉得确实简单易用,值得关注。
安装使用
推荐docker或Railway部署
docker版本
这里以mysql为例:
#1. 拉取镜像
docker pull docker.umami.dev/umami-software/umami:mysql-latest
#2. 运行容器,先确保存在umami
docker run -d \
--name umami \
-p 3000:3000 \
-e DATABASE_URL=mysql://<username>:<password>@<host>:3306/umami \
-e DATABASE_TYPE=mysql \
-e HASH_SALT=Umami-yunong \
--restart always \
docker.umami.dev/umami-software/umami:mysql-latest
容器启动后在浏览器访问:http://ip:3000
a. 登录
b. 添加站点
c. 编辑->跟踪代码
将这段粘贴到网站的头部信息中,就可以实现跟踪效果
d. 效果
Railway 部署(推荐)
umami 官方文档中介绍了多种部署方法,包括部署到 Vercel、Railway 等方法。我一开始是使用 docker 部署在自己的服务器上,但后来发现使用 Railway 托管似乎更简单,且它每个月有5美元免费额度应该足够支持我的用量了,于是便又迁移到了 Railway。具体参考官网在Railway部署的文档
部署完成后,效果跟docker版本一样,参考上图
踩坑指南
**切记不能自己执行sql语句**
,无论docker版还是Railway中,都报错,显示数据库能正常连接,却无法启动,最终的原因是:因为在我创建好数据库后,又在官网github源码中找了sql先自行初始化,导致启动报错。
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.22.19
$ npm-run-all check-db update-tracker start-server
$ node scripts/check-db.js
✓ DATABASE_URL is defined.
✓ Database connection successful.
✓ Database version check successful.
Error: P3005
The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline
✗ Command failed: prisma migrate deploy
Error: P3005
The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
ERROR: "check-db" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.