Zabbix

Using Zabbix to monitor other systems with the Zabbix agent

published on

If you have followed the instructions in Installing Zabbix 7 LTS on Ubuntu you will now have a Zabbix server that you can use to monitor systems.

By default it will only be monitoring itself since you haven't yet configured it to monitor anything else.

Whilst there are many ways in which systems can be monitored one way is to install the Zabbix agent on the system you wish Zabbix to monitor. Obviously this can only be done on systems that you can install software on.

Installing the Zabbix agent

For the purposes of this tutorial we will presume you want to install the Zabbix agent on Ubuntu. If you wish to install the agent on something else instead visit https://www.zabbix.com/download. When you get to the Zabbix component section select one of the agent options.

Run the following commands to install Zabbix agent on Ubuntu 24.04:

wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-2+ubuntu24.04_all.deb
sudo dpkg -i zabbix-release_7.0-2+ubuntu24.04_all.deb
sudo apt update
sudo apt install zabbix-agent

Setting up the agent

I like to make sure the communication between the Zabbix server and agent is encrypted so I will run the following commands to ensure this will be the case:

openssl rand -hex 256 > [servername.psk]
sudo mv [servername.psk] /etc/zabbix
    where [servername] is the name of the server that the key applies to
sudo chown zabbix:zabbix /etc/zabbix/[servername].psk
sudo chmod 640 /etc/zabbix/[servername].psk

Now edit the agent configuration file and adding the IP address of the Zabbix server to the Server= line (it can also be added to the ServerActive= line if you wish to be able to perform active checks as well as passive) and add the hostname of the agent server to the Hostname= line.

Now find the TLSConnect and TLSAccept lines and change them to =psk. Find the TLSPSKIdentity line and add the agent server hostname again. Now find the TLSPSKFile line and add the location of where you saved the .psk file created above (/etc/zabbix/servername].psk if you followed the above instructions).

You will now need to restart the Zabbix agent by running sudo systemctl restart zabbix-agent && sudo systemctl enable zabbix-agent.

Note: Make sure to allow ports 10050 and 10051 in your firewall (depending on whether you are allowing passive checks, active checks or both).

Set up Zabbix

Login to the Zabbix GUI and open the Data Collection menu then select Hosts and finally select Create host.

Fill in the hostname (the same as you entered into the Zabbix agent configuration file), the group (for this example that would be Linux Servers) and the IP address of your server you installed the agent on.

On the Templates tab add the templates you wish to use. For this example this would be Linux Zabbix agent.

On the Encryption tab make sure Connections to host and Connections from host have psk ticked (if there are any other options ticked then untick them).

Add the hostname you entered into the agent configuration file earlier into the PSK Identity field.

Finally add the contents of the [servername.psk] file into the PSK field.

Once done click on Add (this might also be Update if you are coming back to make further changes).

Conclusion

You have now set up the Zabbix agent and, given a bit of time to start collecting data, the Zabbix GUI will have started recording and saving data from the agent.