Zabbix & Grafana Installation

If you wish to manually download the sql files:

1. Install Zabbix Repository

If you have a proxy you have to set it up in /etc/wget.rc.

Select a desired Zabbix version for your distribution at https://www.zabbix.com/download.

In this case we will be using Zabbix 7.0 LTS with Debian 13 (Trixie).

# debian
wget wget https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.0+debian13_all.deb
dpkg -i zabbix-release_latest_7.0+debian13_all.deb
apt update

2. Install Latest Postgres Repo

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/postgresql.gpg
sudo apt-get -y install postgresql

3. Install Zabbix Server, Frontend, Agent (v2), and plugins

# Server, Frontend, and Agent
apt install zabbix-server-pgsql zabbix-frontend-php php8.4-pgsql zabbix-apache-conf zabbix-sql-scripts zabbix-agent2
# Plugins
apt install zabbix-agent2-plugin-mongodb zabbix-agent2-plugin-mssql zabbix-agent2-plugin-postgresql 

4. Set default DB template to UTF8 in Postgres

wget "https://docs.brconsulting.info/downloads/zabbix/00-zbx-grf-install/01-zbx-set-psql-utf8-default.sql"
chmod 755 01-zbx-set-psql-utf8-default.sql
sudo -u postgres psql < 01-zbx-set-psql-utf8-default.sql

5. Create initial Zabbix DB

# This will prompt a password for your Zabbix DATABASE USER, make sure to
# generate a safe, complex one.
sudo -u postgres createuser --pwprompt zabbix
# This creates the database zabbix with the user zabbix being the owner
sudo -u postgres createdb -O zabbix zabbix 

6. Import Initial Zabbix DB Schema and data

zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix

7. Configure DB for Zabbix Server

# Edit file /etc/zabbix/zabbix_server.conf
DBPassword=password

8. Start Zabbix Services

systemctl restart zabbix-server zabbix-agent2 nginx php8.4-fpm
systemctl enable zabbix-server zabbix-agent2 nginx php8.4-fpm 

9. Setting up NGINX and PHP-FPM to access Zabbix

You’ll need to add two things for this type of installation:

  • An NGINX Configuration File.
  • A PHP-FPM Pool Configuration File.

Make sure to change the version based on what php version your zabbix version uses (in both configuration files)

NGINX Configuration File

For the NGINX Configuration file, you may wish to set it as your default_server, or not. Modify it accordingly.

# /etc/nginx/sites-available/zabbix.conf
server {
    listen 80 default_server;
    server_name zabbix.example.com;

    # Redirect HTTP to HTTPS (Temporary, for permanent use 301)
    return 307 https://$host$request_uri;
}

server {
    listen 443 ssl default_server;
    http2 on;
    server_name zabbix.example.com;

    # SSL Certificates
    ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;

    root /usr/share/zabbix;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # PHP Processing
    location ~ \.php$ {
        # fastcgi_pass unix:/run/php/php8.4-fpm.sock;
        fastcgi_pass unix:/run/php/php8.4-fpm-zabbix.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Then link it to sites-enabled with: ln -s /etc/nginx/sites-{available,enabled}/zabbix.conf

PHP-FPM Configuration File

; /etc/php/8.4/fpm/pool.d/zabbix.conf
[zabbix]
user = www-data
group = www-data
listen = /run/php/php8.4-fpm-zabbix.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

; Mandatory Zabbix frontend PHP settings
php_value[max_execution_time] = 300
php_value[memory_limit] = 128M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000

; Replace with your actual location time zone
php_value[date.timezone] = America/Buenos_Aires

Once these configuration files are set, you may restart the services:

# Reload NGINX
nginx -s reload
# Restart php-fpm
systemctl restart php8.4-fpm

Now you may access the Zabbix GUI and continue your setup by going to the server url (https://your_server_ip).

10. Locale Installation

If you require a locale that is not installed you may install one doing the following:

dpkg-reconfigure locales
systemctl restart nginx

11. Log in with Admin (User) / zabbix (Pwd)

Create an Admin API user for Grafana (If installed) with SUPER ADMIN PERMISSIONS and NO FRONT END ACCESS

12. Add Grafana repositories

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | gpg --dearmor > /etc/apt/trusted.gpg.d/grafana.gpg
echo "deb https://packages.grafana.com/enterprise/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana-enterprise

13. Start the Grafana Server

systemctl daemon-reload
systemctl start grafana-server
systemctl enable grafana-server

14. First Login

15. Installing the Zabbix Datasource Plugin (Grafana)

Go back to the terminal and install the Zabbix Datasource Plugin

grafana cli plugins install alexanderzobnin-zabbix-app
systemctl restart grafana-server

16. Enable Zabbix Plugin

Head over to the Plugins section and enable it.

17. Adding the Zabbix DB as a Datasource (Optional)

  • Create DB User and Grant read access to it
  • Then do the following:
wget https://docs.brconsulting.info/downloads/zabbix/00-zbx-grf-install/02-zbx-allow-grafana-select.sql
# MAKE SURE TO CHANGE THE PASSWORD ON THE SQL FILE.
nano 02-zbx-allow-grafana-select.sql
chmod 750 02-zbx-allow-grafana-select.sql
sudo -u postgres psql < 02-zbx-allow-grafana-select.sql
  • Add Datasource on Grafana

18. Add Zabbix Datasource (API - Requires Admin user)

  • Go back to Grafana GUI and set up the following

    (*)Only if you did step 17