Zabbix

How to self host Zabbix, an Enterprise-class open source network monitoring solution



zabbix.gif


Install packages

pacman -Syu zabbix-server zabbix-frontend-php mariadb apache php php-fpm php-apache php-gd fping traceroute

Install MariaDB/MySQL system tables

mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
systemctl enable mariadb
systemctl start mariadb

Improve initial security with recommended security measures, such as removing anonymous accounts and removing the test database.

mysql_secure_installation

When prompted to “Switch to unix_socket authentication” enter n for No.

Listen only on the loopback address

/etc/my.cnf.d/server.cnf
[mysqld]
bind-address = localhost
systemctl restart mariadb

Database Initialization

mysql -v -u root -p -e "create database zabbix character set utf8 collate utf8_bin"
mysql -v -u root -p -e "grant all on zabbix.* to zabbix@localhost identified by 'MYPASSWORD'"
mysql -v -u zabbix -p -D zabbix < /usr/share/zabbix-server/mysql/schema.sql
mysql -v -u zabbix -p -D zabbix < /usr/share/zabbix-server/mysql/images.sql
mysql -v -u zabbix -p -D zabbix < /usr/share/zabbix-server/mysql/data.sql

Database Configuration

/etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=MYPASSWORD
LogType=system

Setup Apache HTTP Server

Enable proxy modules

/etc/httpd/conf/httpd.conf

uncomment LoadModule proxy_module modules/mod_proxy.so
uncomment LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
comment # LoadModule mpm_event_module modules/mod_mpm_event.so
uncomment LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

At the end of the LoadModule list
add LoadModule php_module modules/libphp.so
add AddHandler php-script .php

At the end of the Include list
add Include conf/extra/php_module.conf
add Include conf/extra/php-fpm.conf

/etc/httpd/conf/extra/php-fpm.conf
DirectoryIndex index.php index.html
<FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>

Symlink the Zabbix web application directory to your http document root

ln -s /usr/share/webapps/zabbix /srv/http/zabbix

Setup PHP

List available php modules

php -m
/etc/php/php.ini
date.timezone = Europe/Berlin
display_errors = On
open_basedir = /srv/http/:/var/www/:/home/:/tmp/:/var/tmp/:/var/cache/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/

post_max_size = 16M
max_execution_time = 300
max_input_time = 300

extension=bcmath
extension=curl
extension=gd
extension=gettext
extension=mysqli
extension=sockets
extension=zip

Enable and start services

systemctl enable php-fpm
systemctl enable httpd
systemctl enable zabbix-server-mysql

Access Zabbix via your local web server, http://localhost/zabbix/,
finish the installation wizard and access the frontend the first time.
The default username is Admin and password zabbix.


Fix “[ERROR] Incorrect definition of table mysql.column_stats: expected column ‘histogram’”

mysql_upgrade --user=root

Setup client machines

Install client

pacman -Syu zabbix-agent2

Configuration

/etc/zabbix/zabbix_agent2.conf

Replace the server variable with the IP of your monitoring server. Only servers from this/these IP will be allowed to access the agent.

Server=archlinux-zabbix
ServerActive=archlinux-zabbix
Hostname=HOSTNAME

Make sure the port 10050 on your device being monitored is not blocked and is properly forwarded.

comment out # Include=./zabbix_agent2.d/plugins.d/*.conf


Monitor Arch Linux clients for available system updates using a custom UserParameter

# Monitor Arch Linux system updates
Include=/etc/zabbix/zabbix_agent2.conf.d/*.conf
mkdir /etc/zabbix/zabbix_agent2.conf.d
/etc/zabbix/zabbix_agent2.conf.d/archlinuxupdates.conf
UserParameter=archlinuxupdates,checkupdates | wc -l
chown -R zabbix-agent:zabbix-agent /etc/zabbix/zabbix_agent2.conf.d
chmod 755 /etc/zabbix/zabbix_agent2.conf.d
chmod 644 /etc/zabbix/zabbix_agent2.conf.d/archlinuxupdates.conf

Monitor nVidia GPU

/etc/zabbix/zabbix_agent2.conf.d/nvidiagpu.conf
UserParameter=gpu.temp,nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits -i 0
UserParameter=gpu.memtotal,nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits -i 0
UserParameter=gpu.used,nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits -i 0
UserParameter=gpu.free,nvidia-smi --query-gpu=memory.free --format=csv,noheader,nounits -i 0
UserParameter=gpu.fanspeed,nvidia-smi --query-gpu=fan.speed --format=csv,noheader,nounits -i 0
UserParameter=gpu.utilisation,nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits -i 0
UserParameter=gpu.power,nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits -i 0
UserParameter=cpu.temp,sensors | grep "CPU Temperature" | awk '{print $ 3}' | cut -c 2-5
chown -R zabbix-agent:zabbix-agent /etc/zabbix/zabbix_agent2.conf.d

Enable and start the zabbix-agent service

systemctl enable zabbix-agent2
systemctl start zabbix-agent2
systemctl status zabbix-agent2