The Eye of Sauron

Monitor Your Network with Zabbix

© gleolite, 123RF.com

© gleolite, 123RF.com

Author(s):

Use Zabbix to keep tabs on all your machines across the network.

Special Thanks: This article was made possible by support from Linux Professional Institute

Zabbix is a network monitoring application that lets you stay on top of all your network activities. The app is very scalable and can work on networks of any size, from a home network with a couple of computers to an enterprise with dozens. It’s cross-platform and will keep track of machines running Linux, Windows, or Mac OS X. You can use it to keep a close eye on every aspect of these machines. You can ask Zabbix to report on several aspects including free disk space, CPU load, network traffic statistics, memory consumption, application status, and much more.

Zabbix keeps all the collected information in databases, such as MySQL, although you can also plug it into PostgreSQL and SQLite databases as well. Zabbix is very adept at sending out alerts and creating graphs. It can send out alerts via the Jabber/XMPP instant messaging protocol or email. Unlike other monitoring apps, Zabbix also lets you set up actions on remote machines that are triggered automatically on predefined events. Zabbix also excels at visualizing your network. It can generate real-time graphing of monitored events and offers graphs, network maps, screens, and even slideshows, making it suitable for complex networks, whose sys admins prefer to see graphical data representations.

Zabbix Components

A monitoring app primarily performs two functions: It collects data on all of the network's devices and reports the data to a central controlling authority. Zabbix relies on two key components for these functions: zabbix-server and zabbix-agent.

As the name suggests, you install zabbix-agent onto all the machines you wish to monitor on the network. The agent can monitor hardware resources, as well as applications, and pushes all the collected information to zabbix-server. The zabbix-agent is available for Linux, FreeBSD, OpenBSD, NetBSD, HP-UX, Mac OS X, Solaris, and various Windows versions. The other component, zabbix-server, is responsible for polling and trapping data. In case of problems or downtime, the server sends notifications to the configured accounts. You only need to install one instance of zabbix-server on your network.

In addition to zabbix-agent, Zabbix can also monitor devices via the SNMP protocol. While zabbix-agent can monitor physical and virtual machines, you can use SNMP to monitor network devices like routers and switches, as well as servers as long as you’ve configured them to respond to SNMP events.

With Zabbix, you get a centralized web interface that you can use to control the events that are monitored across the network. Due to its vast number of features, the interface may at times seem too complex and cumbersome to many first time users. However, the app is well-documented and intuitive to operate, and the interface will grow on you over time.

Prepare the Base

There are two ways to install Zabbix. You can compile and install Zabbix from source, or you can install Zabbix packages if your distribution supports them. Installing the packages is faster and makes things easier to maintain, while installing from source takes longer but optimizes the app for your server. In this tutorial, I’ll use precompiled binaries from the official Zabbix repository. Although I prefer to deploy server software atop CentOS, I’m setting up Zabbix on top of Ubuntu 18.04 LTS because of dependency issues in CentOS 7.

Use the following commands to add and install the Zabbix repository:

$ wget https://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/
  zabbix-release/zabbix-release_4.2-1+bionic_all.deb
$ sudo dpkg -i zabbix-release_4.2-1+bionic_all.deb
$ sudo apt update

Once the repository has been installed, use it to install Zabbix server with the MariaDB database, along with the Zabbix front end:

$ sudo apt install zabbix-server-mysql
$ sudo apt install zabbix-frontend-php

Before proceeding any further, I’ll set a password for the root user of the MariaDB server using a script that will also run through some common security configuration options:

$ sudo mysql_secure_installation

Now use the newly defined credentials for the database server to create a database for Zabbix:

$ sudo mysql -uroot -p

From inside the MariaDB monitor, create the database for Zabbix:

MariaDB> create database zabbix character set utf8 collate utf8_bin;

Create a new database user called zabbix to access the new zabbix database:

MariaDB> grant all privileges on zabbix.* to zabbix@localhost identified
  by 'Password';
