Umami是什么?
Umami是一个开源项目,简单、快速、专注用户隐私的网站统计项目。
下面来介绍如何本地安装部署Umami项目,进行你的网站统计接入。特别对于首次使用docker的萌新有非常好的指导、参考和帮助作用。
Umami的github和docker镜像地址
github:
https://github.com/umami-software/umami
docker,使用MySQL版,
docker pull docker.umami.is/umami-software/umami:mysql-latest
准备Linux服务器
如果需要安装在自己的Linux服务器,由于需要运行Docker、MySQL8、Nodejs等,这里的服务器配置是:2核CPU 4G内存。
准备工作:国内docker镜像源
为避免拉取超时,先准备国内镜像源。修改/etc/docker/daemon.json配置文件,然后重启docker服务。
# vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.ccs.tencentyun.com",
"https://docker.nju.edu.cn",
"https://docker.m.daocloud.io"
]
}
sudo systemctl daemon-reload # 重启daemon进程
sudo systemctl restart docker # 重启docker服务
准备工作:docker网络,用于umami连接mysql8
docker network create my_mysql_network
准备工作:先安装mysql8 docker和初始化
虽然Umami支持PostgreSQL或MySQL,但这里使用的是MySQL版本,所以需要先安装mysql8。
# docker pull mysql:8.0
8.0: Pulling from library/mysql
2c0a233485c3: Pull complete
fb027c65a85c: Pull complete
d87e05573c29: Pull complete
7d202bd608a9: Pull complete
930324cdd290: Pull complete
441e29354b23: Pull complete
4f0710d03b24: Pull complete
ead7d3dd9cc0: Pull complete
55d2712d2c86: Pull complete
4aaa23a8b413: Pull complete
84ba6b75f842: Pull complete
Digest: sha256:4f33388ab0a152ca309eeb70cd2e4a9a8989d5006ec2a4890d883afbffd6be4a
Status: Downloaded newer image for mysql:8.0
docker.io/library/mysql:8.0
查看镜像,
[root@iz8vbetvcrpn38l0x1kd06z docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 8.0 04faa32c7d29 33 hours ago 764MB
新建一个目录,用于准备数据库数据存放目录,
mkdir -p /home/apps/docker/mysql_8.0_data
启动数据库,
docker run -d \
--name mysql8 \
--network my_mysql_network \
-p 3306:3306 \
-v /home/apps/docker/mysql_8.0_data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=xxxxxx_password \
mysql:8.0
> mysql:8.0
a5641d144dc9ce2b896654bd972b57f8b86b9ea62522b898fde0cc80a0752b5c
查看启动情况,
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5641d144dc9 mysql:8.0 "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql8
进入数据库mysql8,
# docker exec -it mysql8 mysql -uroot -pxxxxxx_password
新建数据库,
mysql> CREATE DATABASE dogstar_umami_db;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| dogstar_umami_db |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
查看数据库地址和端口,
mysql> SHOW VARIABLES LIKE 'hostname';
+---------------+--------------+
| Variable_name | Value |
+---------------+--------------+
| hostname | a5641d144dc9 |
+---------------+--------------+
1 row in set (0.01 sec)
mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
docker镜像拉取umami
docker pull docker.umami.is/umami-software/umami:mysql-latest
启动umami,指定网络,指定数据库连接,指定端口等。
docker run -d \
--name umami \
--network my_mysql_network \
-e DATABASE_URL=mysql://root:xxxxxx_password@a5641d144dc9:3306/dogstar_umami_db \
-e HASH_SALT=dogstarxxxx \
-p 3000:3000 \
docker.umami.is/umami-software/umami:mysql-latest
查看,是否启动成功。
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
344a33733053 docker.umami.is/umami-software/umami:mysql-latest "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 0.0.0.0:3000->3000/tcp umami
a5641d144dc9 mysql:8.0 "docker-entrypoint.s…" 29 minutes ago Up 29 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql8
查看日记,没有报错。
# docker logs -f umami
yarn run v1.22.22
$ 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.
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "dogstar_umami_db" at "a5641d144dc9:3306"
7 migrations found in prisma/migrations
No pending migrations to apply.
✓ Database is up to date.
$ node scripts/update-tracker.js
$ node server.js
▲ Next.js 15.0.4
- Local: http://localhost:3000
- Network: http://0.0.0.0:3000
✓ Starting...
✓ Ready in 143ms
查看数据库表
mysql> use dogstar_umami_db;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> show tables;
+----------------------------+
| Tables_in_dogstar_umami_db |
+----------------------------+
| _prisma_migrations |
| event_data |
| report |
| session |
| session_data |
| team |
| team_user |
| user |
| website |
| website_event |
+----------------------------+
10 rows in set (0.00 sec)
本地测试访问
# curl http://127.0.0.1:3000
正常,
配置nginx和对外域名
# vim /etc/nginx/conf.d/umami.yesapi.cn.conf
server {
listen 80;
server_name umami.yesapi.cn;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
访问网站,http://umami.yesapi.cn
初始账号密码:admin / xxxxxx
创建新网站,
获得追踪代码,
<script defer src="http://umami.yesapi.cn/script.js" data-website-id="194ab56b-0d02-4a34-9aa7-e64f4cd32de6"></script>
接入统计,
查看统计,
至此,部署、安装和网站统计接入,成功完成!