How to start monitor Linux host with Zabbix server in 30 minuts…

Adam Jurkiewicz Pythonista
6 min readOct 4, 2023

In this article we connect Linux host to Zabbix monitoring server using zabbix agent 2 service. We have our monitoring server1 which has Linux Debian 11 system, MySQL database and Apache. 30 minutes should be enough to complete all steps.

Our scenario is as follows:

Configuring zabbix agent2

From Zabbix download center we have to set properly options and follow the instructions:

For Debian 11 server: https://www.zabbix.com/download?zabbix=6.0&os_distribution=debian&os_version=11&components=agent_2&db=&ws=

We have to download and install software:

# wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-4+debian11_all.deb
# dpkg -i zabbix-release_6.0-4+debian11_all.deb
# apt update
# apt install zabbix-agent2 zabbix-agent2-plugin-*

Communication beetween machines

Now we have to allow communication between Zabbix Server and this machine, so we add firewall rule (one open TCP port is enough):

# ufw allow proto tcp from 188.68.237.191 to any port 10050

Also, we need to open TCP port 10051 on Zabbix Server, to allow Active checks from our Debian, so we have to do:

root@linux-admin:~# ufw allow proto tcp from 188.68.236.236 to any port 10051

Creating host in Zabbix Dashboard

In CONFIGURATION | Hosts, we should Add new one.

Remember to ADD Interface IP and port.

Change Zabbix Server IP in agent configuration file.

Thi is important step — we have to write Zabbix Server IP in file /etc/zabbix/zabbix_agent2.conf on our Debian server:

# vim /etc/zabbix/zabbix_agent2.conf

### Option: Server
# List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.
# Incoming connections will be accepted only from the hosts listed here.
# If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally
# and '::/0' will allow any IPv4 or IPv6 address.
# '0.0.0.0/0' can be used to allow any IPv4 address.
# Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
#
# Mandatory: yes
# Default:
# Server=

# Server=127.0.0.1
Server=188.68.237.191


##### Active checks related

### Option: ServerActive
# Zabbix server/proxy address or cluster configuration to get active checks from.
# Server/proxy address is IP address or DNS name and optional port separated by colon.
# Cluster configuration is one or more server addresses separated by semicolon.
# Multiple Zabbix servers/clusters and Zabbix proxies can be specified, separated by comma.
# More than one Zabbix proxy should not be specified from each Zabbix server/cluster.
# If Zabbix proxy is specified then Zabbix server/cluster for that proxy should not be specified.
# Multiple comma-delimited addresses can be provided to use several independent Zabbix servers in parallel. Spaces are allowed.
# If port is not specified, default port is used.
# IPv6 addresses must be enclosed in square brackets if port for that host is specified.
# If port is not specified, square brackets for IPv6 addresses are optional.
# If this parameter is not specified, active checks are disabled.
# Example for Zabbix proxy:
# ServerActive=127.0.0.1:10051
# Example for multiple servers:
# ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
# Example for high availability:
# ServerActive=zabbix.cluster.node1;zabbix.cluster.node2:20051;zabbix.cluster.node3
# Example for high availability with two clusters and one server:
# ServerActive=zabbix.cluster.node1;zabbix.cluster.node2:20051,zabbix.cluster2.node1;zabbix.cluster2.node2,zabbix.domain
#
# Mandatory: no
# Default:
# ServerActive=

# ServerActive=127.0.0.1
ServerActive=188.68.237.191

### Option: Hostname
# List of comma delimited unique, case sensitive hostnames.
# Required for active checks and must match hostnames as configured on the server.
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=

Hostname=Moodle TS server

Next we need to start end enable zabbix agent2 service.

# systemctl start zabbix-agent2
# systemctl enable zabbix-agent2

After about 30 minutes, we can see everything is working.

OK, lets check MySQL, for start there is no data…

We will follow the documentation available on page: https://www.zabbix.com/documentation/current/en/manual/guides/monitor_mysql

Firts, we have to add zbx_monitor user and give privileges on Debian server (replace <password> for the “zbx_monitor” user with a password of your choice, good passwords can be generated with pwgencommand):

#mysql -u root -p

# Enter password:
mysql> CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';
mysql> GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';
mysql> quit;

Next, in CONFIGURATION | Hosts update in Macros TAB switch to Inherited and host macros, look for the following macros and click on Change next to the macro value to update it:

  • {$MYSQL.DSN} — set the data source of the MySQL server (the connection string of a named session from the MySQL Zabbix agent 2 plugin configuration file). This guide uses the default data source tcp://localhost:3306 for monitoring a MySQL server
  • {$MYSQL.PASSWORD} — set the password of the previously created MySQL user “zbx_monitor”.
  • {$MYSQL.USER} — set the name of the previously created MySQL user “zbx_monitor”.

After 10 minutes, we shoud see first data — in our case it is a problem ;-)

We can check graphs to see data.

Monitoring apache2 service

Here we will follow the documentation available at: https://www.zabbix.com/documentation/current/en/manual/guides/monitor_apache

In apache configuration file: /etc/apache2/mods-enabled/status.conf we modify Require ip and write Zabbix server IP

<IfModule mod_status.c>
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Uncomment and change the "192.0.2.0/24" to allow access from other hosts.

<Location /server-status>
SetHandler server-status
Require local
Require ip 188.68.237.191
</Location>

# Keep track of extended status information for each request
ExtendedStatus On

# Determine if mod_status displays the first 63 characters of a request or
# the last 63, assuming the request itself is greater than 63 chars.
# Default: Off
#SeeRequestTail On


<IfModule mod_proxy.c>
# Show Proxy LoadBalancer status in mod_status
ProxyStatus On
</IfModule>


</IfModule>

Then we should restart apache service:

#systemctl restart apache2 

We can check, if server-status is available from Zabbix server:

root@linux-admin:~# curl 188.68.236.236/server-status


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<title>Apache Status</title>
</head><body>
<h1>Apache Server Status for 188.68.236.236 (via 188.68.236.236)</h1>

<dl><dt>Server Version: Apache/2.4.56 (Debian) OpenSSL/1.1.1n</dt>
<dt>Server MPM: prefork</dt>
<dt>Server Built: 2023-04-02T03:06:01
[...]

Configuring in Zabbix dashboard

The only one thing we should add is a template called “Apache by HTTP” — it sould have all configuration correct.

After few seconds we shoud see the data:

That is everything — if this documents is helpful for you, just let me know by clap your hand and the one after document.

--

--

Linux (Debian/Ubuntu) admin 😆, Python (OOP, fastAPI) programmer 🖥️ | Teacher, trainer 📚 ⚓