Zabbix Agent vs Zabbix Agent 2
Agent 2 is written in Go and ships as a single binary with built-in plugin support for system metrics, Docker, PostgreSQL and other services. The original agent (zabbix-agentd) is written in C and requires external scripts or loadable modules for anything beyond basic system counters. Agent 2 uses more memory (typically 15-25 MB resident versus 8-12 MB for agent 1) but handles concurrent plugin queries without forking child processes, so under load it scales better and uses fewer file descriptors.
Agent 2 works with Zabbix server 4.4 and later, but you lose some features (flexible intervals, dependent items) unless the server is 5.0 or newer. If your server is still 4.2 or older, stay with agent 1. For new deployments on 5.0, 6.0 LTS or 7.0 LTS, pick agent 2. The configuration syntax is almost identical; migration takes minutes.
Both agents support active and passive checks, PSK or certificate encryption, and custom UserParameter commands. Agent 2 adds native plugins that run inside the agent process, so you can query a PostgreSQL database or scrape a Prometheus endpoint without shell scripts. The Zabbix agent concepts documentation covers the architecture differences in detail.
Installing Zabbix Agent 2 from Packages
Adding the Zabbix Repository
Zabbix publishes official packages for every major distribution. For Debian 12 or Ubuntu 22.04/24.04, download the repository configuration package for version 7.0 LTS:
wget https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.0+debian12_all.deb
dpkg -i zabbix-release_latest_7.0+debian12_all.deb
apt update
On RHEL 9, Rocky 9 or AlmaLinux 9, install the RPM release package:
rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rocky/9/x86_64/zabbix-release-latest-7.0.el9.noarch.rpm
dnf clean all
dnf makecache
SUSE Enterprise 15 uses a separate repository URL; replace the version and distribution in the path as needed. The release package adds /etc/apt/sources.list.d/zabbix.list or /etc/yum.repos.d/zabbix.repo and imports the GPG signing key.
Installing the Agent Package
Install the agent 2 package. On Debian and Ubuntu:
apt install zabbix-agent2 zabbix-agent2-plugin-*
On RHEL, Rocky and Alma:
dnf install zabbix-agent2 zabbix-agent2-plugin-*
The wildcard pulls in all available plugins (PostgreSQL, MongoDB, Redis, etc.). If you only need system metrics, install zabbix-agent2 alone. The package creates the zabbix user and group, sets up log rotation, and installs a systemd unit but does not start the service yet.
File Locations and Service Setup
The main configuration file is /etc/zabbix/zabbix_agent2.conf. Plugin configuration snippets live in /etc/zabbix/zabbix_agent2.d/plugins.d/*.conf. Logs go to /var/log/zabbix/zabbix_agent2.log by default. After editing the config, enable and start the service:
systemctl enable zabbix-agent2
systemctl start zabbix-agent2
systemctl status zabbix-agent2
You should see active (running) and a line like zabbix_agent2[12345]: Starting Zabbix Agent 2 (7.0.0). If the status shows failed, check the log for permission errors or missing configuration keys. The service runs as the zabbix user, so it cannot bind to privileged ports or read files owned by root without additional permissions.
Agent Configuration File Essentials
Server and ServerActive Directives
Open /etc/zabbix/zabbix_agent2.conf and set two key directives. Server= lists IP addresses or CIDR ranges allowed to connect for passive checks (the server polls the agent). ServerActive= points to the server's IP and port for active checks (the agent pushes data). A typical configuration:
Server=192.168.1.10
ServerActive=192.168.1.10:10051
If your server has multiple interfaces or you run a proxy, list all IPs in Server= separated by commas: Server=192.168.1.10,10.0.0.5. The agent rejects connections from any other address. ServerActive takes a hostname or IP with an optional port (default 10051). The agent connects to this address, retrieves the list of active items, and starts pushing metrics.
Hostname and HostMetadata
Set Hostname= to match the host name you will configure in the Zabbix server web interface. If the names do not match exactly, the server refuses data from the agent. For dynamic environments, leave Hostname= commented and set HostMetadata= with a string that triggers an auto-registration action on the server (covered in part 2). The agent sends its system hostname and metadata; the server creates the host automatically if an action matches.
ListenPort=10050 and ListenIP=0.0.0.0 control where the agent binds for passive checks. Change ListenIP to a specific interface IP if you want to restrict access by network. If you only use active checks, you can set ListenPort=0 to disable the listening socket entirely.
Passive vs Active Mode Trade-Offs
Passive checks: the server opens a TCP connection to the agent on port 10050, requests an item value, and closes the connection. Simple to firewall (allow inbound 10050 on the agent) but each item query is a separate connection. For 100 hosts with 50 items polled every 60 seconds, the server opens 83 connections per second.
Active checks: the agent connects to the server on port 10051 once, retrieves the full item list, then pushes all values in batches. The server never connects to the agent, so you only need outbound 10051 from the agent network. Active mode scales to thousands of hosts because the server does not manage connection state for each poll. The downside: item changes on the server take up to RefreshActiveChecks seconds (default 120) to propagate to the agent.
For most deployments, use active checks unless you have a hard requirement to never allow outbound connections from monitored hosts. You can mix both: set Server= and ServerActive=, then configure some items as passive (Zabbix agent type) and others as active (Zabbix agent active type) in the web interface. Restrict remote commands with AllowKey=system.run[*] or DenyKey=* if you do not want the server executing arbitrary scripts on the agent.
Enabling PSK Encryption Between Agent and Server
Pre-shared key encryption protects metrics in transit with a simple shared secret. PSK is faster to set up than TLS certificates and sufficient for most internal networks where you trust the server endpoint. The agent and server each hold a copy of the same 256-bit key; anyone who intercepts traffic sees only encrypted payloads.
Generating a PSK Key
Generate a 32-byte hex string (256 bits) using OpenSSL:
openssl rand -hex 32
You will see output like a1b2c3d4e5f67890abcdef1234567890a1b2c3d4e5f67890abcdef1234567890. Save this string; you need it for both the agent configuration file and the server web interface. Every host can share the same key, or you can generate unique keys per host. Unique keys limit exposure if one agent is compromised, but shared keys simplify bulk deployments.
Configuring the Agent for PSK
Edit /etc/zabbix/zabbix_agent2.conf and add four lines in the TLS section:
TLSConnect=psk
TLSAccept=psk
TLSPSKIdentity=host01-psk
TLSPSKFile=/etc/zabbix/zabbix_agent2.psk
TLSConnect=psk forces the agent to use PSK for active checks (outbound to the server). TLSAccept=psk requires PSK for passive checks (inbound from the server). The identity is a plain-text label that the server uses to look up the correct key; pick something descriptive like hostname-psk. Create the key file and paste the hex string from the previous step:
echo "a1b2c3d4e5f67890abcdef1234567890a1b2c3d4e5f67890abcdef1234567890" > /etc/zabbix/zabbix_agent2.psk
chown zabbix:zabbix /etc/zabbix/zabbix_agent2.psk
chmod 0600 /etc/zabbix/zabbix_agent2.psk
The file must be readable only by the zabbix user. If permissions are wrong, the agent logs cannot read PSK file and refuses to start. Restart the agent:
systemctl restart zabbix-agent2
Check /var/log/zabbix/zabbix_agent2.log for a line like using PSK identity "host01-psk". If you see TLS handshake failed, the server either has the wrong key or the identity does not match.
Adding the Host on the Server with PSK
In the Zabbix web interface, go to Configuration โ Hosts โ Create host. Fill in the host name (must match the agent's Hostname= directive exactly), then scroll to the Encryption section. Set Connections to host to PSK and Connections from host to PSK. Paste the same PSK identity (host01-psk) into the PSK identity field and the 64-character hex key into the PSK field. Click Add. Within 60 seconds the host availability icon should turn green. If it stays red, the most common mistake is a typo in the identity or key; check both sides character by character.
Adding the Host in Zabbix Server
Once the agent is running and reachable, register it in the Zabbix server web interface. The server needs the host's IP, the port the agent listens on, and a set of templates that define which metrics to collect.
Host Configuration Parameters
Navigate to Configuration โ Hosts โ Create host. Enter a Host name that matches the Hostname= value in the agent config (case-sensitive). In the Groups field, select or create a host group like Linux servers. Under Interfaces, click Add and choose Agent. Set the IP address to the agent's IP and port to 10050. If the agent only runs active checks, the IP can be 127.0.0.1 (it will never be used) but the interface must exist. Leave Monitored by proxy as (no proxy) unless you run a distributed setup.
Linking Templates
Scroll to the Templates section and click Select. Choose Linux by Zabbix agent 2 or OS Linux from the list. The template defines hundreds of items (CPU load, memory usage, disk I/O, network interfaces) and triggers (high CPU, low disk space). If you need PostgreSQL, Nginx or custom application counters, link more templates or create your own. Click Add to attach the template, then scroll down and click Add again to save the host. The server immediately schedules the first data collection.
Verifying the First Connection
Wait 60 seconds, then go to Monitoring โ Latest data. Select your host group and host name in the filters. You should see rows for system.cpu.load[,avg1], vfs.fs.size[/,used], vm.memory.size[available] and other items with recent timestamps and values. If the table is empty, check the host list at Configuration โ Hosts and look at the Availability column. The ZBX icon should be green (agent reachable). Red means the server cannot connect; grey means no data yet. Click the icon for a tooltip with the last error message, such as Get value from agent failed: cannot connect to [192.168.1.20]:10050: Connection refused. That tells you the agent is not listening or a firewall is blocking port 10050.
Troubleshooting Connection Failures
When the host availability icon stays red or grey, the problem is almost always network connectivity, a mismatch between agent and server configuration, or a firewall rule. Work through the agent log, server log and network path in that order.
Agent Log Diagnosis
Tail the agent log in real time:
tail -f /var/log/zabbix/zabbix_agent2.log
Common error messages and their causes:
cannot connect to [192.168.1.10]:10051: connection refusedโ The agent is in active mode (ServerActive=is set) but cannot reach the server on port 10051. Check that the server IP is correct and that the server process is running. Verify withnc -zv 192.168.1.10 10051from the agent host.failed to accept an incoming connection: connection from 192.168.1.99 rejected, allowed hosts: 192.168.1.10โ Passive check from an IP not listed inServer=. Add the server's IP or CIDR to theServer=directive.TLS handshake with 192.168.1.10:10051 failed: wrong PSK identity or PSKโ The PSK identity or key on the agent does not match the server configuration. Re-check both fields in the web interface.
If the log shows active checks disabled, the agent could not retrieve the item list from the server. This happens when the host is not yet configured on the server or the host name does not match.
Server-Side Checks
On the Zabbix server, check /var/log/zabbix/zabbix_server.log for lines mentioning the host name. Look for:
no active checks on server [192.168.1.10:10051]: host [host01] not foundโ The agent is sending the wrong host name, or you have not created the host in the web interface.cannot send list of active checks to [192.168.1.20]: host [host01] not monitoredโ The host exists but is disabled. Go to Configuration โ Hosts, find the host and click Enabled.
If the server log is silent, the agent's packets never arrive. Move to network-layer checks.
Firewall and Network Verification
For passive checks, the server must reach the agent on TCP port 10050. Test from the server:
nc -zv 192.168.1.20 10050
If that times out, check iptables on the agent:
iptables -L INPUT -n -v | grep 10050
Add a rule if needed:
iptables -I INPUT -p tcp --dport 10050 -s 192.168.1.10 -j ACCEPT
For active checks, the agent must reach the server on TCP port 10051. Test from the agent host with the same nc command. If you see Connection refused, the server is not listening; check that zabbix-server is running and ListenPort=10051 is set in /etc/zabbix/zabbix_server.conf.
On RHEL and derivatives, SELinux can block network connections. Check denials in the audit log:
ausearch -m avc -ts recent | grep zabbix
If you see denied { name_connect }, enable the boolean:
setsebool -P zabbix_can_network on
To watch the actual TCP handshake, run tcpdump on the agent while the server polls:
tcpdump -i any -n port 10050 or port 10051
You should see SYN, SYN-ACK, ACK packets followed by encrypted TLS data if PSK is enabled. If you see only SYN retransmits, a firewall or routing issue is dropping packets.
Custom UserParameter Plugins
UserParameter directives in /etc/zabbix/zabbix_agent2.conf let you extend the agent with shell scripts or binaries that output metrics the built-in items do not cover. A UserParameter maps a custom item key to a command the agent executes when the server requests that key. The command must print a single numeric or text value to stdout, or a JSON object for low-level discovery. Exit code zero means success; any other code makes the item go unsupported.
Writing a UserParameter Script
Suppose you want to monitor NVMe drive temperature. Create /usr/local/bin/disk_temp.sh:
#!/bin/bash
nvme smart-log /dev/nvme0 | awk '/^temperature/ {print $3}'
Make it executable and test as the zabbix user:
chmod +x /usr/local/bin/disk_temp.sh
sudo -u zabbix /usr/local/bin/disk_temp.sh
You should see a single integer like 37. If the script prints multiple lines or fails, the item will return no data. The script must complete within the timeout window (default Timeout=3 in the agent config); longer-running commands get killed. Increase Timeout= if you query slow APIs or databases, but keep it under 30 seconds to avoid blocking the agent's worker threads.
Agent Configuration for UserParameters
Add a UserParameter line to /etc/zabbix/zabbix_agent2.conf or create a drop-in file in /etc/zabbix/zabbix_agent2.d/:
UserParameter=custom.disktemp,/usr/local/bin/disk_temp.sh
The key custom.disktemp is what you will configure in the server's item definition. Reload the agent to pick up the new parameter:
systemctl reload zabbix-agent2
Check the log for loaded UserParameter: custom.disktemp. If you need to pass arguments to the script (for example, to monitor multiple disks) use UserParameter=custom.disktemp[*],/usr/local/bin/disk_temp.sh $1 and set UnsafeUserParameters=1 in the agent config. This is a security risk because the server can inject arbitrary arguments, so only enable it in trusted environments. Restrict allowed characters with AllowKey= and DenyKey= directives if you turn on unsafe parameters.
Testing Custom Items on the Server
On the Zabbix server host, use zabbix_get to query the agent directly:
zabbix_get -s 192.168.1.20 -k custom.disktemp
You should see the same output the script produced. If you get ZBX_NOTSUPPORTED, the agent does not recognize the key; check for typos and confirm you reloaded the service. Once zabbix_get succeeds, go to the web interface, navigate to Configuration โ Hosts, select your host, click Items โ Create item. Set Name to NVMe temperature, Type to Zabbix agent, Key to custom.disktemp, and Type of information to Numeric (unsigned). Save the item and wait one update interval. The value appears in Monitoring โ Latest data. For more complex examples and JSON discovery rules, see the Zabbix UserParameter documentation.
Active vs Passive Checks Performance
Active checks reverse the connection direction: the agent opens a persistent connection to the server on port 10051, retrieves the list of monitored items, and pushes metric values on schedule. The server never connects to the agent, so you only need one firewall rule (outbound TCP 10051 from each agent network). This scales to thousands of hosts because the server maintains minimal state; each agent manages its own item queue. The agent refreshes the item list every RefreshActiveChecks=120 seconds by default, so changes you make in the web interface (new items, updated intervals) take up to two minutes to propagate.
Passive checks work the other way: the server opens a new TCP connection to each agent on port 10050, requests a single item value, and closes the connection. Each item poll is a separate handshake. For 100 hosts with 50 items polled every 60 seconds, the server opens 83 connections per second. This still works fine at moderate scale, but you need an inbound firewall rule on every agent host. Passive checks are easier to troubleshoot (zabbix_get queries the same path the server uses) and item changes apply immediately.
For 100+ hosts, prefer active checks. The server CPU and network usage stays flat as you add agents. For DMZ or restricted network zones where agents cannot initiate outbound connections, use passive checks and allow inbound 10050 per host. Hybrid mode works: set both Server= and ServerActive= in the agent config, then configure some items as Zabbix agent (passive) and others as Zabbix agent (active) in the web interface. Use passive for items you need to poll on-demand (remote commands, user login counts) and active for everything else. Latency differs: passive checks return data within seconds of the poll; active checks can lag 1-10 seconds depending on the agent's internal queue and batch size.
Post-Installation Checklist
Before adding the next hundred hosts, verify the foundation is solid. Confirm the agent appears in Monitoring โ Latest data with recent values for CPU, memory and disk. Check that triggers fire correctly by filling a test filesystem past 80% or running stress --cpu 4 --timeout 60s to spike load. If you enabled PSK, run a packet capture on the agent during a poll and confirm you see encrypted TLS Application Data instead of plaintext Zabbix protocol headers.
Decide on a naming convention for host names and host groups now. Use DNS names or FQDNs if your infrastructure relies on dynamic IPs; use static IPs if DNS is unreliable. Create host groups by function (web servers, database servers, Kubernetes nodes) rather than location, so you can apply templates and actions consistently. Document your PSK key storage: if you lose the key, you must regenerate and re-deploy to every agent. For multi-site deployments, consider Zabbix proxies to reduce WAN traffic; each proxy aggregates data from local agents and forwards compressed batches to the central server.
Set up alerting next: define trigger actions that send email or webhook notifications when a host goes down or a disk fills. The default templates include reasonable thresholds, but tune them to your workload. High CPU on a batch-processing node is normal; high CPU on an idle API server is not. For a broader comparison of monitoring tools and when to pick Zabbix over Prometheus or Nagios, see Linux Server Monitoring Tools Comparison. If you are building a full observability stack, the Prometheus and Grafana Setup guide covers complementary metric visualization.
Frequently Asked Questions
What is the difference between Zabbix agent and Zabbix agent 2?
Zabbix agent 2 is a Go rewrite of the original C-based agent. It includes native plugins for services like PostgreSQL and Docker, uses less memory under concurrent load, and handles all metric collection in a single process without forking. The old agent still receives security patches but no new features. Use agent 2 for any deployment on Zabbix 5.0 or later; the configuration syntax is nearly identical, so migration is straightforward.
How do I configure PSK encryption for Zabbix agent 2?
Generate a 256-bit hex key with openssl rand -hex 32, save it to /etc/zabbix/zabbix_agent2.psk with mode 0600 owned by the zabbix user, then add TLSConnect=psk, TLSAccept=psk, TLSPSKIdentity=your-label and TLSPSKFile=/etc/zabbix/zabbix_agent2.psk to the agent config. In the Zabbix web interface, set the host's encryption to PSK and paste the same identity and key. Restart the agent and verify the connection turns green within 60 seconds.
Why is my Zabbix agent showing as unavailable on the server?
Check the agent log for connection errors and confirm the Server= directive includes the server's IP. Test network connectivity with nc -zv server_ip 10050 for passive checks or nc -zv server_ip 10051 for active checks. Verify firewall rules allow the required ports and that the host name in the agent config exactly matches the host name configured in the web interface. If you enabled PSK, confirm the identity and key match on both sides.
Should I use active or passive checks for Zabbix monitoring?
Use active checks for deployments with more than 100 hosts or when agents cannot accept inbound connections. Active mode scales better because the server does not manage per-host connection state. Use passive checks in restricted networks where agents cannot initiate outbound connections, or when you need immediate item updates. You can run both modes simultaneously by setting Server= and ServerActive=, then choosing the check type per item in the web interface.
How do I add custom metrics with UserParameter in Zabbix agent 2?
Write a script that outputs a single value to stdout, make it executable, and add a line like UserParameter=custom.mykey,/path/to/script.sh to /etc/zabbix/zabbix_agent2.conf. Reload the agent with systemctl reload zabbix-agent2, then test with zabbix_get -s agent_ip -k custom.mykey. In the web interface, create a Zabbix agent item with that key. The script must complete within the agent's timeout (default three seconds) and run as the zabbix user.