Zabbix on CentOS 7

Zabbix is a monitoring tool which is widely used in all kinds of environments. Zabbix is very flexible, information can be retrieved using HTTP/SNMP or by installing a Zabbix agent on the machines to monitor, and allows a lot of customization. Unfortunately this also means that the learning curve can be rather high. This post will go a little deeper into the installation process and the first steps in Zabbix.

Zabbix can be installed from most standard repositories in a variety of Linux distributions. For this post, I’m using CentOS 7 and I decided to use the official Zabbix repository to ensure that we’re using the latest version of Zabbix. Zabbix requires a database backend and for this post, I will use MariaDB (a fork of MySQL).

Add the Zabbix repository and install the packages

The first step is to enable the Zabbix official repository by creating a file in /etc/yum.repos.d:

 # vim /etc/yum.repos.d/zabbix.repo

Contents of the file:


The packages in the standard CentOS repositories have the version number in their name. (zabbix22 for version 2.2) so they will not conflict with the packages from the repository which we added.

To be sure, we can check if we really are installing the latest version:

# yum install yum-utils
Complete !
# repoquery -qi zabbix
Name        : zabbix
Version     : 2.4.3
Release     : 1.el7
Architecture: x86_64
Size        : 592701
Packager    : None
Group       : Applications/Internet
URL         :
Repository  : Zabbix
Summary     : Enterprise-class open source distributed monitoring solution.
Source      : zabbix-2.4.3-1.el7.src.rpm
Description :
Zabbix is software that monitors numerous parameters of a network and
the health and integrity of servers. Zabbix uses a flexible
notification mechanism that allows users to configure e-mail based
alerts for virtually any event.  This allows a fast reaction to server
problems. Zabbix offers excellent reporting and data visualisation
features based on the stored data. This makes Zabbix ideal for
capacity planning.

As you can see, package Zabbix is version 2.4.3 and it will be taken from the repository which we just added, named Zabbix.

Besides the Zabbix-repository, you will also need the EPEL repository for some dependencies. If you haven’t done so, add that repo too:

# yum -y install epel-release
# yum -y install zabbix-server-mysql zabbix-agent zabbix-web-mysql mysql mariadb-server httpd php

Configure the database

After installing the packages, we need to do initialize MariaDB and set the root password. Don’t get confused with all the references to MySQL in the commands below. MariaDB is a fork of MySQL and clearly branding wasn’t very high on the priority list 🙂

# systemctl start mariadb
# mysql_secure_installation

Now that MariaDB is running and initialized, we can add a database for Zabbix, named zabbix, and create a user that has access to that DB. Use the root-password which you changed in the previous step when asked for a password and replace secretpassword with your own password for the zabbix database user.

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix_pass';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit

Now that the database and user are ready, it’s time to create the database schema for Zabbix in the DB which we just added. The schema is delivered with Zabbix in /usr/share/doc/zabbix-server-mysql-/create/. (If you would install the packages from the standard repositories, the schema can be found in /usr/share/zabbix-mysql/.)

# mysql -u root -p zabbix </usr/share/doc/zabbix-server-mysql-2.4.3/create/schema.sql
Enter password:
# mysql -u root -p zabbix </usr/share/doc/zabbix-server-mysql-2.4.3/create/images.sql
Enter password:
# mysql -u root -p zabbix </usr/share/doc/zabbix-server-mysql-2.4.3/create/data.sql
Enter password:

Или в случае с Zabbix 2.5(3.0_rc1):

# mysql -u root -p zabbix < /usr/share/doc/zabbix-server-mysql/create.sql

Be aware that, for this post, I’m leaving the rest of the MariaDB configuration at it’s default. For a production environment you really need some tuning in MariaDB to optimize the database system. To do so, I recommend using Zabbix for a while and then use on a regular basis to tune the database parameters. This approach is very straightforward and delivers very good results with a minimal effort.

Configure the webserver

At this point, our database is ready so the next step is to configure the webserver (Apache) and PHP.

The default parameters of PHP need some tuning for Zabbix:

