Zabbix agent deployment and configuration

Installation and configuration of the Zabbix agent, the counterpart of the Zabbix server, that collects and sends data to the server to be shown, is quite easy and can be done with a simple bash script.

# File:


# Zabbix version

# File name version

if [ -z $HOSTNAME ]
        HOSTNAME=$(cat /etc/hostname)

if [ -z $SERVER ]

dpkg -i zabbix-release_${FNV}+ubuntu20.04_all.deb
apt update
apt install -y zabbix-agent

sed -i "s/^Server=127\.0\.0\.1$/Server=${SERVER}/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/^Hostname=Zabbix server$/Hostname=${HOSTNAME}/g" /etc/zabbix/zabbix_agentd.conf

systemctl restart zabbix-agent.service

Now let’s imagine you have 1000 hosts and would have to do that on each and every one of them. That’s going to be a long day of work.

My assumption here is, that you as the administrator have ssh root access to all these machines via a ssh public key and each host has a individual hostname (For example: vm1, vm2, vm3, …, vmN or GUIDs).

If this is given the shown script can be transferred to the host via “scp” and executed via “ssh”. I will show this with 4 hosts but with a little bash magic this can be extended to a lot more.

# File:

for HOST in vm1 vm2 vm3 vm4
        scp root@$host:/root/
        ssh root@$host "chmod u+x ./; ./ $SERVER $HOST; rm ./;"

In this script the server securely copies the file “” shown above to the hosts one by one and executes it to install and configure Zabbix agent. The agent is restarted afterwards and can be added to the Zabbix server. I am planing to write another tutorial on how to do this via API. This can then be integrated into the server script.

The client script can also be used to add the Zabbix agent manually. Just check the current version and modify the script if necessary.

As always: I hope this saves somebody some time and makes administration a little bit easier.