UbuntuUbuntu Based

How To Install Metabase on Ubuntu 22.04 LTS

Install Metabase on Ubuntu 22.04

In this tutorial, we will show you how to install Metabase on Ubuntu 22.04 LTS. For those of you who didn’t know, Metabase is an open-source business intelligence and analytics platform that allows users to easily create and share interactive dashboards and reports, it can connect to a variety of data sources, and the drag-and-drop interface makes it easy for non-technical users to create charts, graphs, and reports, it also provides a wide range of customization options, it has built-in data warehousing feature and can handle big data with the help of external data warehousings solutions like Amazon Redshift and Google BigQuery.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Metabase with Docker. You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Metabase.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Metabase on Ubuntu 22.04 LTS Jammy Jellyfish

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Installing Docker.

By default, Docker is not available on Ubuntu 22.04 base repository. Now run the following command below to add the Docker repository to the system:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Next, import the GPG key to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

After the repository is enabled, now install the latest version of the Docker package using the below command:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

You can verify that Docker is installed and about the current version:

docker -v

After successfully installed, enable Docker (to start automatically upon system boot), start, and verify the status using the commands below:

sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl status docker

By default, Docker requires root privileges. If you want to avoid using sudo every time you run the docker command, add your username to the docker group:

sudo usermod -aG docker $(whoami)
su - ${USER}

Confirm that your user is added to the Docker group:

groups

For additional resources on installing and managing Docker, read the post below:

Step 3. Create Docker Compose File for Metabase.

First, create a directory for Metabase configuration:

mkdir metabase
cd metabase

Next, create and open the Docker compose file using your favorite text editor:

nano docker-compose.yml

Add the following file:

version: '3.9'
services:
  metabase:
    image: metabase/metabase:latest
    container_name: metabase
    hostname: metabase
    volumes:
    - /dev/urandom:/dev/random:ro
    ports:
      - 3000:3000
    environment:
      MB_DB_TYPE: postgres
      MB_DB_DBNAME: metabase
      MB_DB_PORT: 5432
      MB_DB_USER_FILE: /run/secrets/db_user
      MB_DB_PASS_FILE: /run/secrets/db_password
      MB_DB_HOST: postgres
    env_file:
      - metabase.env
    healthcheck:
      test: curl --fail -I http://localhost:3000/api/health || exit 1
      interval: 15s
      retries: 5
      start_period: 10s
      timeout: 5s
    networks:
      - metanet1
    depends_on:
      - postgres
    secrets:
      - db_password
      - db_user
  postgres:
    image: postgres:latest
    container_name: postgres
    hostname: postgres
    environment:
      POSTGRES_USER_FILE: /run/secrets/db_user
      POSTGRES_DB: metabase
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
    healthcheck:
      test: ['CMD', 'pg_isready', '-U', 'postgres']
    volumes:
      - ./postgresql:/var/lib/postgresql/data
    networks:
      - metanet1
    secrets:
      - db_password
      - db_user
networks:
  metanet1:
    driver: bridge
secrets:
   db_password:
     file: db_password.txt
   db_user:
     file: db_user.txt

Save and close the file. The PostgreSQL database username and password are stored in the files db_user.txt and db_password.txt files respectively.

Then we create and open the db_user.txt file for editing:

nano db_user.txt

Next, create and open the db_password.txt file for editing:

nano db_password.txt

Step 4.  Configure Environment files Metabase.

First, we generate an encryption key using the following command below:

openssl rand -base64 32

Next, create and open the metabase.env file for editing:

nano metabase.env

Add the following code to it. Paste the secret key you generated against the MB_ENCRYPTION_SECRET_KEY variable. Fill in your Metabase domain including the HTTPS protocol. Fill in your SMTP details using whichever provider you use. We are using Amazon SES. The MB_PASSWORD_COMPLEXITY variable is set to strong which means your Metabase password:

MB_SITE_URL=https://your-domain.com
MB_SITE_NAME="Howtoforge"

MB_ADMIN_EMAIL=meilana@your-domain.com
MB_EMAIL_FROM_ADDRESS=admin@your-domain.com
MB_EMAIL_FROM_NAME=idroot
MB_EMAIL_SMTP_HOST=email-smtp.us-west-2.amazonaws.com
MB_EMAIL_SMTP_USERNAME=AWS_USERID
MB_EMAIL_SMTP_PASSWORD=AWS_KEY
MB_EMAIL_SMTP_PORT=587
MB_EMAIL_SMTP_SECURITY=starttls

MB_ENCRYPTION_SECRET_KEY=QWPbmwNvWYVqR5Ne46dk0OvTH1xWGDt=
MB_ANON_TRACKING_ENABLED=false
MB_APPLICATION_NAME=Howtoforge Metabase
MB_PASSWORD_COMPLEXITY=strong

After all our configuration files are complete, it is time to start and launch the containers:

docker compose up -d

You can watch the status of the containers using the following command below:

watch docker ps

Step 5. Installing Nginx

By default, the Nginx is available on Ubuntu 22.04 base repository. Now run the following command below to install the latest version of Nginx to your Ubuntu system:

sudo apt install nginx

After successful installation, enable Nginx (to start automatically upon system boot), start, and verify the status using the commands below:

sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx

Confirm the installation and check the installed build version of Nginx:

nginx -v

Now create vhost and open the file /etc/nginx/conf.d/metabase.conf:

nano /etc/nginx/conf.d/metabase.conf

Add the following file:

server {
  # Redirect any http requests to https
  listen         80;
  listen         [::]:80;
  server_name    your-domain.com;
  return 301     https://$host$request_uri;
}

server {
  listen                    443 ssl http2;
  listen                    [::]:443 ssl http2;
  server_name               your-domain.com.com;

  access_log                /var/log/nginx/metabase.access.log;
  error_log                 /var/log/nginx/metabase.error.log;

  location / {
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_set_header	    X-Forwarded-Host $http_host;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass              http://127.0.0.1:3000;
  }
}

Save and close the file then, restart the Nginx service with the following command:

nginx -t
sudo systemctl restart nginx

For additional resources on installing Nginx, read the post below:

Step 6. Secure Metabase with Let’s Encrypt SSL.

First, install the Certbot client using the following command below:

sudo apt install certbot python3-certbot-nginx

Next, get your SSL certificate with Let’s Encrypt by following these steps:

certbot --apache -d your-domain.com

Let’s Encrypt certificates have 90 days of validity, and it is highly advisable to renew the certificates before they expire. You can test automatic renewal for your certificates by running this command:

sudo certbot renew --dry-run

Step 7. Configure Firewall.

Ubuntu 22.04 has ufw a firewall running by default. Enable connection through ports 80 HTTP and 443 HTTPS:

sudo ufw allow 'Nginx FULL'
sudo ufw enable
sudo ufw status

Step 8. Accessing Metabase Web Interface.

Once successfully installed, open your web browser and access the Metabase Web UI using the URL https://your-domain.com. You will be redirected to the following page:

Install Metabase on Ubuntu 22.04 LTS Jammy Jellyfish

Congratulations! You have successfully installed Metabase. Thanks for using this tutorial for installing Metabase with Docker Compose on the Ubuntu system. For additional help or useful information, we recommend you check the official Metabase website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button