Note: You need to log in as a root user on your Linux server with “su -” or use “sudo” to successfully execute commands used in this tutorial.
Step 1: Install Zabbix server, frontend, and agent
Install Zabbix 5 .deb package on your Ubuntu OS (Ubuntu 20.04 Focal and Ubuntu 18.04 Bionic are supported). Choose 5.0 LTS release (stable, 5-year support) or 5.2 standard release (more features, 6-month support, more bugs).
Zabbix 5.0 LTS version (supported until May 31, 2025)
wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+$(lsb_release -sc)_all.deb
sudo dpkg -i zabbix-release_5.0-1+$(lsb_release -sc)_all.deb
sudo apt update
sudo apt-get upgrade
sudo apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent
OR
Zabbix 5.2 standard version (supported until May 31, 2021)
wget https://repo.zabbix.com/zabbix/5.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.2-1+ubuntu$(lsb_release -rs)_all.deb
sudo dpkg -i zabbix-release_5.2-1+ubuntu$(lsb_release -rs)_all.deb
sudo apt update
sudo apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent
Step 2: Configure database
In this installation, I will use password rootDBpass as root password and zabbixDBpass as Zabbix password for DB. Consider changing your password for security reasons.
a. Install MariaDB
Install MariaDB database:
sudo apt -y install mariadb-common mariadb-server mariadb-client
If you receive a error because of unmet dependencies, then install it like this “sudo apt -y install mariadb-common mariadb-server-10.3 mariadb-client-10.3“.
Once the installation is complete, start the MariaDB service and enable it to start on boot using the following commands:
sudo systemctl start mariadb
sudo systemctl enable mariadb
b. Reset root password for database
Secure MySQL/MariaDB by changing the default password for MySQL root:
sudo mysql_secure_installation
Enter current password for root (enter for none): Press Enter
Set root password? [Y/n]: Y
New password: <Enter root DB password>
Re-enter new password: <Repeat root DB password>
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
c. Create database
sudo mysql -uroot -p'rootDBpass' -e "create database zabbix character set utf8 collate utf8_bin;"
sudo mysql -uroot -p'rootDBpass' -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbixDBpass';"
d. Import initial schema and data.
Temporary disable strict mode (ZBX-16465) to avoid MySQL error “ERROR 1118 (42000) at line 1284: Row size too large (> 8126)” :
sudo mysql -uroot -p'rootDBpass' zabbix -e "set global innodb_strict_mode='OFF';"
Import database shema for Zabbix server (could last up to 5 minutes):
sudo zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p'zabbixDBpass' zabbix
Enable strict mode:
sudo mysql -uroot -p'rootDBpass' zabbix -e "set global innodb_strict_mode='ON';"
e. Enter database password in Zabbix configuration file
Open zabbix_server.conf file with command:
sudo nano /etc/zabbix/zabbix_server.conf
and add database password in this format anywhere in file:
DBPassword=zabbixDBpass
Save and exit file (ctrl+x, followed by y and enter).
Step 3: Configure firewall
If you have a UFW firewall installed on Ubuntu, use these commands to open TCP ports: 10050 (agent), 10051 (server), and 80 (frontend):
ufw allow 10050/tcp
ufw allow 10051/tcp
ufw allow 80/tcp
ufw reload
Step 4: Start Zabbix server and agent processes
sudo systemctl restart zabbix-server zabbix-agent
sudo systemctl enable zabbix-server zabbix-agent
Step 5: Configure Zabbix frontend
a. Configure PHP for Zabbix frontend
Edit file /etc/zabbix/apache.conf:
sudo nano /etc/zabbix/apache.conf
Uncomment 2 lines in apache.conf that starts with “# php_value date.timezone Europe/Riga” by removing symbol # and set the right timezone for your country, for example:
php_value date.timezone Europe/London
Save and exit file (ctrl+x, followed by y and enter)
b. Restart Apache web server and make it start at system boot
sudo systemctl restart apache2
sudo systemctl enable apache2
c. Configure web frontend
Connect to your newly installed Zabbix frontend using URL “http://server_ip_or_dns_name/zabbix” to initiate the Zabbix installation wizard.
In my case, that URL would be “http://192.168.1.161/zabbix” because I have installed Zabbix on the server with IP address 192.168.1.161 (you can find the IP address of your server by typing “ip a” command in the terminal).
Basically, in this wizard you only need to enter a password for Zabbix DB user and just click “Next step” for everything else. In this guide, I have used a zabbixDBpass as a database password, but if you set something else, be sure to enter the correct password when prompted by the wizard.
1. Installation step: Welcome screen
2. Installation step: Pre-requisites check
3. Installation step: Configure DB connection
4. Installation step: Configure Zabbix server
5. Installation step: Pre-installation summary
6. Installation step: Finish
That’s it, you have installed Zabbix monitoring system!
Step 6: Login to frontend using Zabbix default login credentials
Use Zabbix default admin username “Admin” and password “zabbix” (without quotes) to login to Zabbix frontend at URL “http://server_ip_or_dns_name/zabbix” via your browser.
In my example, I have installed Zabbix on server 192.168.1.161 so I will enter in my browsers URL field http://192.168.1.161/zabbix (you can find the IP address of your server by typing “ip a” command in the terminal)
Zabbix 5.0 dashboard
Step 7: Optimizing Zabbix Server (optional)
Don’t bother with this optimization if you are monitoring a small number of devices, but if you are planning to monitor a large number of devices then continue with this step.
Open “zabbix_server.conf
” file with command: “sudo nano /etc/zabbix/zabbix_server.conf
” and add this configuration anywhere in file:
StartPollers=100 StartPollersUnreachable=50 StartPingers=50 StartTrappers=10 StartDiscoverers=15 StartPreprocessors=15 StartHTTPPollers=5 StartAlerters=5 StartTimers=2 StartEscalators=2 CacheSize=128M HistoryCacheSize=64M HistoryIndexCacheSize=32M TrendCacheSize=32M ValueCacheSize=256M
Save and exit file (ctrl+x, followed by y and enter).
This is not a perfect configuration, keep in mind that you can optimize it even more. Let’s say if you don’t use ICMP checks then set the “StartPingers
” parameter to 1 or if you don’t use active agents then set “StartTrappers
” to 1 and so on. You can find out more about the parameters supported in a Zabbix server configuration file in the official documentation.
If you try to start the Zabbix server you will receive an error “[Z3001] connection to database 'Zabbix' failed: [1040] Too many connections
” in the log “/var/log/zabbix/zabbix_server.log
” because we are using more Zabbix server processes than MySQL can handle. We need to increase the maximum permitted number of simultaneous client connections and optimize MySQL – so move to the next step.
Step 8: Optimizing MySQL / MariaDB database (optional)
a. Create custom MySQL configuration file
Create file “10_my_tweaks.cnf” with “/etc/mysql/mariadb.conf.d/10_my_tweaks.cnf” and paste this configuration:
[mysqld]
max_connections = 404
innodb_buffer_pool_size = 800M
innodb-log-file-size = 128M
innodb-log-buffer-size = 128M
innodb-file-per-table = 1
innodb_buffer_pool_instances = 8
innodb_old_blocks_time = 1000
innodb_stats_on_metadata = off
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-flush-log-at-trx-commit = 2
tmp-table-size = 96M
max-heap-table-size = 96M
open_files_limit = 65535
max_connect_errors = 1000000
connect_timeout = 60
wait_timeout = 28800
Save and exit the file (ctrl+x, followed by y and enter) and set the correct file permission:
sudo chown mysql:mysql /etc/mysql/mariadb.conf.d/10_my_tweaks.cnf
sudo chmod 644 /etc/mysql/mariadb.conf.d/10_my_tweaks.cnf
Some things to remember!
Configuration parameter max_connections must be larger than the total number of all Zabbix proxy processes plus 150. You can use the command below to automatically check the number of Zabbix processes and add 150 to that number:
root@ubuntu:~ $ egrep "^Start.+=[0-9]" /etc/zabbix/zabbix_server.conf | awk -F "=" '{s+=$2} END {print s+150}'
The second most important parameter is innodb_buffer_pool_size, which determines how much memory can MySQL get for caching InnoDB tables and index data. You should set that parameter to 70% of system memory if only database is installed on server.
However, in this case, we are sharing a server with Zabbix and Apache processes so you should set innodb_buffer_pool_size to 40% of total system memory. That would be 800 MB because my Ubuntu server has 2 GB RAM.
I didn’t have any problems with memory, but if your Zabbix proxy crashes because of lack of memory, reduce “innodb_buffer_pool_size” and restart MySQL server.
Leave a Reply