MariaDB> flush privileges;
MariaDB> quit

Remember to replace 'Password' with the credentials you wish to use for the zabbix user.

The Zabbix installation ships with the schema for the initial database that you can import into the newly created zabbix database with a single command:

$ sudo zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz |
  mysql -uzabbix -p zabbix

Once the command has completed and populated the database, it’s time to point the Zabbix server to the database:

$ sudo nano /etc/zabbix/zabbix_server.conf

Scroll down the file and make sure the server has the correct authentication information for the zabbix database by editing the following parameters:

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<password>

One of the advantages of using the Zabbix binaries is that they automatically install the Apache web server and also create a virtual host file for Zabbix. You will however need to tweak the virtual host file to update some settings:

$ sudo nano /etc/apache2/conf-enabled/zabbix.conf

Since we are using PHP 7, scroll down to the <IfModule mod_php7.c> section and change the following parameters to the values mentioned below:

php_value max_execution_time 600
php_value memory_limit 128M
php_value post_max_size 32M
php_value upload_max_filesize 16M
php_value max_input_time 600
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Europe/Berlin

Substitute the time zone with the one for your location using the values from the PHP documentation. When you are done, restart the Apache web server before starting the Zabbix server:

$ sudo systemctl restart apache2.service
$ sudo systemctl start zabbix-server.service
$ sudo systemctl enable zabbix-server.service

The last command will make the Zabbix server automatically start at boot.

Configure the Installation

Now that the Zabbix server is up and running, we’ll switch to the browser-based front end. Fire up a web browser and head to http://localhost/zabbix to bring up the front end. Replace localhost with the Zabbix server's IP address in case you are accessing it from another computer on the network. Since this is the first time you are accessing the interface, it will guide you through a short setup wizard. The process will check your PHP configuration (Figure 1). You’ll also be prompted for the details of the zabbix database. Before the front end establishes the connection to the Zabbix server and the database server, it will allow you to review the settings (Figure 2).

Figure 1: The screen displays the current values in the file along with the required minimums.
Figure 2: Review all settings and use the Back button to make any changes before proceeding further.

Once the front end has been configured and can connect to the Zabbix server and the database, it will automatically take you to the login screen. You can log in using the default credentials for the Zabbix Super Admin with Admin as the username and zabbix as the password.

The first order of business is to create a user to delegate some administrative control. Head to Administration | Users and click the Create user button in the top right-corner of the interface. In addition to the required details, make sure the user is added to one of the existing user groups, for example Zabbix administrators (Figure 3).

Figure 3: User groups help assign access permissions. Head to Administration | User groups to add custom user groups.

Before you add the user, you should also assign a notification delivery method to the user. Switch to the Media tab and click the Add button. Use the Type pull-down menu to select the notification method you want to use. I prefer the default option, which is email. Now enter the user's email address and click the Add button to save the settings and create the new user (Figure 4).

Figure 4: You can select multiple media types and specify a time for when they’ll be active.

Next up, you’ll need to define the host access permissions for this user. For this, click the user's group of in the Groups column, which is Zabbix administrators for the user we just created, and switch to the Permissions tab. Here, click the Select button and then select the groups from the pop-up list of groups. Click the Read button to give this user read-only permission to the selected groups. Save the settings for the new user by clicking the Update button in the user group properties screen.

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Hyperic HQ

    Monitor a Java application server with Hyperic HQ.

  • Tutorials – Intrusion Protection

    No computer security is perfect, so make sure you've got a second line of protection.

  • News

    Fedora Project announces Fedora 30; the Apache Software Foundation completes migration to GitHub; Canonical combines its services in a single package; Black Hole Image has an open source connection; Ubuntu 19.04 released; Linux Mint founder calls for better developer support; and VMware patches critical vulnerabilities.

  • Security Lessons

    Learn how to monitor and block attacks without lifting a finger.

  • Cfengine 3

    Automate admin tasks with the powerful Cfengine framework.

comments powered by Disqus

Direct Download

Read full article as PDF:

News