Link Search Menu Expand Document

Installing and using Zabbix

This is how I installed a new instance of Zabbix on a Proxmox guest, moving from an ESXi host and along transfer the new database to the newly created guest.

Table of contents
  1. Getting started
    1. Prerequisites
    2. Install qemu-guest-agent
    3. tzdata
    4. Perform backup
    5. Stop Zabbix server
    6. Back up the existing Zabbix database
    7. Back up configuration files, PHP files and Zabbix binaries
  2. Installation
    1. Install Zabbix repository
    2. Install Zabbix server, frontend, agent
    3. Import old database
    4. Configure the database for Zabbix server
    5. Configure PHP for Zabbix frontend
    6. Start Zabbix server and agent processes
    7. Configure Zabbix frontend
  3. FreeNAS
    1. Dependencies
    2. Coniguration of FreeNAS
    3. Import templates
  4. Fault finding
    1. Stop all Zabbix processes
    2. Delete a database
    3. Show version
    4. Unable to connect
    5. Upgrade
  5. Authors
  6. Acknowledgments

Getting started

Prerequisites

  • Ubuntu 18.04
  • MySQL
  • NGINX

Install qemu-guest-agent

The qemu-guest-agent is a helper daemon, which is installed in the guest. It is used to exchange information between the host and guest, and to execute command in the guest.

In Proxmox VE, the qemu-guest-agent is used for mainly two things:

To properly shutdown the guest, instead of relying on ACPI commands or windows policies To freeze the guest file system when making a backup (on windows, use the volume shadow copy service VSS).

administrator@zabbix:~$ sudo apt-get install qemu-guest-agent
administrator@zabbix:~$ sudo shutdown now

In Proxmox, go to Options and Enable by selecting Use QEMU Guest Agent. Start your VM again.

tzdata

Ensure that your timezone is correct.

merovingian@zabbix:~$ sudo dpkg-reconfigure tzdata

Perform backup

Outline; Server upgrade process

1 Stop Zabbix server

Stop Zabbix server to make sure that no new data is inserted into database.

2 Back up the existing Zabbix database

This is a very important step. Make sure that you have a backup of your database. It will help if the upgrade procedure fails (lack of disk space, power off, any unexpected problem).

3 Back up configuration files, PHP files and Zabbix binaries

Make a backup copy of Zabbix binaries, configuration files and the PHP file directory.

Stop Zabbix server

Stop Zabbix server to make sure that no new data is inserted into database.

zabbix@linuxdog:~$ service zabbix-server stop
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'zabbix-server.service'.
Authenticating as: Monitoring Tool (zabbix)
Password: 
==== AUTHENTICATION COMPLETE ===
zabbix@linuxdog:~$ 
zabbix@linuxdog:~$ service zabbix-agent stop
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'zabbix-agent.service'.
Authenticating as: Monitoring Tool (zabbix)
Password: 
==== AUTHENTICATION COMPLETE ===
zabbix@linuxdog:~$ 

Back up the existing Zabbix database

This is a very important step. Make sure that you have a backup of your database. It will help if the upgrade procedure fails (lack of disk space, power off, any unexpected problem).

List available databases:

zabbix@linuxdog:~$ sudo su
[sudo] password for zabbix: 
root@linuxdog:/home/zabbix# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 31209
Server version: 10.1.43-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT table_schema "databases name", sum(data_length + index_length)/1024/1024  "DВ size in MB" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+----------------+
| databases name     | DВ size in MB  |
+--------------------+----------------+
| information_schema |     0.17187500 |
| mysql              |     0.87331867 |
| performance_schema |     0.00000000 |
| zabbix             |  1187.75000000 |
+--------------------+----------------+
4 rows in set (0.09 sec)

MariaDB [(none)]> 

Back up configuration files, PHP files and Zabbix binaries

Make a backup copy of Zabbix binaries, configuration files and the PHP file directory.

Configuration files:

zabbix@linuxdog:~$ sudo mkdir /opt/zabbix-backup/
zabbix@linuxdog:~$ cp /etc/zabbix/zabbix_server.conf /opt/zabbix-backup/
zabbix@linuxdog:~$ sudo cp /etc/zabbix/zabbix_server.conf /opt/zabbix-backup/
zabbix@linuxdog:~$ sudo cp /etc/apache2/conf-enabled/zabbix.conf /opt/zabbix-backup/
zabbix@linuxdog:~$ 

PHP files and Zabbix binaries:

