6.5 KiB
20240324102024 Umamiのインストール
#server #umami #raspi
Umami はアクセス解析。cookieとかを使わない。
ここに書いてある通りにやる: Docs: Installation – Umami が、gitではなくリリース版を使う。
データベースは MariaDBを入れた: 20240324102510 MySQL MariaDBのインストール
Umami用DBを作る(ユーザーがrootでいいのだろうか)
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.11.6-MariaDB-0+deb12u1 Debian 12
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE umami_db;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> Ctrl-C -- exit!
Aborted
$ sudo npm install -g yarn
$ wget https://github.com/umami-software/umami/archive/refs/tags/v2.11.0.tar.gz
$ cd umami
$ npm i
20240407 最新だと npm i
で下記エラーになる
$ npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: umami@2.11.0
npm ERR! Found: @prisma/client@5.11.0
npm ERR! node_modules/@prisma/client
npm ERR! @prisma/client@"5.11.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @prisma/client@"^4.8.0" from @umami/prisma-client@0.14.0
npm ERR! node_modules/@umami/prisma-client
npm ERR! @umami/prisma-client@"^0.14.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! /home/kazbo/.npm/_logs/2024-04-07T07_05_54_650Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in: /home/kazbo/.npm/_logs/2024-04-07T07_05_54_650Z-debug-0.log
$ npm i --force --ignore-scripts
で最後までいけた。
umamiのディレクトリ内で.envファイルを作成。 umami_dbは↑で作成した名前
DATABASE_URL=mysql://[username]:[password]@localhost:3306/umami_db
$ yarn build
port :3000は20240312115855 Raspi4 GiteaからForgejoに変更してみるが使っていたので、ポートを変更して起動。
$ yarn start -p 3100
ここまでやってローカル :3100にブラウザでアクセス、表示されればOK。
以下はトンネルの構成とかnginxでどうやってアクセスしたいか?によってケースバイケースの内容なので普遍性は無い。
umami.kinoshita-lab.org
でアクセスしたい場合。
Cloudflare経由のトンネル
20240211202623 Raspi4 Cloudflare tunnel経由でhttpsサーバーを公開する あたりを参照、 .cloudflared/config.yaml のingressに下記を追加
- hostname: umami.kinoshita-lab.org
service: http://localhost
で再起動。
nginxの設定
あまりよくわかっていないのでforgejoの設定とほぼ同じ
# umami
server {
listen 80;
listen [::]:80;
server_name umami.kinoshita-lab.org;
location / {
# make wnginx use unescaped URI, keep "%2F" as is
proxy_pass http://127.0.0.1:3100;
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
nginxを再起動。 umami.kinoshita-lab.org
経由でumamiにアクセスできることを確認。
systemctlに追加
こんなのを /etc/systemd/systemに追加して
[Unit]
Description = umami
[Service]
WorkingDirectory=/home/kazbo/umami
ExecStart = yarn start -p 3100
Restart = always
Type = simple
User = kazbo
[Install]
WantedBy = multi-user.target
起動、こんな感じで動いていればOK(多分)
$ sudo systemctl daemon-reload
$ sudo systemctl start umami
$ sudo systemctl status umami
● umami.service - umami
Loaded: loaded (/etc/systemd/system/umami.service; disabled; preset: enabled)
Active: active (running) since Sun 2024-03-24 11:27:18 JST; 4s ago
Main PID: 99500 (node)
Tasks: 23 (limit: 3916)
CPU: 1.979s
CGroup: /system.slice/umami.service
├─99500 node /usr/local/bin/yarn start -p 3100
├─99511 /bin/sh -c "next start -p 3100"
└─99512 next-server
Mar 24 11:27:18 saipi4 systemd[1]: Started umami.service - umami.
Mar 24 11:27:18 saipi4 yarn[99500]: yarn run v1.22.22
Mar 24 11:27:18 saipi4 yarn[99500]: warning ../package.json: No license field
Mar 24 11:27:18 saipi4 yarn[99500]: $ next start -p 3100
Mar 24 11:27:19 saipi4 yarn[99512]: ▲ Next.js 14.1.0
Mar 24 11:27:19 saipi4 yarn[99512]: - Local: http://localhost:3100
Mar 24 11:27:19 saipi4 yarn[99512]: ⚠ "next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.
Mar 24 11:27:19 saipi4 yarn[99512]: ✓ Ready in 1089ms
umamiの設定
- umamiにログイン、とりあえず日本語化
-
- Webサイトの追加 名前とドメインを入力
quartzの設定
quartz.configのそれっぽい所に下記を追加・・・すればうまくいくはずだが、
analytics: {
provider: "umami",
websiteId: "**",
host: "https://umami.kinoshita-lab.org/script.js"
}
hostのところを入力すると、下記エラーになる。
⠋ Emitting output files
ERROR
Failed to emit from plugin `ComponentResources`: Transform failed with 1 error:
<stdin>:13:29: ERROR: Expected ";" but found ":"
<stdin>:13:29: ERROR: Expected ";" but found ":"
at Socket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Socket.Readable.push (node:internal/streams/readable:390:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
しかたがないのでHead.tsxに下記追加で動かしている。
<script defer src="https://umami.kinoshita-lab.org/script.js" data-website-id="****"></script>