From b7d655ec5a133c78037a728781bb8875174a87a7 Mon Sep 17 00:00:00 2001 From: Dejavu Moe Date: Wed, 10 May 2023 18:31:23 +0800 Subject: add plausible --- plausible/GeoIP/geoip.conf | 2 + plausible/GeoIP/geonames.csv | 0 plausible/clickhouse/clickhouse-config.xml | 16 ++++++++ plausible/clickhouse/clickhouse-user-config.xml | 8 ++++ plausible/clickhouse/data/.gitkeep | 0 plausible/db-data/.gitkeep | 0 plausible/docker-compose.yml | 53 +++++++++++++++++++++++++ plausible/plausible-conf.env | 15 +++++++ plausible/plausible-deploy.sh | 35 ++++++++++++++++ plausible/plausible.nginx | 36 +++++++++++++++++ 10 files changed, 165 insertions(+) create mode 100644 plausible/GeoIP/geoip.conf create mode 100644 plausible/GeoIP/geonames.csv create mode 100644 plausible/clickhouse/clickhouse-config.xml create mode 100644 plausible/clickhouse/clickhouse-user-config.xml create mode 100644 plausible/clickhouse/data/.gitkeep create mode 100644 plausible/db-data/.gitkeep create mode 100644 plausible/docker-compose.yml create mode 100644 plausible/plausible-conf.env create mode 100644 plausible/plausible-deploy.sh create mode 100644 plausible/plausible.nginx diff --git a/plausible/GeoIP/geoip.conf b/plausible/GeoIP/geoip.conf new file mode 100644 index 0000000..a6eeb5b --- /dev/null +++ b/plausible/GeoIP/geoip.conf @@ -0,0 +1,2 @@ +GEOIPUPDATE_ACCOUNT_ID=123456 +GEOIPUPDATE_LICENSE_KEY=abcd12345 \ No newline at end of file diff --git a/plausible/GeoIP/geonames.csv b/plausible/GeoIP/geonames.csv new file mode 100644 index 0000000..e69de29 diff --git a/plausible/clickhouse/clickhouse-config.xml b/plausible/clickhouse/clickhouse-config.xml new file mode 100644 index 0000000..c9ad646 --- /dev/null +++ b/plausible/clickhouse/clickhouse-config.xml @@ -0,0 +1,16 @@ + + + warning + true + + + + + + + + + + + + diff --git a/plausible/clickhouse/clickhouse-user-config.xml b/plausible/clickhouse/clickhouse-user-config.xml new file mode 100644 index 0000000..56cf1cd --- /dev/null +++ b/plausible/clickhouse/clickhouse-user-config.xml @@ -0,0 +1,8 @@ + + + + 0 + 0 + + + diff --git a/plausible/clickhouse/data/.gitkeep b/plausible/clickhouse/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plausible/db-data/.gitkeep b/plausible/db-data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plausible/docker-compose.yml b/plausible/docker-compose.yml new file mode 100644 index 0000000..3f2a414 --- /dev/null +++ b/plausible/docker-compose.yml @@ -0,0 +1,53 @@ +version: "3.3" +services: + + geoip: + image: maxmindinc/geoipupdate + restart: always + environment: + - 'GEOIPUPDATE_EDITION_IDS=GeoLite2-City GeoLite2-Country' + - 'GEOIPUPDATE_FREQUENCY=72' + env_file: + - ./GeoIP/geoip.conf + volumes: + - ./GeoIP:/usr/share/GeoIP + + plausible_db: + image: postgres:14-alpine + restart: always + volumes: + - ./db-data:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=postgres + + plausible_events_db: + image: clickhouse/clickhouse-server:22.6-alpine + restart: always + volumes: + - ./clickhouse/data:/var/lib/clickhouse + - ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro + - ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro + ulimits: + nofile: + soft: 262144 + hard: 262144 + + plausible: + image: plausible/analytics:latest + restart: always + command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run" + depends_on: + - plausible_db + - plausible_events_db + - geoip + ports: + - "127.0.0.1:8000:8000" + env_file: + - ./plausible-conf.env + environment: + - TZ=Asia/Shanghai + volumes: + - ./GeoIP:/geoip:ro + - ./GeoIP/geonames.csv:/etc/app/geonames.csv:ro + - ./GeoIP/GeoLite2-City.mmdb:/etc/app/GeoLite2-City.mmdb:ro + - ./GeoIP/GeoLite2-Country.mmdb:/etc/app/GeoLite2-Country.mmdb:ro diff --git a/plausible/plausible-conf.env b/plausible/plausible-conf.env new file mode 100644 index 0000000..93af21e --- /dev/null +++ b/plausible/plausible-conf.env @@ -0,0 +1,15 @@ +DISABLE_REGISTRATION=true +BASE_URL=https://plausible.yourdomain.com +GOOGLE_CLIENT_ID= +GOOGLE_CLIENT_SECRET= +MAILER_EMAIL=plausible@xxx.com +SMTP_HOST_ADDR=smtp.xxx.com +SMTP_HOST_PORT=465 +SMTP_USER_NAME=plausible@xxx.com +SMTP_USER_PWD= +SMTP_HOST_SSL_ENABLED=true +SMTP_RETRIES=2 +SECRET_KEY_BASE= +GEOLITE2_COUNTRY_DB=/etc/app/GeoLite2-Country.mmdb +IP_GEOLOCATION_DB=/etc/app/GeoLite2-City.mmdb +GEONAMES_SOURCE_FILE=/etc/app/geonames.csv diff --git a/plausible/plausible-deploy.sh b/plausible/plausible-deploy.sh new file mode 100644 index 0000000..c33d22d --- /dev/null +++ b/plausible/plausible-deploy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +echo -e "本脚本将帮助您使用 Docker Compose 快速部署 Plausible\nAuthor: Dejavu Moe\nPost:https://dejavu.moe/posts/plausible-selfhosted-with-docker-complete-guide/" +read -p "请按 Enter 键继续..." enter + +if [[ "$(command -v docker)" == "" && "$(command -v docker compose)" == "" ]]; then + echo "您的机器上尚未安装最新版的 Docker 和 Docker Compose 插件,执行中止" + exit 1 +else + echo "开始执行脚本" +fi + +echo "Plausible 相关的持久化数据将会被保存在 $(pwd)/container/plausible/" + +if [ -d container ]; then + echo "当前目录下已经存在 container 文件夹,跳过目录创建" +else + mkdir container + echo "已创建 container 文件夹" +fi + +cd container +git init +git remote add origin https://github.com/DejavuMoe/self-hosted.git +git config --local core.sparsecheckout true +echo "plausible" >> .git/info/sparse-checkout +git pull --depth=1 origin master +cd plausible +echo "正在下载 geonames.csv.数据库..." +wget https://s3.eu-central-1.wasabisys.com/plausible-application/geonames.csv -P GeoIP/ +echo -e "Plausible 所需的环境已经初始化完成\n请完成环境变量的填写\n之后在当前目录使用下面命令完成部署\nsudo docker compose up -d\n按任意键退出..." +read -n 1 -s -r -p "" +exit 0 \ No newline at end of file diff --git a/plausible/plausible.nginx b/plausible/plausible.nginx new file mode 100644 index 0000000..96baede --- /dev/null +++ b/plausible/plausible.nginx @@ -0,0 +1,36 @@ +server { + listen 80; + listen [::]:80; + server_name plausible.yourdomain.com; + + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name plausible.yourdomain.com; + + access_log /var/log/nginx/plausible.access.log; + error_log /var/log/nginx/plausible.error.log; + + ssl_certificate /etc/nginx/cert/plausible.yourdomain.com.pem; + ssl_certificate_key /etc/nginx/cert/plausible.yourdomain.com.key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 5m; + ssl_ciphers 'TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+AESGCM:EDH+AESGCM:EECDH+CHACHA20:EDH+CHACHA20:EECDH+AES128:EDH+AES128:EECDH+AES256:EDH+AES256:EECDH+3DES:EDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS'; + + location / { + proxy_pass http://localhost:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_redirect off; + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf