Docker 搭建自用网站数据统计工具Umami

前言

搭建网站的朋友都需要用到数据统计,如果对数据统计没什么太大的要求,只想知道当天有多少访问量就可以使用这个Umami。

界面截图

图片[1]-Docker 搭建自用网站数据统计工具Umami-新锐博客

教程

本次教程分为两个部分,一个是一键部署,一个是通过Docker-Compose。

1.一键部署

1.使用宝塔面板的朋友可以将宝塔面板升级到最新版本,自带的Docker应用商店搜索Umami就行了。

图片[2]-Docker 搭建自用网站数据统计工具Umami-新锐博客

2.安装成功后在页面中选择管理

图片[3]-Docker 搭建自用网站数据统计工具Umami-新锐博客

这里我已经安装了,所以显示是重建应用,一般是安装应用。

3.从访问信息中获取到应用的URL地址,一般为ip+端口3000。

4.宝塔面板新建网站php版本选择纯静态,设置中找到反向代理,填写名称和ip+端口3000即可。

2.Docker-Compose

1.配置化数据库语句

mkdir -p /home/docker/mysql/init && 
vim /home/docker/mysql/init/umami.sql

将下面的 sql 语句复制进去。

CREATE DATABASE `umami` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';
USE umami;
-- CreateTable
CREATE TABLE `account` (
    `user_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(255) NOT NULL,
    `password` VARCHAR(60) NOT NULL,
    `is_admin` BOOLEAN NOT NULL DEFAULT false,
    `created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
    `updated_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
    `account_uuid` VARCHAR(36) NOT NULL,
 
    UNIQUE INDEX `account_username_key`(`username`),
    UNIQUE INDEX `account_account_uuid_key`(`account_uuid`),
    INDEX `account_account_uuid_idx`(`account_uuid`),
    PRIMARY KEY (`user_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
-- CreateTable
CREATE TABLE `event` (
    `event_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `website_id` INTEGER UNSIGNED NOT NULL,
    `session_id` INTEGER UNSIGNED NOT NULL,
    `created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
    `url` VARCHAR(500) NOT NULL,
    `event_name` VARCHAR(50) NOT NULL,
    `event_uuid` VARCHAR(36) NOT NULL,
 
    UNIQUE INDEX `event_event_uuid_key`(`event_uuid`),
    INDEX `event_created_at_idx`(`created_at`),
    INDEX `event_session_id_idx`(`session_id`),
    INDEX `event_website_id_idx`(`website_id`),
    INDEX `event_event_uuid_idx`(`event_uuid`),
    PRIMARY KEY (`event_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
-- CreateTable
CREATE TABLE `event_data` (
    `event_data_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `event_id` INTEGER UNSIGNED NOT NULL,
    `event_data` JSON NOT NULL,
 
    UNIQUE INDEX `event_data_event_id_key`(`event_id`),
    PRIMARY KEY (`event_data_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
-- CreateTable
CREATE TABLE `pageview` (
    `view_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `website_id` INTEGER UNSIGNED NOT NULL,
    `session_id` INTEGER UNSIGNED NOT NULL,
    `created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
    `url` VARCHAR(500) NOT NULL,
    `referrer` VARCHAR(500) NULL,
 
    INDEX `pageview_created_at_idx`(`created_at`),
    INDEX `pageview_session_id_idx`(`session_id`),
    INDEX `pageview_website_id_created_at_idx`(`website_id`, `created_at`),
    INDEX `pageview_website_id_idx`(`website_id`),
    INDEX `pageview_website_id_session_id_created_at_idx`(`website_id`, `session_id`, `created_at`),
    PRIMARY KEY (`view_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
-- CreateTable
CREATE TABLE `session` (
    `session_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `session_uuid` VARCHAR(36) NOT NULL,
    `website_id` INTEGER UNSIGNED NOT NULL,
    `created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
    `hostname` VARCHAR(100) NULL,
    `browser` VARCHAR(20) NULL,
    `os` VARCHAR(20) NULL,
    `device` VARCHAR(20) NULL,
    `screen` VARCHAR(11) NULL,
    `language` VARCHAR(35) NULL,
    `country` CHAR(2) NULL,
 
    UNIQUE INDEX `session_session_uuid_key`(`session_uuid`),
    INDEX `session_created_at_idx`(`created_at`),
    INDEX `session_website_id_idx`(`website_id`),
    INDEX `session_session_uuid_idx`(`session_uuid`),
    PRIMARY KEY (`session_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
-- CreateTable
CREATE TABLE `website` (
    `website_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `website_uuid` VARCHAR(36) NOT NULL,
    `user_id` INTEGER UNSIGNED NOT NULL,
    `name` VARCHAR(100) NOT NULL,
    `domain` VARCHAR(500) NULL,
    `share_id` VARCHAR(64) NULL,
    `created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
 
    UNIQUE INDEX `website_website_uuid_key`(`website_uuid`),
    UNIQUE INDEX `website_share_id_key`(`share_id`),
    INDEX `website_user_id_idx`(`user_id`),
    INDEX `website_website_uuid_idx`(`website_uuid`),
    PRIMARY KEY (`website_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
-- CreateAdminUser
INSERT INTO account (username, password, is_admin, account_uuid) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true, uuid());

3.新建docker-compose.yaml,并将如下代码加进去

mkdir umami && cd umami && 
touch docker-compose.yaml && 
cat > docker-compose.yaml <<EOF
version: '3.1'
services:
  umami:
    image: hausen1012/umami:mysql-latest
    container_name: umami
    restart: always
    ports:
      - 3000:3000
    environment:
      DATABASE_URL: mysql://root:123456@mysql:3306/umami
      DATABASE_TYPE: mysql
      HASH_SALT: replace-me-with-a-random-string
    depends_on:
      - mysql
  mysql:
    image: mysql:8.0.26
    container_name: mysql
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: 123456
    volumes:
      - /home/docker/mysql/data:/var/lib/mysql
      - /home/docker/mysql/init:/docker-entrypoint-initdb.d
EOF

4.启动docker-compose

docker-compose up -d

访问网站

默认账号密码:admin/umami

设置

先别添加网站,右上角地球标志设置语言为中文,再去后台把账号密码重新设置一下,然后再添加网站,并且获取到跟踪代码以及分享代码。

 

 

THE END
喜欢就支持一下吧
抢沙发
头像
提交
头像

昵称

取消
昵称

    请登录后查看评论内容