From f1fb823ca39b9daea6b90d76440e88743507df8f Mon Sep 17 00:00:00 2001 From: "Kaz Saita(raspi4)" Date: Sun, 24 Mar 2024 12:00:23 +0900 Subject: [PATCH] sync notes(auto) --- content/20240324102024 Umamiのインストール.md | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 content/20240324102024 Umamiのインストール.md diff --git a/content/20240324102024 Umamiのインストール.md b/content/20240324102024 Umamiのインストール.md new file mode 100644 index 0000000..bd2f06c --- /dev/null +++ b/content/20240324102024 Umamiのインストール.md @@ -0,0 +1,163 @@ +# 20240324102024 Umamiのインストール +#server #umami #raspi + +[Umami](https://umami.is/) はアクセス解析。cookieとかを使わない。 + +ここに書いてある通りにやる: [Docs: Installation – Umami](https://umami.is/docs/install) + +データベースは 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) +``` + +``` +$ sudo npm install -g yarn +$ git clone https://github.com/umami-software/umami.git +``` + +umamiのディレクトリ内で.envファイルを作成。 umami_dbは↑で作成した名前 +``` +DATABASE_URL=mysql://[username]:****@localhost:3306/umami_db +``` + +``` +$ yarn build +``` + +port :3000は[[20240312115855 Raspi4 GiteaからForgejoに変更してみる|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: +:13:29: ERROR: Expected ";" but found ":" + :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に下記追加で動かしている。 +``` + +``` + +## Refs. +- [Docs: Installation – Umami](https://umami.is/docs/install) \ No newline at end of file