zabbix@linuxdog:~$ sudo cp -R /usr/share/zabbix/ /opt/zabbix-backup/
zabbix@linuxdog:~$ sudo cp -R /usr/share/doc/zabbix-* /opt/zabbix-backup/

Installation

https://www.zabbix.com/download?zabbix=4.4&os_distribution=ubuntu&os_version=18.04_bionic&db=mysql&ws=apache

Install Zabbix repository

# wget https://repo.zabbix.com/zabbix/4.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.4-1+bionic_all.deb
# dpkg -i zabbix-release_4.4-1+bionic_all.deb
# apt update

Install Zabbix server, frontend, agent

# apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent

Import old database

Then we are going to import the old database in to the new ZABBIX instance. Before we do that, stop all zabbix processes;

root@zabbix:/home/merovingian# systemctl stop zabbix-server zabbix-agent apache2

Then we will create a new database, zabbix44, and grant all privileges to which a user named zabbix can connect to from localhost. Then we will import the old database dump to this newly created zabbix44 database:

merovingian@zabbix:~ sudo su
[sudo] password for merovingian: 
root@zabbix:/home/merovingian# 
root@zabbix:/home/merovingian# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 112
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database zabbix44 character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix44.* to zabbix@localhost identified by 'zabbix-user-password;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit;
root@zabbix:/home/merovingian# mysql -uzabbix -p zabbix44 < /home/merovingian/oldzabbix/2020-01-23\ ZABBIX\ backup/dbdump 
Enter password: zabbix-user-password

Importing the old database into zabbix44 might take some time, depending on how large the old database is.

Configure the database for Zabbix server

Edit file /etc/zabbix/zabbix_server.conf:

merovingian@zabbix:~$ sudo nano /etc/zabbix/zabbix_server.conf 
[sudo] password for merovingian: 
(...)
DBName=zabbix44
(...)
DBPassword=zabbix-user-password

Configure PHP for Zabbix frontend

Edit file /etc/zabbix/apache.conf, uncomment and set the right timezone for you.

merovingian@zabbix:~$ sudo nano /etc/zabbix/apache.conf 
 # php_value date.timezone Europe/Riga
    </IfModule>
    <IfModule mod_php7.c>
(...)
 # php_value date.timezone Europe/Riga

Start Zabbix server and agent processes

Now we are goingn to start Zabbix. Before we do that, open a new terminal and let us tail the zabbix server log file to see what is going on:

merovingian@zabbix:~$ tail -f /var/log/zabbix/zabbix_server.log 

Let us start everything:

merovingian@zabbix:~$ sudo systemctl restart zabbix-server zabbix-agent apache2

Our tail -f window should now display that zabbix is performing a database upgrade.

(...)
  3288:20200211:125834.910 completed 93% of event name update
  3288:20200211:125834.910 completed 94% of event name update
  3288:20200211:125835.442 completed 95% of event name update
  3288:20200211:125835.442 completed 96% of event name update
  3288:20200211:125835.442 completed 97% of event name update
  3288:20200211:125835.443 completed 98% of event name update
  3288:20200211:125835.443 completed 99% of event name update
  3288:20200211:125835.443 completed 100% of event name update
  3288:20200211:125835.456 event name update completed
(...)

Make the Zabbix server and agent processes start at system boot.

# systemctl enable zabbix-server zabbix-agent apache2

Configure Zabbix frontend

Connect to your newly installed Zabbix frontend: http://server_ip_or_name/zabbix.

Remember, if you are using an old database, the GUI usernames and passwords are the same as it was.

merovingian@zabbix:~/oldzabbix/2020-01-23 ZABBIX backup$ sudo su
[sudo] password for merovingian: 
root@zabbix:/home/merovingian/oldzabbix/2020-01-23 ZABBIX backup# bzip2 -d dbdump.bz2 
root@zabbix:/home/merovingian/oldzabbix/2020-01-23 ZABBIX backup# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 53
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT table_schema "databases name", sum(data_length + index_length)/1024/1024  "DВ size in MB" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+----------------+
| databases name     | DВ size in MB  |
+--------------------+----------------+
| information_schema |     0.17187500 |
| mysql              |     0.65456867 |
| performance_schema |     0.00000000 |
| zabbix             |    14.39062500 |
+--------------------+----------------+
4 rows in set (0.02 sec)

