What is Zabbix? Zabbix is an open source enterprise class monitoring solution. You can collect metrics from a seemingly unlimited amount of sources. These include network devices, cloud services, cloud containers, virtual machines, OS monitoring, log files, databases, applications, IoT devices, log files, endpoints, and more. The Zabbix Agent can be deployed on any operating system that you want to monitor, including all linux flavors, BSD, MacOS, AIX, Windows, Solaris, and more. Detect problems with services as they happen and get alerted by e-mail, SMS, Teams, Slack, rocket.chat, telegram, and pretty much any messaging system you can think of.
We will be installing Zabbix on a CentOS Stream 9 virtual machine to act as the Zabbix server. It will also include a MySQL databse and Nginx as the front end. We will then install the zabbix agent on a separate CentOS 9 stream VM and add it to our monitoring panel. Let’s get started.
Installation
The first thing we need to do is add the Zabbix repository. Become root as all commands require root/sudo privileges.
[vulnifo@zabbix ~]$ sudo -i
[sudo] password for vulnifo:
[root@zabbix ~]#
Install the Zabbix Repository for CentOS Stream 9.
# rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/9/x86_64/zabbix-release-6.2-3.el9.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/6.2/rhel/9/x86_64/zabbix-release-6.2-3.el9.noarch.rpm
warning: /var/tmp/rpm-tmp.qz1tvU: Header V4 RSA/SHA512 Signature, key ID 08efa7dd: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-6.2-3.el9 ################################# [100%]
Clean dnf packages.
# dnf clean all
21 files removed.
Install mariadb-server and complete the initial installation.
# dnf install mariadb-server
# mysql_secure_installation
Complete the initial setup of mariadb, it will go through various options to setup mariadb.
...
Enter current password for root (enter for none):
OK, successfully used password, moving on...
...
Change the root password? [Y/n] y
...
Remove anonymous users? [Y/n] y
... Success!
...
Disallow root login remotely? [Y/n] y
... Success!
...
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
...
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Enable mariadb at boot time for the system.
# systemctl enable --now mariadb
Install Zabbix Server, Agent, and Frontend.
# dnf install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent
Do the initial configuration of the database. Items in bold should be changed to your specific setting. Use the root password you created during the initial setup.
# mysql -u root -p
Enter password:
...
MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
MariaDB [(none)]> create user zabbix@localhost identified by 'password';
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
MariaDB [(none)]> set global log_bin_trust_function_creators = 1;
MariaDB [(none)]> quit;
Now we want to import the initial schema and data for the database. You will be prompted for the password you set in the last step. This step will take a bit of time depending on your server/vm specs.
# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -u zabbix -p zabbix
Now go back into the database and disable log_bin_trust_function_creators.
# mysql -u root -p
Enter password:
...
MariaDB [(none)]> set global log_bin_trust_function_creators = 0;
MariaDB [(none)]> quit;
Now we need to edit some configuration files. Use whatever text editor you like, I will use nano.
The first file we need is to configure the database for Zabbix. Set it to the Zabbix database password you set earlier.
# nano /etc/zabbix/zabbix_server.conf
...
DBPassword=password
Configure php for the Zabbix Frontend. Uncomment the following lines and set your server name. (For example our server_name is zabbix.lab.vulnifo.com)
# nano /etc/nginx/conf.d/zabbix.conf
...
listen 8080;
server_name example.com;
Now startand enable at boot time the Zabbix server and the Agent.
# systemctl restart zabbix-server zabbix-agent nginx php-fpm
# systemctl enable zabbix-server zabbix-agent nginx php-fpm
Allow the Zabbix Frontend port through the firewall.
# firewall-cmd --add-port=8080/tcp --permanent
# firewall-cmd --reload
Initial Setup
Open a web browser and input either your server name you set earlier or your server’s IP address and port 8080.
http://172.16.5.39:8080
You will be greeted with the initial setup screen.
Select your default language and then select “Next step”
A lit of server statistics will show up. This confirms that the system and Zabbix is ready and setup correctly.
If everything is OK select “Next step”
Enter the username and password for the database you created earlier.
Once finished select “Next step”
Enter your server name, your timezone, and select a theme if desired.
Select “Next step” once finished.
You will now see a summary of your initial installation.
If everything looks good select “Next step” or press “Back” to make any changes.
Your installation is now finished!
Select “Finish” and then you can log in to your Zabbix dashboard. The default credentials are: username= Admin / password= zabbix
After logging in you will be presenting with the default Zabbix dashboard.
Adding a Host
The Zabbix Agent includes a large suite of monitoring values for you to use. You can monitor individual metrics on devices that don’t support the agent (which would be fairly difficult to find) but these can be network switches or the like with SNMP for example. But since we want metrics on a VM, lets install and configure the agent on the VM and then add it as a host to our Zabbix server.
This VM is running CentOS Stream 9. For a list of repositories for other operating system go to the official Zabbix download page where you can select your operating system, Zabbix version, and which agent type you would like to download.
First add the Zabbix repository for our distribution (centos stream 9)
[vulnifo@stream9 ~]$ sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.2/rhel/9/x86_64/zabbix-release-6.2-3.el9.noarch.rpm
...
[vulnifo@stream9 ~]$ sudo dnf clean all
Now install the Zabbix Agent
[vulnifo@stream9 ~]$ sudo dnf install zabbix-agent
Allow port 10050 through the firewall so the server can make the agent connection.
[vulnifo@stream9 ~]$ sudo firewall-cmd --add-port=10050/tcp --permanent
[vulnifo@stream9 ~]$ sudo firewall-cmd --reload
Start and enable the Zabbix agent at boot time.
[vulnifo@stream9 ~]$ systemctl restart zabbix-agent
[vulnifo@stream9 ~]$ systemctl enable zabbix-agent
The last thing we need to do is tell the agent where our Zabbix server is so it can accept the connection.
Edit the zabbix_agentd.conf file
[vulnifo@stream9 ~]$ sudo nano /etc/zabbix/zabbix_agentd.conf
Find the line that says “Server=127.0.0.1” and change it to the IP address of your Zabbix server.
Server=<your zabbix server ip>
Save and quit the file.
Now go back into your Zabbix dashboard and in the left menu select Monitoring > Hosts
On the top right select “Create Host”
Enter the information for the host you want to connect to. Enter the Host Name, Select a Host Group (there’s default lists), Add an Interface with the IP of your Host, and enter any other optional information you would like.
Select “Add” and you should see your host populate on the hosts screen.
Now if you click on your host you get a popup with different information you can see about the host.
Selecting “Latest data” for example will give you a long list of information it is pulling from the agent.
Now you can add other hosts and customize your dashboard for any information that you specifically want to collect.
Conclusion
There you have it, Zabbix server is installed and we added a host to get data collection. Zabbix is VERY powerful and can show as many metrics at you that you want. It is a good solution for server monitoring as it is available for such a wide selection of devices/operating systems.
If you have any questions or feel you can better this content, please get a hold of us and let us know on social media or our contact page.
As always, follows us @vulnifo for updates!