The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Update Debian/systemd docs (#62701)
Rodrigo López Dato76b863c7ea43
diff --git a/docs/installation-and-operation/running-metabase-on-debian.md b/docs/installation-and-operation/running-metabase-on-debian.mdindex d6a4fadfab8..3c0e411434a 100644--- a/docs/installation-and-operation/running-metabase-on-debian.md+++ b/docs/installation-and-operation/running-metabase-on-debian.md@@ -1,136 +1,119 @@----title: Running Metabase on Debian as a service with nginx+title: Running Metabase as a systemd serviceredirect_from:- /docs/latest/operations-guide/running-metabase-on-debian----# Running Metabase on Debian as a service with nginx+# Running Metabase as a systemd service-For those people who don't (or can't) use Docker in their infrastructure, there's still a need to easily setup and deploy Metabase in production. On Debian-based systems, this means registering Metabase as a service that can be started/stopped/uninstalled.+For those people who don't (or can't) use Docker in their infrastructure, you can register Metabase as a [systemd](https://wiki.debian.org/systemd) service that can be started/stopped/uninstalled.-**Note:** This is just a _bare-bones recipe_ to get you started. Anyone can take it from here to do what they need to do on their systems, and should follow best practices for setting up and securing the rest of their server.+We'll use Debian as an example in this guide, but the steps should apply to most Linux distributions that use systemd. This is a _bare-bones recipe_ to get you started. Anyone can take it from here to do what they need to do on their systems, and should follow best practices for setting up and securing the rest of their server.## Assumptions-The core assumption in this guide:+The core assumptions in this guide:+- You have a [Java Runtime Environment (JRE)](../installation-and-operation/running-the-metabase-jar-file#1-install-java-jre) installed on your system- You will run Metabase using the `metabase.jar` file-- You already have `nginx` and `postgres` (or another supported database) running on your server+- You already have Nginx running on your server- You will use environment variables to configure your Metabase instance-- You have `sudo` access on your server+- You have root access on your server-## Create an unprivileged user to run Metabase and give the user access to app and logs+For production setups, you must set up a [PostgreSQL or MySQL/MariaDB application database](/../installation-and-operation/configuring-application-database) as Metabase's application database.-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.+## Create an unprivileged user to run Metabase-```+For security reasons, we want to have Metabase run as an unprivileged user. If you don't already have such a user, create one called `metabase`:++```sh+# Create a "metabase" groupsudo groupadd -r metabase-sudo useradd -r -s /bin/false -g metabase metabase-sudo chown -R metabase:metabase </your/path/to/metabase/directory>-sudo touch /var/log/metabase.log-sudo chown syslog:adm /var/log/metabase.log-sudo touch /etc/default/metabase-sudo chmod 640 /etc/default/metabase++# Create a "metabase" user, with a home directory at /home/metabase+sudo useradd -m -r -s /bin/false -g metabase metabase```-## Create a Metabase Service+## Download the Metabase JAR file-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`.+The Metabase JAR file can be stored anywhere that the `metabase` user can read from.+One convenient location is this user's home directory at `/home/metabase`.-### The Metabase service file+If you prefer to use a different location for the Metabase JAR file, make sure to update any references to `/home/metabase/metabase.jar` in the following steps throughout this guide.-Create the `/etc/systemd/system/metabase.service` service file and open it in your editor:+```sh+# Download the Metabase OSS JAR file into /home/metabase:+sudo -u metabase wget -O /home/metabase/metabase.jar https://downloads.metabase.com/latest/metabase.jar++# Or, if you're using Metabase Pro/Enterprise:+sudo -u metabase wget -O /home/metabase/metabase.jar https://downloads.metabase.com/enterprise/latest/metabase.jar-```-sudo touch /etc/systemd/system/metabase.service-sudo <your-editor> /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.+## Environment variables for Metabase++[Environment variables](../configuring-metabase/environment-variables.md) let you configure and customize your Metabase instance.++We'll create a file to store these environment variables, which we'll use when creating the systemd service for Metabase.+This command will create an environment variable file at `/home/metabase/.env`, which you should update to point to your [PostgreSQL application database](/docs/latest/installation-and-operation/configuring-application-database):++```bash+sudo -u metabase cat << EOF > /home/metabase/.env+MB_JETTY_HOST=127.0.0.1+MB_JETTY_PORT=3000++# Uncomment and update the variables below to connect to your Postgres application database+# If not set, Metabase will use a built-in database (not suitable for production)+# MB_DB_TYPE=postgres+# MB_DB_HOST=your_metabase_db_hostname+# MB_DB_PORT=5432+# MB_DB_DBNAME=your_metabase_db_name+# MB_DB_USER=your_metabase_db_user+# MB_DB_PASS=your_metabase_db_password+EOF```++## Create a Metabase service++Every service needs a configuration file that tells systemd how to manage it and what capabilities it supports. System-wide services are typically registered at `/etc/systemd/system/<servicename>`. So, a Metabase service should live at `/etc/systemd/system/metabase.service`.++### The Metabase service file++The following command will create a file at `/etc/systemd/system/metabase.service` with a simple systemd service file to run Metabase:++```sh+sudo cat << EOF > /etc/systemd/system/metabase.service[Unit]Description=Metabase server-After=syslog.targetAfter=network.target[Service]-WorkingDirectory=</your/path/to/metabase/directory/>-ExecStart=/usr/bin/java --add-opens java.base/java.nio=ALL-UNNAMED -jar </your/path/to/metabase/directory/>metabase.jar-EnvironmentFile=/etc/default/metabase+WorkingDirectory=~+ExecStart=/usr/bin/java --add-opens java.base/java.nio=ALL-UNNAMED -jar /home/metabase/metabase.jar+EnvironmentFile=/home/metabase/.envUser=metabaseType=simple-StandardOutput=syslog-StandardError=syslog-SyslogIdentifier=metabaseSuccessExitStatus=143TimeoutStopSec=120Restart=always[Install]WantedBy=multi-user.target+EOF```-## 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 <your-editor> /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](../configuring-metabase/environment-variables.md) provide a good way to customize and configure your Metabase instance on your server. On Debian systems, services typically expect to have accompanying configs inside `etc/default/<service-name>`.--### The Metabase config file--Open your `/etc/default/metabase` environment config file in your editor:--```-sudo <your-editor> /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-```--## Final steps+The best part of setting up Metabase as a systemd service is that it will start up at every system boot, and get restarted automatically if it crashes. We only have a few more quick steps to finish registering our service and having Metabase up and running.-The best part of setting up Metabase as a service on a Debian-based system is to be confident it will start up at every system boot. We only have a few more quick steps to finish registering our service and having Metabase up and running.+## Ensure your database is ready-### Ensure your database is ready+If you're running a PostgreSQL application database, make sure you've created a database for Metabase, as well as a user that can access that database. These values should match what you've set in your Metabase config for the `MB_DB_TYPE`, `MB_DB_DBNAME`, `MB_DB_USER`, and `MB_DB_PASS` environment variables. If you don't have your database properly configured, Metabase won't be able to start.-If you're running `postgres` or some other database, you need to ensure you've already followed the instructions for your database system to create a database for Metabase, as well as a user that can access that database. These values should match what you've set in your Metabase config for the `MB_DB_TYPE`, `MB_DB_DBNAME`, `MB_DB_USER`, and `MB_DB_PASS` environment variables. If you don't have your database properly configured, Metabase won't be able to start.+## Ensure Nginx proxies requests to Metabase-### Ensure `nginx` is setup to proxy requests to Metabase+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.-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.--**Note:** 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](https://nginx.org/en/docs/).+**Note:** 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](https://nginx.org/en/docs/).```# sample nginx.conf@@ -138,16 +121,16 @@ Getting into too much detail about configuring `nginx` is well outside the scopeserver {listen 80;listen [::]:80;- server_name your.domain.com;+ server_name yourdomain.example.com;location / {proxy_pass http://127.0.0.1:3000;}}```-### Register your Metabase service+## 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.+Now, it's time to register our Metabase service with systemd so it will start up at system boot:```sudo systemctl daemon-reload@@ -155,7 +138,13 @@ sudo systemctl start metabase.servicesudo systemctl status metabase.service```-Once we are ok here, enable the service to startup during boot.+To print the live Metabase service logs, you can run:++```+journalctl -fxeu metabase.service+```++Once we are OK here, enable the service to start up during boot:```sudo systemctl enable metabase.service@@ -163,10 +152,10 @@ sudo systemctl enable metabase.service## Start, stop, or restart Metabase-Now, whenever you need to start, stop, or restart Metabase, all you need to do is:+Now, whenever you need to restart, stop, or start Metabase, all you need to do is:```-sudo systemctl start metabase.service-sudo systemctl stop metabase.servicesudo systemctl restart metabase.service+sudo systemctl stop metabase.service+sudo systemctl start metabase.service```