Metabase is an open-source business intelligence tool. Metabase lets you ask questions about your data, and displays answers in formats that make sense, whether that’s a bar chart or a detailed table. You can save your questions, and group questions into handsome dashboards.
In this guide, we are going to learn how to run metabase using jar file. We will create a systemd service to manage it and proxy traffic with Nginx.
To run Metabase via a JAR file, you will need to have a Java Runtime Environment (JRE) installed on your system.
Also checkout:
Installing Java
Metabase requires that you have Java 8 or higher available on your system. We have run Metabase with both the OpenJDK and Oracle JDK, so feel free to use either. We will use java 11 in this guide.
If Java is not installed in your system, use this command:
sudo dnf install java-11-openjdk
Type y
to confirm install when prompted. Once the installation is done, you can confirm the version of java installed using this command:
$ java -version
openjdk version "11.0.16.1" 2022-08-12 LTS
Running Metabase as a jar
Metabase is distributed as a single jar that can be downloaded and run. In this section we will learn how to run it in the command line. First download metabase. I am using version 0.44.3 but feel free to download the version you prefer.
curl -LO https://downloads.metabase.com/v0.44.3/metabase.jar
Next, create a new directory and move the Metabase JAR into it.
sudo mkdir /opt/metabase
sudo mv metabase.jar /opt/metabase
The most basic way of running Metabase is to open up a terminal and use Java to launch the application.
Change into the directory you created then run the JAR from a terminal with:
java -jar metabase.jar
Metabase will start using the default settings. You should see some log entries starting to run in your terminal window showing you the application progress as it starts up. Once Metabase is fully started you’ll see a confirmation such as:
2022-09-28 21:05:56,378 INFO core.QuartzScheduler :: Scheduler MetabaseScheduler_$_unstable-rockysrv1664399143835 started. 2022-09-28 21:05:56,388 INFO metabase.task :: Task scheduler started 2022-09-28 21:05:56,388 INFO metabase.core :: Metabase Initialization COMPLETE
This will launch a Metabase server on port 3000 by default. You can access metabase by navigating to http://<server_ip>:3000.
You can use another port than 3000 by setting the MB_JETTY_PORT
environment variable before running the jar.
Note that in the default configuration Metabase will use a local H2 database for storing all its own application data. This default is meant for simple evaluation or personal use. If you want to run Metabase in production the recommended way is to migrate away from H2.
Setting up Metabase for production
The steps are similar to those steps above with two important differences: if you want to run Metabase in production, you’ll want to:
- Use a production application database to store your Metabase application data.
- Run Metabase as a service.
If you’d prefer to use Docker, check out running Metabase on Docker.
Setting up Production Database
Metabase supports a couple of databases. Checkout the databases supported.
In this guide we will demonstrate a postgres example. Before proceeding ensure that you have postgres up and running. If not checkout these guides:
- How to Install and Configure Postgres 14 on Rocky Linux 9
- Running Postgresql 14 with Docker and Docker-Compose
Once postgres is up and running, connect to it then create an empty database:
create database metabase; create user metabase with encrypted password 'StrongP4$S'; grant all privileges on database metabase to metabase;
You can call your app db whatever you want. And there’s no need to create any tables in that database; Metabase will do that for you. You’ll just need to set environment variables for Metabase to use on startup so Metabase knows how to connect to this database.
Now before starting the app we need to set some environment variables:
export MB_DB_TYPE=postgres
export MB_DB_DBNAME=metabaseappdb
export MB_DB_PORT=5432
export MB_DB_USER=username
export MB_DB_PASS=password
export MB_DB_HOST=localhost
java -jar metabase.jar
The above command would connect Metabase to your Postgres database, metabaseappdb
via localhost:5432
with the user account username
and password password
. If you’re running Metabase as a service, you’ll put these environment variables in a separate configuration file.
Create an unprivileged user to run Metabase with acces to app and logs
For security reasons we want to have Metabase run as an unprivileged user. We will call the user simply metabase
. Further we will create the files we will need later for logging and configuration of Metabase, and apply the correct security settings for our unprivileged user.
sudo groupadd -r metabase
sudo useradd -r -s /bin/false -g metabase metabase
sudo chown -R metabase:metabase /opt/metabase
sudo touch /var/log/metabase.log
sudo chown rocky:rocky /var/log/metabase.log
sudo touch /etc/default/metabase
sudo chmod 640 /etc/default/metabase
Running the Metabase JAR as a service
If you need to run the JAR in production, you should run Metabase as a service. Running Metabase as a service will:
- Make sure Metabase runs automatically (and stay running).
- Allow you to run Metabase with an unprivileged user (which is good for security).
Every service needs a script that tells systemd
how to manage it, and what capabilities it supports. Services are typically registered at /etc/systemd/system/<servicename>
. So, a Metabase service should live at /etc/systemd/system/metabase.service
.
Create the /etc/systemd/system/metabase.service
service file and open it in your editor:
sudo touch /etc/systemd/system/metabase.service
sudo vim /etc/systemd/system/metabase.service
In /etc/systemd/system/metabase.service
, replace configurable items (they look like <some-var-name>
) with values sensible for your system. The Metabase script below has extra comments to help you know what everything is for.
[Unit]
Description=Metabase server
After=syslog.target
After=network.target
[Service]
WorkingDirectory=</your/path/to/metabase/directory/>
ExecStart=/usr/bin/java -jar </your/path/to/metabase/directory/>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
Create syslog conf
Next we need to create a syslog conf to make sure systemd can handle the logs properly.
sudo touch /etc/rsyslog.d/metabase.conf
sudo vim /etc/rsyslog.d/metabase.conf
if $programname == 'metabase' then /var/log/metabase.log
& stop
Restart the syslog service to load the new config.
sudo systemctl restart rsyslog.service
Environment Variables for Metabase
Environment variables provide a good way to customize and configure your Metabase instance on your server. In our systemd config, we have specified environment variables configs to be defined in etc/default/metabase
.
The Metabase config file
Open your /etc/default/metabase
environment config file in your editor:
sudo vim /etc/default/metabase
In /etc/default/metabase
, replace configurable items (they look like <some-var-name>
) with values sensible for your system. Some Metabase configs have available options, some of which are shown below, separated by |
symbols:
MB_PASSWORD_COMPLEXITY=<weak|normal|strong>
MB_PASSWORD_LENGTH=<10>
MB_JETTY_HOST=<0.0.0.0>
MB_JETTY_PORT=<12345>
MB_DB_TYPE=<postgres|mysql|h2>
MB_DB_DBNAME=<your_metabase_db_name>
MB_DB_PORT=<5432>
MB_DB_USER=<your_metabase_db_user>
MB_DB_PASS=<ssshhhh>
MB_DB_HOST=<localhost>
MB_EMOJI_IN_LOGS=<true|false>
# any other env vars you want available to Metabase
Register your Metabase service
Now, it’s time to register our Metabase service with systemd
so it will start up at system boot. We’ll also ensure our log file is created and owned by the unprivileged user our service runs the metabase.jar
as.
sudo systemctl daemon-reload
sudo systemctl start metabase.service
sudo systemctl status metabase.service
Once we are ok here, enable the service to startup during boot.
sudo systemctl enable metabase.service
Setting up Nginx for Proxy
Getting into too much detail about configuring nginx
is well outside the scope of this guide, but here’s a quick nginx.conf
file that will get you up and running.
If you don’t have nginx installed, use this command:
sudo dnf install nginx
The nginx.conf
below assumes you are accepting incoming traffic on port 80 and want to proxy requests to Metabase, and that your Metabase instance is configured to run on localhost
at port 3000
. There are several proxy directives you may care about, so you should check those out further in the Official nginx
docs.
# sample nginx-metabase.conf
# proxy requests to Metabase instance
server {
listen 80;
listen [::]:80;
server_name metabase.domain.com;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
That’s it!
Now you should be able to access your metabase set up from your browser and proceed with further configurations.
In this guide we learnt how to set up Metabase by downloading the jar, installing Java and running it. We also took a step further to set up the service as a systemd service and Nginx to proxy traffic.