1. Monitor Linux with Zabbix agent
This page walks you through the steps required to start basic monitoring of Linux machines with Zabbix. The steps described in this tutorial can be applied to any Linux-based operating system.
Who this guide is for
This guide is designed for new Zabbix users and contains the minimum set of steps required to enable basic monitoring of your Windows machine. If you are looking for deep customization options or require more advanced configuration, see Configuration section of Zabbix manual.
Prerequisites
Before proceeding with this installation guide, you must download and install Zabbix server and Zabbix frontend according to instructions for your OS.
Install Zabbix agent
Zabbix agent is the process responsible for gathering data.
Check your Zabbix server version:
Install Zabbix agent of the same version (recommended) on the Linux machine that you want to monitor. Based on your monitoring needs, it may be the same machine, where Zabbix server is installed, or a completely different machine.
Choose the most suitable installation method:
Run as a Docker container — see the list of available images in Zabbix Docker repository.
Install from Zabbix packages (available for Alma Linux, CentOS, Debian, Oracle Linux, Raspberry Pi OS, RHEL, Rocky Linux, SUSE Linux Enterprise Server, Ubuntu).
Configure Zabbix for monitoring
Zabbix agent can collect metrics in active or passive mode (simultaneously).
A passive check is a simple data request. Zabbix server or proxy asks for some data (for example, CPU load) and Zabbix agent sends back the result to the server. Active checks require more complex processing. The agent must first retrieve from the server(s) a list of items for independent processing and then bulk send the data back. See Passive and active agent checks for more info.
Monitoring templates provided by Zabbix usually offer two alternatives — a template for Zabbix agent and a template for Zabbix agent (active). With the first option, the agent will collect metrics in passive mode. Such templates will deliver identical monitoring results, but using different communication protocols.
Further Zabbix configuration depends on whether you select a template for active or passive Zabbix agent checks.
Passive checks
Zabbix frontend
1. Log in to Zabbix frontend.
2. Create a host in Zabbix web interface.
This host will represent your Linux machine.
3. In the Interfaces parameter, add Agent interface and specify the IP address or DNS name of the Linux machine where the agent is installed.
4. In the Templates parameter, type or select Linux by Zabbix agent.
Zabbix agent
Open Zabbix agent configuration file (by default, the path is /usr/local/etc/zabbix_agentd.conf):
Add the IP address or DNS name of your Zabbix server to the Server parameter.
Active checks
Zabbix frontend
1. Log in to Zabbix frontend.
2. Create a host in Zabbix web interface.
This host will represent your Linux machine.
3. In the Templates parameter, type or select Linux by Zabbix agent active.
Zabbix agent
Open Zabbix agent configuration file (by default, the path is /usr/local/etc/zabbix_agentd.conf):
- The name of the host you created in Zabbix web interface to the Hostname parameter.
- The IP address or DNS name of your Zabbix server to the ServerActive parameter.
View collected metrics
Congratulations! At this point, Zabbix is already monitoring your Linux machine.
To view collected metrics, open the Monitoring->Hosts menu section and click on the Latest data next to the host.
This action will open a list of all the latest metrics collected from Linux server host.
Set up problem alerts
Zabbix can notify you about a problem with your infrastructure using a variety of methods. This guide provides configuration steps for sending email alerts.
1. Go to the User settings -> Profile, switch to the tab Media and add your email.
Next time, when Zabbix detects a problem you should receive an alert via email.
Test your configuration
On Linux, you can simulate high CPU load and as a result receive a problem alert by running:
You may need to run several md5sum processes for CPU load to exceed the threshold.
When Zabbix detects the problem, it will appear in the Monitoring->Problems section.
If the alerts are configured, you will also receive the problem notification.
2 Agent
Zabbix agent is deployed on a monitoring target to actively monitor local resources and applications (hard drives, memory, processor statistics, etc.).
The agent gathers operational information locally and reports data to Zabbix server for further processing. In case of failures (such as a hard disk running full or a crashed service process), Zabbix server can actively alert the administrators of the particular machine that reported the failure.
Zabbix agents are extremely efficient because of use of native system calls for gathering statistical information.
Passive and active checks
Zabbix agents can perform passive and active checks.
In a passive check the agent responds to a data request. Zabbix server (or proxy) asks for data, for example, CPU load, and Zabbix agent sends back the result.
Active checks require more complex processing. The agent must first retrieve a list of items from Zabbix server for independent processing. Then it will periodically send new values to the server.
Whether to perform passive or active checks is configured by selecting the respective monitoring item type. Zabbix agent processes items of type ‘Zabbix agent’ or ‘Zabbix agent (active)’.
Supported platforms
Zabbix agent is supported on the following platforms:
- Windows (all desktop and server versions since XP)
- Linux (also available in NetBSD and HP-UX, and those are compatible with current Zabbix server/proxy version.
Agent on UNIX-like systems
Zabbix agent on UNIX-like systems is run on the host being monitored.
Installation
See the package installation section for instructions on how to install Zabbix agent as package.
Alternatively see instructions for manual installation if you do not want to use packages.
In general, 32bit Zabbix agents will work on 64bit systems, but may fail in some cases.
If installed as package
Zabbix agent runs as a daemon process. The agent can be started by executing:
This will work on most of GNU/Linux systems. On other systems you may need to run:
Similarly, for stopping/restarting/viewing status of Zabbix agent, use the following commands:
Start up manually
If the above does not work you have to start it manually. Find the path to the zabbix_agentd binary and execute:
Agent on Windows systems
Zabbix agent on Windows runs as a Windows service.
Preparation
Zabbix agent is distributed as a zip archive. After you download the archive you need to unpack it. Choose any folder to store Zabbix agent and the configuration file, e. g.
Copy bin\zabbix_agentd.exe and conf\zabbix_agentd.conf files to c:\zabbix.
Edit the c:\zabbix\zabbix_agentd.conf file to your needs, making sure to specify a correct «Hostname» parameter.
Installation
After this is done use the following command to install Zabbix agent as Windows service:
Now you should be able to configure «Zabbix agent» service normally as any other Windows service.
See more details on installing and running Zabbix agent on Windows.
Other agent options
It is possible to run multiple instances of the agent on a host. A single instance can use the default configuration file or a configuration file specified in the command line. In case of multiple instances each agent instance must have its own configuration file (one of the instances can use the default configuration file).
The following command line parameters can be used with Zabbix agent:
Parameter | Description |
---|---|
UNIX and Windows agent | |
-c —config <config-file> | Path to the configuration file. You may use this option to specify a configuration file that is not the default one. On UNIX, default is /usr/local/etc/zabbix_agentd.conf or as set by compile-time variables —sysconfdir or —prefix On Windows, default is c:\zabbix_agentd.conf |
-p —print | Print known items and exit. Note: To return user parameter results as well, you must specify the configuration file (if it is not in the default location). |
-t —test <item key> | Test specified item and exit. Note: To return user parameter results as well, you must specify the configuration file (if it is not in the default location). |
-h —help | Display help information |
-V —version | Display version number |
UNIX agent only | |
-R —runtime-control <option> | Perform administrative functions. See runtime control. |
Windows agent only | |
-m —multiple-agents | Use multiple agent instances (with -i,-d,-s,-x functions). To distinguish service names of instances, each service name will include the Hostname value from the specified configuration file. |
Windows agent only (functions) | |
-i —install | Install Zabbix Windows agent as service |
-d —uninstall | Uninstall Zabbix Windows agent service |
-s —start | Start Zabbix Windows agent service |
-x —stop | Stop Zabbix Windows agent service |
Specific examples of using command line parameters:
- printing all built-in agent items with values
- testing a user parameter with «mysql.ping» key defined in the specified configuration file
- installing a «Zabbix Agent» service for Windows using the default path to configuration file c:\zabbix_agentd.conf
- installing a «Zabbix Agent [Hostname]» service for Windows using the configuration file zabbix_agentd.conf located in the same folder as agent executable and make the service name unique by extending it by Hostname value from the config file
Runtime control
With runtime control options you may change the log level of agent processes.
Option | Description | Target |
---|---|---|
log_level_increase[=<target>] | Increase log level. If target is not specified, all processes are affected. |
Target can be specified as: process type — all processes of specified type (e.g., listener) See all agent process types. process type,N — process type and number (e.g., listener,3) pid — process identifier (1 to 65535). For larger values specify target as ‘process-type,N’. |
log_level_decrease[=<target>] | Decrease log level. If target is not specified, all processes are affected. |
|
userparameter_reload | Reload user parameters from the current configuration file. Note that UserParameter is the only agent configuration option that will be reloaded. |
- increasing log level of all processes
- increasing log level of the third listener process
- increasing log level of process with PID 1234
- decreasing log level of all active check processes
Runtime control is not supported on OpenBSD, NetBSD and Windows.
Agent process types
- active checks — process for performing active checks
- collector — process for data collection
- listener — process for listening to passive checks
The agent log file can be used to observe these process types.
Process user
Zabbix agent on UNIX is designed to run as a non-root user. It will run as whatever non-root user it is started as. So you can run agent as any non-root user without any issues.
If you will try to run it as ‘root’, it will switch to a hardcoded ‘zabbix’ user, which must be present on your system. You can only run agent as ‘root’ if you modify the ‘AllowRoot’ parameter in the agent configuration file accordingly.
Configuration file
For details on configuring Zabbix agent see the configuration file options for zabbix_agentd or Windows agent.
Locale
Note that the agent requires a UTF-8 locale so that some textual agent items can return the expected content. Most modern Unix-like systems have a UTF-8 locale as default, however, there are some systems where that may need to be set specifically.
Exit code
Before version 2.2 Zabbix agent returned 0 in case of successful exit and 255 in case of failure. Starting from version 2.2 and higher Zabbix agent returns 0 in case of successful exit and 1 in case of failure.
Installation Zabbix Agent On Linux
In this article, I will explain the installation of Zabbix Agent on Linux machines.
Basically the way we will follow :
- Defining Zabbix Repostory
- Zabbix Linux Agent Installation
- Zabbix Agent Configuration
- Control of Zabbix Agent Services
- Linux firewall configuration
- Defining Zabbix Agent to Zabbix Server
Now we can start the installation.
We update our Linux server.
We add the Zabbix warehouse to our linux machine. I added the latest version 4.2 repository.
For detailed information about Redhat repository :
Zabbix Documentation 4.2
Official Zabbix packages are available for RHEL 7, CentOS 7 and Oracle Linux 7. In this documentation we will refer to…
For detailed information about Debian repository :
Zabbix Documentation 4.2
Official Zabbix packages are available for: Install the repository configuration package. This package contains apt…
In this article I will install on Centos 7.
Repository link
Packet Installation
We are installing the latest version of zabbix agent
Zabbix Agent Configuration
We open our config file.
We find the following lines and edit them according to our server address.
After doing the above, we save it by pressing Ctrl + O. After saving the changes, we press Ctrl + X to exit.
Server : The full name or IP address of your Zabbix server.
Hostname : Unique name for this computer on your Zabbix server.
LogFile : Line indicating where to save the logs.
After making the necessary settings, we start our service.
With the command below, our service will be running at startup automatically whenever the machine is restart.
To view the service status :
Configuring Linux Zabbix Agent Firewall Rules
For Ubuntu [On Debian based systems] :
If you are using IpTables :
Centos and Fedora :
You can run the command below to see which applications are using the 10050 port on your Linux Machine.
We restart the Zabbix Agent and view which ports our running zabbix application uses.
Adding Zabbix Client to Zabbix Server
If our Zabbix Agent work as a service on Linux, we are ready to add it on Zabbix Server. We go to the Host menu in Configuration and press the Create host button.
Host Tab :
Host Name : You can write any name you want.
Group : You can choose one of the ready-made groups or add a group yourself.
Agent interfaces : We enter the ip address of the machine where the agent is installed.
Template Tab :
We choose the template that has ready definitions in the Zabbix library and is suitable for our system.
Since we add an operating system to Linux, I choose Template OS Linux here. Apart from that, I added three more templates, this is up to you. After selecting Templates, I add my selection by clicking the Add button.
Finally, we click on the update button and after 2 minutes, our agent is active in green.
Zabbix Agent
Information about configured hosts in Zabbix is available in Configuration → Hosts. There is already one pre-defined host, called Zabbix server , but we want to learn adding another. To add a new host, click on Create host. This will present us with a host configuration form.
All hosts that you want to monitor have to have the [Zabbix Agent] installed. I will use the official Docker image to do that on my host machine:
Where some-zabbix-agent is the name you want to assign to your container, some-hostname is the hostname, it is Hostname parameter in Zabbix agent configuration file, some-zabbix-server is IP or DNS name of Zabbix server or proxy and tag is the tag specifying the version you want. See the list above for relevant tags, or look at the full list of tags.
Option2 Zabbix Agent Package
Run the below command to install Zabbix Agent on your host.
Modify Zabbix Agent Configuration
Open zabbix_agentd.conf file and make below necessary changes (Add your Zabbix Server IP and add Zabbix Agent hostname) and save + Exit.
Restart Zabbix Agent
Adding New host in Zabbix server
Login to Zabbix Server web interface.
Step 1
- Go to Configuration Main menu
- Click Hosts Sub menu
- Then, Create Host button
Step 2
- Enter your Original Host Name
- Enter visible name which you want to show the host
- Add Linux Servers group
- Add Zabbix Server IP
- Tick Enabled Check box to monitor the host
- Click Templates
- Click Select to add new template
- Choose Template App Docker (A list of all available templates can be found under Configuration/Templates)
- Add button to add the Template to new hosts
- Click Update to complete the process
Adding Encryption for Remote Hosts
For encryption we have an option to use PSK-based encryption. The secret should be minimum a 128-bit (16-byte PSK, entered as 32 hexadecimal digits) up to 2048-bit (256-byte PSK, entered as 512 hexadecimal digits). You can generate a 256 bit PSK secret on your server with openssl using the command:
Now we have to add a user called zabbix and assign this file to him — so we don't run into permission error once we mount it into the Zabbix Agent container:
We now have to restart the Zabbix Agent container with the following arguments:
Note that the path for the TLS PSK File mounts into /var/lib/zabbix/enc . To point to our PSK file we have to set the variable to ZBX_TLSPSKFILE=./agent_tls.psk and NOT ZBX_TLSPSKFILE=/var/lib/zabbix/enc/agent_tls.psk !
Our Zabbix Server will now loose it's connection:
Copy your generated pre-shared key cat /opt/zabbix/agent_tls.psk and the TLS Identity you set above ZBX_TLSPSKIDENTITY into the host configuration in Zabbix Dashboard:
The connection should now show up as encrypted a short while afterwards:
Zabbix User Management
Go to Administration → Users and click on Create user. In the new user form, make sure to add your user to one of the existing user groups, for example Zabbix administrators :
By default, new users have no media (notification delivery methods) defined for them. To create one, go to the Media tab and click on Add:
Adding Permissions
By default, a new user has no permissions to access hosts. To grant the user rights, click on the group of the user in the User Groups administration menu (in this case — Zabbix administrators ). In the group properties form, go to the Permissions tab.
In this pop-up, mark the checkbox next to Linux servers, then click Select. Linux servers should be displayed in the selection field. Click the Read button to set permission level and then Add to add the group to the list of permissions. In the user group properties form, click Update.
Zabbix Agent 2
Zabbix Agent2 is a drop-in replacement for an old Zabbix agent. Then new agent provides very wide functionality and possibilities to develop plugins for extended monitoring. Agent2 is written in Go language and supports custom plugins that you can write as per your needs and tasks.