Metabase is a free and open source GUI-based query tool. It integrates with almost all types of databases and provides a very simple GUI to run queries on the database. Metabase lets you easily filter and group the data to find something without writing the SQL query. The application lets you visualize the data into beautiful charts and graphs.
In this tutorial, we will install Metabase on CentOS 7 server.
Requirements
Metabase requires at least 1GB of RAM. All the required dependencies will be installed throughout the tutorial. You will need a minimal installation of CentOS 7 with root access on it. If you are logged in as a non-root user, you can run sudo -i
to switch to root user.
Installing Metabase
Before installing any package it is recommended that you update the packages and repository using the following command.
yum -y update
Metabase runs on both OpenJDK and Oracle JAVA. In this tutorial, we will install the latest version of Oracle Java into the server. Run the following commands to do so.
wget --no-cookies --no-check-certificate --header "Cookie:oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.rpm"
If you do not have wget
installed, you can run the yum -y install wget
to install wget. Now install the downloaded RPM using the following command.
yum localinstall jdk-8u121-linux-x64.rpm
You can now check the java version using the following command.
java -version
You will get the following output:
[root@liptan-pc ~]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Now download the Metabase jar file using the following command:
wget http://downloads.metabase.com/v0.23.1/metabase.jar
You can always check for the link to the latest version of Metabase using Metabase download page.
To start the application immediately you can run the following command.
java -jar metabase.jar
But it is recommended to create a systemd service to run Metabase jar file and create a reverse proxy with Apache or nginx for accessing the application on port 80. Using systemd service will automatically start the application on failures and boot time.
Move the Metabase jar file to another location using the following command.
mv metabase.jar /var/metabase.jar
To create a systemd service, create a new systemd service file using the following command.
nano /etc/systemd/system/metabase.service
Now add the following lines into the text file.
[Unit]
Description=Metabase server
After=syslog.target
After=network.target
[Service]
User=root
Type=simple
ExecStart=/bin/java -jar /var/metabase.jar
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=metabase
[Install]
WantedBy=multi-user.target
Save the above text into the Systemd service file. You can now run the Metabase server directly using the following command.
systemctl start metabase
To enable the application to start automatically at boot time, run the following command.
systemctl enable metabase
To check the status of the service, run the following command.
systemctl status metabase
You will likely see the following output.
[root@liptan-pc ~]# systemctl status metabase
● metabase.service - Metabase server
Loaded: loaded (/etc/systemd/system/metabase.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2017-04-09 19:59:32 UTC; 8h ago
Main PID: 18283 (java)
CGroup: /system.slice/metabase.service
└─18283 /bin/java -jar /var/metabase.jar
Apr 09 20:01:44 ip-172-31-10-224 metabase[18283]: 04-09 20:01:44 INFO sync-database.analyze :: Analyzing data in H2...) ...
Instead of using the application on Port 3000, you can use nginx to run on port 80 or 443 in the case of using SSL. This way the main application will run on port 3000, and nginx will work as a reverse proxy. Nginx is not available in the default YUM repository, hence you will need to install EPEL repository also.
yum -y install epel-release
yum -y update
Install nginx web server the following command.
yum -y install nginx
Now we will need to generate SSL certificates from Let’s Encrypt client. If you can want to use commercial SSL certificates instead, you can purchase SSL certificates from HostPresto.
To install Let’s Encrypt client also called Certbot run the following command.
yum -y install certbot
Once the installation finishes, run the following command to obtain the SSL certificates from Let’s Encrypt. Make sure that your domain is pointed to the server, the Let’s Encrypt will check the domain authority before providing the certificates. Make sure that you do not have nginx running at this moment.
certbot certonly --standalone -d yourdomain.com -d www.yourdomain.com
This command will run Let’s Encrypt client to obtain the certificates only but will not install it. --standalone
tells the client to use the standalone web server for authentication of domain authority. -d yourdomain.com
tells the domain name for which the certificates needs to be obtained. Provide your email address and accept the terms and condition. Once the certificates are generated, they are likely to be stored in the following directory.
/etc/letsencrypt/live/yourdomain.com
Where yourdomain.com
is your actual domain. In the directory, you will find cert.pem
which is your domains certificate and privkey.pem
which is your certificate’s private key.
Let’s Encrypt SSL expires in 90 days, so it is recommended to set an automatic renewal for your certificates. Run the following command to open your crontab file.
crontab -e
Enter the following line into the crontab file.
30 1 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log
The above cron job will automatically run every Monday at 1:30 AM and if your certificates are due for expiry, it will automatically renew them.
As the SSL certificates are now generated, we can proceed further to configure nginx configuration file. Now create a new server block for nginx configuration file using the following command.
nano /etc/nginx/conf.d/ssl-yourdomain.com.conf
Replace yourdomain.com
with your actual domain. Now copy and paste the following lines into the file.
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 http2 ssl;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:3000;
proxy_read_timeout 90;
proxy_redirect http://localhost:3000 https://yourdomain.com;
}
}
In the above configuration change yourdomain.com
to your actual domain. Also, make sure that the path to your SSL certificate and private key are correct. Now start nginx web server and enable it to automatically start at boot time using the following commands.
systemctl start nginx
systemctl enable nginx
Now you will need to disable your SELinux because Proxy configuration does not work with SELinux policies. To temporarily disable SELinux without restarting the server, run the following command.
setenforce 0
To completely disable the SELinux you will need to edit the /etc/selinux/config
file.
nano /etc/selinux/config
Find the following line:
SELINUX=enforcing
Change it to:
SELINUX=disabled
Now you will need to reboot your server so that the new configuration can take effect. Now you can start the Metabase service if not started already using the following command.
systemctl start metabase
You can now browse the following URL in your favorite browser.
https://YourDomain.com
You will see the following screen.
HP_NO_IMG/data/uploads/users/5bc5f3e0-17df-4257-afd4-59fc57ecae4e/1943891599.png” alt=”” />
Click on the button Let’s get started. You will be asked to create the administrator account.
HP_NO_IMG/data/uploads/users/5bc5f3e0-17df-4257-afd4-59fc57ecae4e/507356446.png” alt=”” />
Provide your details and click Next. You will be asked to add a database now. You can add the database now or, you can choose to skip this step. Metabase comes with few sample database on which you can run your queries to test the application.
Finally, you will be taken to your Metabase dashboard, which will look like shown below.
HP_NO_IMG/data/uploads/users/5bc5f3e0-17df-4257-afd4-59fc57ecae4e/1371446301.png” alt=”” />
Conclusion
In this tutorial, we installed Metabase on CentOS 7. You can now successfully use the application for learning the insights from your dataset.