MariaDB [(none)]> exit
root@zabbix:/home/merovingian/oldzabbix/2020-01-23 ZABBIX backup# mysql -u zabbix -p zabbix < /home/merovingian/oldzabbix/2020-01-23\ ZABBIX\ backup/dbdump 
Enter password: 
root@zabbix:/home/merovingian/oldzabbix/2020-01-23 ZABBIX backup# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 55
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT table_schema "databases name", sum(data_length + index_length)/1024/1024  "DВ size in MB" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+----------------+
| databases name     | DВ size in MB  |
+--------------------+----------------+
| information_schema |     0.17187500 |
| mysql              |     0.65456867 |
| performance_schema |     0.00000000 |
| zabbix             |   971.48437500 |
+--------------------+----------------+
4 rows in set (0.07 sec)

MariaDB [(none)]> 

FreeNAS

Dependencies

merovingian@zabbix:/usr/bin$ sudo apt-get install snmp snmp-mibs-downloader

Coniguration of FreeNAS

Go to FreeNAS GUI and select Services. Edit SNMP as follow:

  • Location: FreeNAS
  • Contact: bender@ilovebender.com
  • Community: BenderNAS
  • [v] SNMP v3 Support
  • Username: usernameX
  • Authentication Type: MD5
  • Password: password1
  • Privacy Protocol: DES
  • Privacy Passphrase: passphrase2
  • Log Level: Error

Hit SAVE.

Copy all the mibs from /usr/local/share/snmp/mibs/ on your FreeNAS to /usr/share/snmp/mibs on your Zabbix.

Import templates

Download https://share.zabbix.com/storage-devices/freenas/freenas-11.

Go to Configuration > Hosts and select your FreeNAS server. Go to Macros and add

  • `{$SNMP_COMMUNITY} is the Community (BenderNAS)
  • {$SNMP_SECNAME} is the Username (usernameX)
  • {$SNMP_AUTH} is the Authentication password (password1)
  • {$SNMP_PRIV} is the Pricacy Passphrase (passphrase2)

{$SNMP_USER} – User name used for authentication in SNMPv3 (by default “racom”)

Restart the Zabbix server.

snmpwalk -v3 -l authPriv -u rtyuih675 -a SHA -A “askdjhfz67z6asd7fgoya” -x DES -X “oisduhx7986x8ygai” 192.168.5.13:161


Fault finding

Stop all Zabbix processes

merovingian@zabbix:~$ sudo su
root@zabbix:/home/merovingian# mysql
root@zabbix:/home/merovingian# systemctl stop zabbix-server zabbix-agent apache2

Delete a database

merovingian@zabbix:~$ sudo su
root@zabbix:/home/merovingian# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 66
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| zabbix             |
+--------------------+
4 rows in set (0.01 sec)

MariaDB [(none)]> DROP DATABASE zabbix;
Query OK, 150 rows affected (5.05 sec)

MariaDB [(none)]> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 

Show version

merovingian@zabbix:/home/merovingian# zabbix_server --version
zabbix_server (Zabbix) 4.4.5
Revision b93f5c4fc0 28 January 2020, compilation time: Jan 30 2020 11:27:03

Copyright (C) 2020 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).

Compiled with OpenSSL 1.1.0g  2 Nov 2017
Running with OpenSSL 1.1.1  11 Sep 2018
root@zabbix:/home/merovingian# 

Unable to connect

Is zabbix.conf.php pointing to the correct database?

merovingian@zabbix:/etc/zabbix/web$ ls -alh
total 12K
drwxr-xr-x 2 www-data root     4.0K Feb 11 14:41 .
drwxr-xr-x 4 root     root     4.0K Feb 11 14:35 ..
-rw-r--r-- 1 www-data www-data  431 Feb 11 14:36 zabbix.conf.php
merovingian@zabbix:/etc/zabbix/web$ sudo nano zabbix.conf.php 

Upgrade

https://www.zabbix.com/documentation/current/manual/installation/upgrade/packages/debian_ubuntu

merovingian@zabbix:~$ sudo apt-get update
merovingian@zabbix:~$ sudo apt-get upgrade

PHP:

merovingian@zabbix:~$ php -v
PHP 7.2.24-0ubuntu0.18.04.6 (cli) (built: May 26 2020 13:09:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.6, Copyright (c) 1999-2018, by Zend Technologies

MariaDB:

merovingian@zabbix:~$ sudo su
[sudo] password for merovingian: 
root@zabbix:/home/merovingian# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16462
Server version: 10.1.44-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> Ctrl-C -- exit!
Aborted

bzip2 -d dbdump.bz2


Authors

Mrs. Johnson


Acknowledgments