Metabase on Raspberry Pi OS

# Metabase とは
> Metabase is a simple and powerful analytics tool which lets anyone learn and make decisions from their company’s data. No technical knowledge required! We hope you love it.
> [© Metabase 2020](https://www.metabase.com/docs/latest/getting-started.html)

# Install Java
Metabase は Java で動作します。

```
pi@raspberrypi:~ $ sudo apt -y install openjdk-8-jdk openjdk-8-jre
pi@raspberrypi:~ $ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1+rpi1-b01)
OpenJDK Client VM (build 25.212-b01, mixed mode)
pi@raspberrypi:~ $ javac -version
javac 1.8.0_212
```

# Download & Install Metabase

Metabase 配布場所
https://www.metabase.com/docs/latest/operations-guide/running-the-metabase-jar-file.html

今回は wget で取得。

```bash
pi@raspberrypi:~ $ sudo mkdir /apps
pi@raspberrypi:~ $ cd /apps/
pi@raspberrypi:/apps $ sudo wget https://downloads.metabase.com/v0.36.6/metabase.jar
--2020-09-25 04:58:30--  https://downloads.metabase.com/v0.36.6/metabase.jar
Resolving downloads.metabase.com (downloads.metabase.com)... 13.35.70.29, 13.35.70.81, 13.35.70.115, ...
Connecting to downloads.metabase.com (downloads.metabase.com)|13.35.70.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 200535561 (191M) [application/java-archive]
Saving to: 'metabase.jar'

metabase.jar      100%[=============>] 191.25M  8.09MB/s    in 21s

2020-09-25 04:58:52 (8.92 MB/s) - 'metabase.jar' saved [200535561/200535561]
pi@raspberrypi:/apps $ ls -la
total 195844
drwxr-xr-x  2 root root      4096 Sep 25 04:58 .
drwxr-xr-x 22 root root      4096 Sep 25 04:57 ..
-rw-r--r--  1 root root 200535561 Sep 15 23:56 metabase.jar
pi@raspberrypi:/apps $ java -jar ./metabase.jar
```

# Metabase 用ユーザ作成と設定
```bash
pi@raspberrypi:~ $ sudo groupadd -r metabase
pi@raspberrypi:~ $ sudo useradd -r -s /bin/false -g metabase metabase
pi@raspberrypi:~ $ sudo chown -R metabase:metabase /apps
pi@raspberrypi:~ $ sudo touch /var/log/metabase.log
pi@raspberrypi:~ $ sudo chown metabase:metabase /var/log/metabase.log
pi@raspberrypi:~ $ sudo touch /etc/default/metabase
pi@raspberrypi:~ $ sudo chmod 640 /etc/default/metabase
```

# Metabase のサービス化

```bash
pi@raspberrypi:~ $ sudo touch /etc/systemd/system/metabase.service
pi@raspberrypi:~ $ sudo vi /etc/systemd/system/metabase.service
```

```vim:metabase.service

[Unit]
Description=Metabase server
After=syslog.target
After=network.target

[Service]
WorkingDirectory=/apps
ExecStart=/usr/bin/java -jar /apps/metabase.jar
EnvironmentFile=/etc/default/metabase
User=metabase
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=metabase
SuccessExitStatus=143
TimeoutStopSec=120
Restart=always

[Install]
WantedBy=multi-user.target
```

# syslog 設定
```bash
pi@raspberrypi:/apps $ sudo touch /etc/rsyslog.d/metabase.conf
pi@raspberrypi:/apps $ sudo vi /etc/rsyslog.d/metabase.conf
```

```vim:metabase.conf
if $programname == 'metabase' then /var/log/metabase.log
&amp; stop
```

```bash
pi@raspberrypi:/apps $ sudo systemctl restart rsyslog.service
```

# Metabase のサービス登録
```bash
pi@raspberrypi:~ $ sudo systemctl daemon-reload
pi@raspberrypi:~ $ sudo systemctl start metabase.service
pi@raspberrypi:~ $ sudo systemctl enable metabase.service
Created symlink /etc/systemd/system/multi-user.target.wants/metabase.service → /etc/systemd/system/metabase.service.
```

# Metabase へのアクセス

http://\<IP-Address\>:3000

![Screen Shot 2020-09-25 at 13.15.40.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/82774/d1ef9bf8-6d8e-03aa-2573-97668c7668e7.png)