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
Related content
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:
|
|
Type y
to confirm install when prompted. Once the installation is done, you can confirm the version of java installed using this command:
|
|
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.45.2 but feel free to download the version you prefer. Get the latest version from its site here.
|
|
Next, create a new directory and move the Metabase JAR into it.
|
|
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:
|
|
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:
|
|
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 Ubuntu 22.04
- 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:
|
|
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:
|
|
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.
|
|
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:
|
|
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.
|
|
Create syslog conf
Next we need to create a syslog conf to make sure systemd can handle the logs properly.
|
|
Restart the syslog service to load the new config.
|
|
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:
|
|
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:
|
|
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.
|
|
Once we are ok here, enable the service to startup during boot.
|
|
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:
|
|
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.
|
|
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.