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:
dev-db/mysql latin1 -ssl
emerge –config =dev-db/mysql-5.6.26
/etc/init.d/mysql start
mysql_secure_installation
rc-update add mysql default
Now we proceed with the zabbix server:
net-analyzer/zabbix agent -curl frontend -ipv6 -java -ldap libxml2 mysql -odbc -openipmi -oracle -postgres -proxy server -snmp -sqlite -ssh -static -xmpp
We create the database:
mysql> CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
mysql> USE mysql;
mysql> GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@localhost IDENTIFIED by 'PASSWORD';
mysql> FLUSH PRIVILEGES;
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:
cp /usr/bin/php-fpm /var/www/cgi-bin/zabbix/
chown -R zabbix:zabbix /var/www/cgi-bin/zabbix/
vi /etc/conf.d/apache2
APACHE2_OPTS="-D INFO -D SSL -D LANGUAGE -D FASTCGI"
<VirtualHost *:80>
ServerAdmin kr0m@alfaexploit.com
DocumentRoot /var/www/zabbix
ServerName zabbix.alfaexploit.com
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>
<Directory "/var/www/zabbix">
options -Indexes FollowSymLinks
AllowOverride All
order allow,deny
Allow from all
</Directory>
# Monitoring status:
<LocationMatch "/(ping|status)">
SetHandler php-fastcgi-virt
Action php-fastcgi-virt /local-bin/php-fpm virtual
</LocationMatch>
</VirtualHost>
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:
[zabbix]
user = zabbix
group = zabbix
listen = /var/run/php-fpm_zabbix.sock
listen.owner = apache
listen.group = 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:
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:
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=******
ListenIP=0.0.0.0
We start the services:
/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:
http://zabbix.alfaexploit.com
Assistant
We access zabbix and change the password and the theme (optional):
Admin
zabbix
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:
net-analyzer/zabbix agent -curl -frontend -ipv6 -java -ldap -libxml2 -mysql -odbc -openipmi -oracle -postgres -proxy -server -snmp -sqlite -ssh -static -xmpp
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.