This page looks best with JavaScript enabled

Zabbix Installation on Gentoo

 ·  🎃 kr0m

Zabbix is a very complete monitoring system, it allows us to collect statistics as well as configure alarms based on the collected data, the alarms can be notified in various ways, email, jabber or through any script opening up endless possibilities.

Zabbix is composed of several elements:

  • ZBX Server: Central server where statistics are queried and alarms are triggered.
  • ZBX DB: Database server where the information collected by the zbx-agents is stored.
  • ZBX Agents: Agents installed on each of the servers we want to monitor.
  • ZBX Proxy: Intermediate server to which the agents send data, thus zbx works better in a network with cuts, environments limited by FWs, etc.

In this guide, we will only install the zabbix server with the database and the agent.

We start with the installation of the database:

vi /etc/portage/package.use/mysql

dev-db/mysql latin1 -ssl
emerge -av dev-db/mysql
emerge –config =dev-db/mysql-5.6.26
/etc/init.d/mysql start
rc-update add mysql default

Now we proceed with the zabbix server:

vi /etc/portage/package.use/zabbix

net-analyzer/zabbix agent -curl frontend -ipv6 -java -ldap libxml2 mysql -odbc -openipmi -oracle -postgres -proxy server -snmp -sqlite -ssh -static -xmpp
emerge -av net-analyzer/zabbix

We create the database:

mysql -u root -p

mysql> USE mysql;
mysql> GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@localhost IDENTIFIED by 'PASSWORD';
mysql> USE zabbix;

We load the necessary tables with their structure:

mysql> SOURCE /usr/share/zabbix/database/mysql/schema.sql
mysql> SOURCE /usr/share/zabbix/database/mysql/data.sql
mysql> SOURCE /usr/share/zabbix/database/mysql/images.sql

We configure the vhost to use fast-cgi:

mkdir -p /var/www/cgi-bin/zabbix
cp /usr/bin/php-fpm /var/www/cgi-bin/zabbix/
chown -R zabbix:zabbix /var/www/cgi-bin/zabbix/
vi /etc/conf.d/apache2

vi /etc/apache2/vhosts.d/01_zabbix.conf
<VirtualHost *:80>
        DocumentRoot /var/www/zabbix
        ErrorLog /var/log/apache2/zabbix.alfaexploit.error_log
        CustomLog /var/log/apache2/zabbix.alfaexploit.access_log combined
        DirectoryIndex index.php index.htm index.html
        ScriptAlias /local-bin /var/www/cgi-bin/zabbix
        AddHandler application/x-httpd-php5 php
        Action application/x-httpd-php5 /local-bin/php-fpm
        FastCgiExternalServer /var/www/cgi-bin/zabbix/php-fpm -socket /var/run/php-fpm_zabbix.sock

        <Directory "/var/www/cgi-bin/zabbix">
            Options -Indexes ExecCGI
            Order allow,deny
            Allow from all

        <Directory "/var/www/zabbix">
            options -Indexes FollowSymLinks
            AllowOverride All
            order allow,deny
            Allow from all

        # Monitoring status:
        <LocationMatch "/(ping|status)">
            SetHandler php-fastcgi-virt
            Action php-fastcgi-virt /local-bin/php-fpm virtual
/etc/init.d/apache2 start
rc-update add apache2 default
cd /var/www/
ln -s /usr/share/webapps/zabbix/2.2.5/htdocs/ zabbix
chown -R zabbix:zabbix /var/www/zabbix
chown -R zabbix:zabbix /usr/share/webapps/zabbix/2.2.5/htdocs/

We configure the fast-cgi pool for the zabbix vhost:

vi /etc/php/fpm-php5.6/pool.d/zabbix.conf

user = zabbix
group = zabbix
listen = /var/run/php-fpm_zabbix.sock
listen.owner = apache = apache
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /status
ping.path = /ping
ping.response = pong
php_admin_value[post_max_size] = 16M
php_admin_value[max_execution_time] = 300
php_admin_value[max_input_time] = 300
php_admin_value[date.timezone] = Europe/Madrid
php_admin_value[always_populate_raw_post_data] = -1
php_admin_value[date.timezone] = Europe/Madrid

We register the services:

vi /etc/services

zabbix-agent       10050/tcp       Zabbix Agent
zabbix-agent       10050/udp       Zabbix Agent
zabbix-trapper     10051/tcp       Zabbix Trapper
zabbix-trapper     10051/udp       Zabbix Trapper

We configure the connection parameters with the database:

vi /etc/zabbix/zabbix_server.conf


We start the services:

/etc/init.d/zabbix-server start
/etc/init.d/zabbix-agentd start
rc-update add zabbix-server default
rc-update add zabbix-agentd default

We access the web interface where an installer will appear:


We access zabbix and change the password and the theme (optional):


Profile -> Change password
Theme -> Dark Orange
Media -> Email

We configure the email parameters so that basic notifications work:

Administration -> Media types -> Email
SMTP server
SMTP helo
SMTP email

We make sure we monitor the zbx server itself:

Configuration -> Hosts -> Zabbix server -> Status must be: Monitored

We wait a few seconds and CPU graphs should appear:

Monitoring -> Graphs

If we wait 30 minutes, it will discover the network interfaces and start drawing traffic graphs.

In the servers to be monitored, we compile zabbix with the agent use flag:

vi /etc/portage/package.use/zabbix

net-analyzer/zabbix agent -curl -frontend -ipv6 -java -ldap -libxml2 -mysql -odbc -openipmi -oracle -postgres -proxy -server -snmp -sqlite -ssh -static -xmpp
emerge -av net-analyzer/zabbix

As a final note, here are some recommendations:

  • MySQL: It is recommended to use partitioning and delete old data through crons. This will help us not to consume disk space with obsolete data and we will obtain better performance since the tables are smaller.
  • ZBX-Proxy: Proxies are usually devices with limited resources since they do not need them. In case the number of servers in a specific location grows, it is preferable to set up a second proxy instead of increasing the resources of the existing one.
If you liked the article, you can treat me to a RedBull here