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:
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 :)
InordertologintoMariaDBtosecureit,we'll need the current
password for the root user. If you'vejustinstalledMariaDB,and
youhaven'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
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
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
Remove anonymous users? [Y/n] y
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
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...
- Removing privileges on test database...
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
All done! If you'vecompletedalloftheabovesteps,yourMariaDB
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.
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/. (If you would install the packages from the standard repositories, the schema can be found in /usr/share/zabbix-mysql/.)
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 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:
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:
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:
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.
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:
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 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.
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:
The Zabbix-agent is part of the base repositories of almost all standard Linux distributions so the easiest is to install it from here:
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:
You can simply extract the archive and edit the following line in the file zabbix_agentd.win.conf:
Replace it with the hostname or IP of your Zabbix server.
After changing zabbix_agentd.win.conf, run the install-agent.bat. It creates a service for the Zabbix agent and starts it.
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:
Create the snmpd.conf file in /etc/snmpd/snmpd.conf: