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 customisation. 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).
This post has been completely reviewed and updated where needed on 08/2017 to make sure everything is still working and is correct.
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:
[jensd@zab ~]$ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm warning: /var/tmp/rpm-tmp.hhZ7PB: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Preparing... ################################# [100%] Updating / installing... 1:zabbix-release-3.2-1.el7 ################################# [100%]
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:
[jensd@zab ~]$ sudo yum install yum-utils -y ... Complete! [jensd@zab ~]$ repoquery -qi zabbix-server-mysql Name : zabbix-server-mysql Version : 3.2.7 Release : 1.el7 Architecture: x86_64 Size : 4180813 Packager : None Group : Applications/Internet URL : http://www.zabbix.com/ Repository : Zabbix Summary : Zabbix server for MySQL or MariaDB database Source : zabbix-3.2.7-1.el7.src.rpm Description : Zabbix server with MySQL or MariaDB database support.
As you can see, the packages for Zabbix are for version 3.2.7 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:
[jensd@zab ~]$ sudo yum install epel-release -y ... Complete !
Now that we are sure that Yum has access to the correct packages, let’s install what is necessary:
[jensd@zab ~]$ sudo yum -y install zabbix-server-mysql zabbix-agent zabbix-web-mysql mysql mariadb-server httpd php ... Complete !
Configure the database
After installing the packages, we need to initialise 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 :)
[jensd@zab ~]$ sudo systemctl start mariadb [jesnd@zab ~]$ mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Now that MariaDB is running and initialised, 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.
[jensd@zab ~]$ mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database zabbix; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'secretpassword'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye
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-<version>/create.sql.gz. (If you would install the packages from the standard repositories, the schema can be found in /usr/share/zabbix-mysql/.)
[jensd@zab ~]$ zcat /usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz | mysql -u zabbix -p zabbix Enter password:
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 optimise the database system. To do so, I recommend using Zabbix for a while and then use https://github.com/major/MySQLTuner-perl 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:
[jensd@zab ~]$ sudo sed -i 's/^max_execution_time.*/max_execution_time=600/' /etc/php.ini [jensd@zab ~]$ sudo sed -i 's/^max_input_time.*/max_input_time=600/' /etc/php.ini [jensd@zab ~]$ sudo sed -i 's/^memory_limit.*/memory_limit=256M/' /etc/php.ini [jensd@zab ~]$ sudo sed -i 's/^post_max_size.*/post_max_size=32M/' /etc/php.ini [jensd@zab ~]$ sudo sed -i 's/^upload_max_filesize.*/upload_max_filesize=16M/' /etc/php.ini [jensd@zab ~]$ sudo sed -i "s/^\;date.timezone.*/date.timezone=\'Europe\/Brussels\'/" /etc/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> <Directory "/usr/share/zabbix/conf"> Require all denied </Directory> <Directory "/usr/share/zabbix/include"> Require all denied </Directory>
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:
[jensd@zab ~]$ sudo sed -i 's/^# DBPassword=.*/DBPassword=secretpassword/' /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:
[jensd@zab ~]$ sudo sed -i 's/^# CacheSize=.*/CacheSize=32M/' /etc/zabbix/zabbix_server.conf [jensd@zab ~]$ sudo sed -i 's/^# StartPingers=.*/StartPingers=5/' /etc/zabbix/zabbix_server.conf
Before we can really use Zabbix, we need to open up the firewall to allow access to the Apache webserver and the webinterface of Zabbix. I’m assuming that outgoing traffic is allowed, otherwise you also need to open up UDP 161 for SNMP and TCP 10050 for the Zabbix agent.
[jensd@zab ~]$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent success [jensd@zab ~]$ sudo firewall-cmd --reload success
[jensd@zab ~]$ sudo iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
When using SELinux, we need to allow Apache to communicate with Zabbix:
[jensd@zab ~]$ sudo setsebool -P httpd_can_connect_zabbix=1
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 the services:
[jensd@zab ~]$ sudo systemctl start zabbix-agent [jensd@zab ~]$ sudo systemctl start zabbix-server [jensd@zab ~]$ sudo systemctl start httpd
At the time of writing, there was an issue with starting the Zabbix components in combination with SELinux on CentOS 7. This is being fixed but if you experience the following error:
[jensd@zab ~]$ tail -3 /var/log/zabbix/zabbix_agentd.log 3381:20170801:132248.952 using configuration file: /etc/zabbix/zabbix_agentd.conf 3381:20170801:132248.952 cannot set resource limit:  Permission denied 3381:20170801:132248.952 cannot disable core dump, exiting... [jensd@zab ~]$ tail -3 /var/log/zabbix/zabbix_server.log 3717:20170801:132744.710 using configuration file: /etc/zabbix/zabbix_server.conf 3717:20170801:132744.710 cannot set resource limit:  Permission denied 3717:20170801:132744.710 cannot disable core dump, exiting..
The fix is as follows (more information on: https://support.zabbix.com/browse/ZBX-10542):
[jensd@zab ~]$ sudo yum install -y policycoreutils-python ... Complete! [jensd@zab ~]$ sudo cat /var/log/audit/audit.log | grep zabbix_agentd | grep denied | tail -1 | audit2allow -M zabbix_agent_resourcelimit ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i zabbix_agent_resourcelimit.pp [jensd@zab ~]$ sudo semodule -i zabbix_agent_resourcelimit.pp [jensd@zab ~]$ sudo systemctl start zabbix-agent [jensd@zab ~]$ sudo cat /var/log/audit/audit.log | grep zabbix_server | grep denied | tail -1 | audit2allow -M zabbix_server_resourcelimit ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i zabbix_server_resourcelimit.pp [jensd@zab ~]$ sudo semodule -i zabbix_server_resourcelimit.pp [jensd@zab ~]$ sudo systemctl start zabbix-server
After starting the services, browse to the following URL: http://<ip or hostname>/zabbix (for example: http://192.168.202.101/zabbix). If all goes well, you should see something like this:
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 secretpassword):
Continue to the next step and provide the desired hostname and instance name:
Go through the pre-installation summary and click next to end 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.
Basic actions for hosts to monitor:
Now that we have our Zabbix server up and running, we need to have something to monitor. For several types of hosts, there is an agent available. The agent is listening for requests on TCP port 10050 so make sure that this port is open from the Zabbix server to the host to monitor
Install the Zabbix agent on Linux:
Unfortunately, the Zabbix-agent that is part of the base repositories is quite old (version 2.2) and you need to add the Zabbix repositories to the hosts where you would like to install the Zabbix agent.
First add the repositories:
[jensd@node ~]$ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm warning: /var/tmp/rpm-tmp.hhZ7PB: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Preparing... ################################# [100%] Updating / installing... 1:zabbix-release-3.2-1.el7 ################################# [100%]
Next, install the agent:
[jensd@node ~]$ sudo yum install zabbix-agent -y ... Complete!
After the installation, set the hostname of the Zabbix-server in /etc/zabbix/zabbix_agentd.conf to match your configuration. Replace 192.168.202.101 by the IP or hostname of your Zabbix-server:
[jensd@node ~]$ sudo sed -i 's/^Server=127.0.0.1/Server=192.168.202.101/g' /etc/zabbix/zabbix_agentd.conf
To disable the active checks, clear the value of the ServerActive parameter:
[jensd@node01 ~]$ sudo sed -i 's/^ServerActive=127.0.0.1/ServerActive=/g' /etc/zabbix/zabbix_agentd.conf
Enable the service and make it persistent:
[jensd@node01 ~]$ sudo systemctl start zabbix-agent [jensd@node01 ~]$ sudo systemctl enable zabbix-agent ln -s '/usr/lib/systemd/system/zabbix-agent.service' '/etc/systemd/system/multi-user.target.wants/zabbix-agent.service'
In case you’re having issues starting the Zabbix agent service, related to permissions for setting the resource limits, please refer to the provide fix above in the installation section for the Zabbix server (last part).
Install the Zabbix agent on Windows
To install the Zabbix agent on a Windows machine, you can find pre-compiled agents for most of the (popular) platforms on the Zabbix website: https://www.zabbix.com/download
The Zabbix 3.2 agent for Windows can be downloaded here: https://www.zabbix.com/downloads/3.2.0/zabbix_agents_3.2.0.win.zip
You can simply extract the archive and edit the following line in the file conf/zabbix_agentd.win.conf:
Replace it with the hostname or IP of your Zabbix server.
After changing zabbix_agentd.win.conf, you can run the following commands (or use them to create a batch file) to install the Zabbix agent as a service:
C:\zabbix_agents_3.2.0.win>cd bin\win64 C:\zabbix_agents_3.2.0.win\bin\win64>zabbix_agentd.e xe --config ../../conf/zabbix_agentd.win.conf --install zabbix_agentd.exe : service [Zabbix Agent] installed successfully zabbix_agentd.exe : event source [Zabbix Agent] installed successfully C:\zabbix_agents_3.2.0.win\bin\win64>net start "Zabb ix Agent" The Zabbix Agent service is starting. The Zabbix Agent service was started successfully.
Enable snmp on Linux
Besides using the Zabbix agent, you can also monitor hosts using SNMP. SNMP isn’t always as fast and flexible as the agent but does the job. Also SNMP can be used for devices that can’t have an agent installed (like a switch):
Install the net-snmp package:
[jensd@node ~]$ sudo yum install net-snmp ... Complete !
Create the snmpd.conf file in /etc/snmpd/snmpd.conf:
com2senm snmpuser default public group snmpgroup v1 snmpuser group snmpgroup v2c snmpuser view roview included .1 view roview included system.sysContact view roview included system.sysName view roview included system.sysLocation view roview included interfaces.ifTable.ifEntry.ifAdminStatus view roview included at.atTable.atEntry.atPhysAddress view roview included at.atTable.atEntry.atNetAddress view roview included ip.ipForwarding view roview included ip.ipDefaultTTL view roview included ip.ipRouteTable.ipRouteEntry.ipRouteDest view roview included ip.ipRouteTable.ipRouteEntry.ipRouteIfIndex view roview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric1 view roview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric2 view roview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric3 view roview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric4 view roview included ip.ipRouteTable.ipRouteEntry.ipRouteType view roview included ip.ipRouteTable.ipRouteEntry.ipRouteAge view roview included ip.ipRouteTable.ipRouteEntry.ipRouteMask view roview included ip.ipRouteTable.ipRouteEntry.ipRouteMetric5 view roview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaIfIndex view roview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress view roview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaNetAddress view roview included ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType view roview included tcp.tcpConnTable.tcpConnEntry.tcpConnState view roview included egp.egpNeighTable.egpNeighEntry.egpNeighEventTrigger view roview included snmp.snmpEnableAuthenTraps access snmpgroup "" any noauth exact roview none none syslocation Datacenter (edit /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) dontLogTCPWrappersConnects yes includeAllDisks 10%
The community string is set as public in the above file, change it to something else if you prefer to.
After configuring, start and enable the service:
[jensd@node ~]$ sudo systemctl start snmpd [jensd@node ~]$ sudo systemctl enable snmpd
Add a host in Zabbix
After installing SNMP or a Zabbix agent on your systems, you can add them in Zabbix as follows:
Log on to the web interface by browsing to http://<ip or hostname>/zabbix (for example: http://192.168.202.101/zabbix) and log in.
Go to Configuration – Hosts and click on “Create host”:
In the next screen, enter a host name, add the host to a group by selecting it on the right side and clicking <<.
When the host has the agent installed, enter the DNS-name or IP for the host in the Agent interfaces. For SNMP, remove the Agent interface and add an SNMP interface containing the same information.
On the templates tab, add ICMP ping and a template that matches the host (for example “Template OS Linux” for a Linux host with a Zabbix agent or “Template SNMP OS Linux” for a Linux host with SNMP).
When using SNMP, you need to enter the community string which you have chose (public in my example above) on the Macros tab:
Finally click Add and the host should be monitored. Don’t panic if you don’t see information immediately give Zabbix some time to discover all items that are relevant for the host.
This should be all it takes to get started with Zabbix. Take some time to explore Zabbix’ functionality and experiment to discover all features.