# sed -i 's/^max_execution_time.*/max_execution_time=600/' /etc/php.ini
# sed -i 's/^max_input_time.*/max_input_time=600/' /etc/php.ini
# sed -i 's/^memory_limit.*/memory_limit=256M/' /etc/php.ini
# sed -i 's/^post_max_size.*/post_max_size=32M/' /etc/php.ini
# sed -i 's/^upload_max_filesize.*/upload_max_filesize=16M/' /etc/php.ini
# sed -i "s/^\;date.timezone.*/date.timezone=\'Europe\/Moscow\'/" /etc/php.ini

Debian style:

# sed -i 's/^max_execution_time.*/max_execution_time=600/' /etc/php5/apache2/php.ini
# sed -i 's/^max_input_time.*/max_input_time=600/' /etc/php5/apache2/php.ini 
# sed -i 's/^memory_limit.*/memory_limit=256M/' /etc/php5/apache2/php.ini 
# sed -i 's/^post_max_size.*/post_max_size=32M/' /etc/php5/apache2/php.ini 
# sed -i 's/^upload_max_filesize.*/upload_max_filesize=16M/' /etc/php5/apache2/php.ini 
# sed -i "s/^\;date.timezone.*/date.timezone=\'Europe\/Moscow\'/" /etc/php5/apache2/php.ini

The above commands just replace lines in /etc/php.ini by a line with the correct value. You can also edit the file by hand if you would like to.

Next up is Apache. The Yum-installation, created a file for Apache in /etc/httpd/conf.d/zabbix.conf. Edit this file to look similar to this:

# Zabbix monitoring system php web frontend
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Require all granted
<Directory "/usr/share/zabbix/conf">
    Require all denied
<Directory "/usr/share/zabbix/include">
    Require all denied

Configure Zabbix parameters:

Next in the list, is the Zabbix configuration file for the server. It needs to know the password which we set for the zabbix database user earlier. Replace secretpassword with your own password which you set for the zabbix database user:

# sed -i 's/^# DBPassword=.*/DBPassword=zabbix_pass/' /etc/zabbix/zabbix_server.conf

In order to avoid some warnings like: “Less than 25% free in the configuration cache” or “Zabbix icmp pinger processes more than 75% busy”, set some more parameters in the file:

# sed -i 's/^# CacheSize=.*/CacheSize=32M/' /etc/zabbix/zabbix_server.conf
# sed -i 's/^# StartPingers=.*/StartPingers=5/' /etc/zabbix/zabbix_server.conf

Нужно грохнуть файрволл:

В 7-й версии CentOS для управления iptables разработан новый инструмент под названием firewalld и все управление производится через него. Я, честно говоря, толком не вник в суть этого инструмента и не могу сказать, удобнее с ним стало или нет. Я привык управлять iptables через самописный скрипт, который мигрирует от сервера к серверу и редактируется под конкретные потребности. Этим скриптом я и управляю доступом к серверу(но об этом отдельно). Так что для начала остановим и отключим firewalld:

# systemctl stop firewalld
# systemctl disable firewalld

И установим утилиты для iptables:

# yum install iptables-services

Включим автозапуск iptables:

# systemctl enable iptables

Создаем bash-script с правилами и помещаем его скажем в /etc/firewall/
Записываем правила:

# chmod 0740 /etc/firewall/
# /sbin/iptables-save  > /etc/sysconfig/iptables

При каждом запуске файла с правилами iptables, все изменения записываются в файл /etc/sysconfig/iptables и применяются при загрузке системы.

Start and initialize Zabbix

At this point, most of the configuration should be completed. The only thing that is left is to start the services related to Zabbix and finish the configuration by using the webinterface:

Start and enable the autostart the services:

# systemctl start zabbix-agent
# systemctl start zabbix-server
# systemctl start httpd

After starting the services, browse to the following URL: http://<ip or hostname>/zabbix (for example: Если все прошло успешно вы должны увидеть что то подобное:


Click next and check if everything is marked with OK:


In the next step, enter the details about the MariaDB user which we created (named zabbix and password secretpass):


Continue to step 6 and finish the installation:


After clicking finish, you should see the login screen to your new Zabbix installation:


The default username is admin and the default password for that user is zabbix.

At this point the Zabbix server is ready to use.