29,99 €
This updated second edition of the Zabbix 6 IT Infrastructure Monitoring Cookbook brings you new recipes, updated with Zabbix 6 functionality. You'll learn how to set up Zabbix with built-in high availability, use the improved Business Service Monitoring, set up automatic reporting, and create advanced triggers. Zabbix offers useful insights into your infrastructure performance and issues and enables you to enhance your monitoring setup with its powerful features. This book covers hands-on, easy-to-follow recipes for using Zabbix 6 to monitor effectively the performance of devices and applications over the network.
You'll start by working your way through the installation and most prominent features of Zabbix and make the right design choices for building a scalable and easily manageable environment. This Zabbix book contains recipes for building items and triggers for different types of monitoring, building templates, and using Zabbix proxies. Next, you'll use the Zabbix API for customization and manage your Zabbix server and database efficiently. Finally, you'll find quick solutions to the common and not-so-common problems that you may encounter in your Zabbix monitoring work.
By the end of this book, you'll be able to use Zabbix for all your monitoring needs and build a solid Zabbix setup by leveraging its key functionalities.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 396
Veröffentlichungsjahr: 2022
Explore the new features of Zabbix 6 for designing, building, and maintaining your Zabbix setup
Nathan Liefting
Brian van Baekel
BIRMINGHAM—MUMBAI
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Vijin Boricha
Publishing Product Manager: Vijin Boricha
Senior Editor: Arun Nadar
Content Development Editor: Romy Dias
Technical Editor: Shruthi Shetty
Copy Editor: Safis Editing
Project Coordinator: Shagun Saini
Proofreader: Safis Editing
Indexer: Manju Arasan
Production Designer: Sinhayna Bias
Marketing Coordinator: Nimisha Dua
First published: January 2021
Second edition: March 2022
Production reference: 1180322
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80324-691-8
www.packt.com
To my grandparents, for supporting my education, my brother, for always being at the ready, and my mom and stepdad, for cheering me on. To my girlfriend, for always supporting whatever new idea I get into my head. To my colleagues throughout the years, my first mentor, Sander F., for inspiring me, and Brian, for making it all possible.
– Nathan Liefting
Despite all the challenges brought to us in recent years, IT technology progress inevitably continues with increasing speed. No matter how far in the past we look, we can understand that IT nowadays is not like it was a year or two ago. For monitoring solutions, there is always an ongoing rush after new technology trends just to be able to support new solutions and comply with growing requirements from businesses that expect more and more from their monitoring solutions.
As an area that is covered in product growth, monitoring also becomes more saturated and flexible, which can also make it more complicated, especially for beginners that are just starting their journey in the world of monitoring. And thus, here comes the beauty of open source, where the community bands together and makes a huge effort to help each other with different ideas, approaches, and best practices. This collaboration with the community is what I try to take part in myself, by creating various videos about Zabbix functionality, monitoring ideas, and different use cases. It is important to understand that nobody will be able to provide a solution to any request, but our goal is to give insights into how to use tools that you should use to build solutions adopted precisely as per your needs.
Community drive and a feeling of one team who shares the same goals cannot be missed by anyone who works with the Zabbix monitoring solution. I'm sure that it is only because of the active community that I have had the chance to meet Brian and Nathan. Many years ago, when Brian was participating in a Zabbix certified specialist course, on day 1, he made it clear that his skills are far beyond an average specialist and even back then, he did his best to share his experience and help students who were on their first days with Zabbix. It is great to see that after all these years, the passion is still there. Now, with the tremendous help of Nathan and the huge experience gained by working with different Zabbix installations and different requirements, these guys have not only acquired a huge baggage of experience to share with you but have also learned the best ways to deliver this information to someone who may be far from an expert in Zabbix and monitoring.
I'm sure that for all of us, the main goal is to make Zabbix accessible to anyone in any place with any skill level. That is the purpose of my videos and that is the purpose of this book: to put all-out experience and lessons learned in one place for our community.
Dmitry Lambert
Creator of the Zabbix YouTube channel https://www.youtube.com/c/ZabbixCookBook
Nathan Liefting, also known as Larcorba, is an IT consultant, trainer, and content creator (artist). He has more than 6 years of professional experience in IT. His experience ranges from managing networks running EVPN/VXLAN to Linux environments and programming. Nathan started working with Zabbix in 2016 when it was still at Zabbix 2 and Zabbix 3 was just released.
He now works for Opensource ICT Solutions BV in the Netherlands as a Zabbix trainer and consultant, designing and building professional Zabbix environments and Zabbix components for some of the biggest companies around the world.
Brian van Baekel quickly discovered how powerful Zabbix is during his career as a network engineer. Ever since, he has been working with Zabbix in various (large) environments, leading to his official Zabbix Certified Trainer certification in early 2017.
In 2018, Brian founded Opensource ICT Solutions BV in the Netherlands and Opensource ICT Solutions LLC in the US. Both companies primarily focus on building Zabbix environments all over the world. In 2021, further expansion of the business was established by opening a subsidiary in the United Kingdom with a full focus on the Zabbix product. All companies provide support, training, and consultancy services, which means Brian works with the Zabbix product 24/7.
Fun fact: Even his cat is named Zabbix.
Patrik Uytterhoeven has about 20 years of experience in IT, mostly with HP UNIX and Red Hat Linux. In late 2012, he joined Open-Future, a leading open source integrator and the first Zabbix reseller and training partner in Belgium. When Patrik joined Open-Future, he also became a Zabbix-certified trainer. Since then, he has provided onsite training and public demonstrations around the world in Europe, America, and Asia.
His next step was to author a book, so the first Zabbix Cookbook was born. Because Patrik also has a deep interest in configuration management, he wrote some Ansible roles. Patrik was also a technical reviewer of Learning Ansible and Ansible Configuration Management. Later, Patrik rewrote the popular Zabbix network monitoring book by Richard Olups and Zabbix 4 Network Monitoring was born.
Roy van Baekel is an experienced network architect and Linux system administrator with more than 10 years of experience building internet service provider networks (MPLS, QoS, BGP, EVPN, and so on) and highly available Linux platforms (Apache, MySQL, Leepalived, KVM, and OpenStack). All these systems are as good as their monitoring capabilities, and as such, Roy has in-depth experience with common monitoring tools such as PRTG, Icinga, and Zabbix. Roy loves to automate repeating tasks – using tools such as Ansible or Puppet. With experience in multiple programming languages, everything is tied together to provide the best solution to customers.
Julio Daniel Zanette is a Christian and technology enthusiast with over 10 years of experience in information technology. Born in Brazil and moving to the UK in 2018, he graduated in information technology management. Having worked for many years as a Sysadmin and always looking for new knowledge and challenges, in recent years, he has moved to the DevOps role. Having been introduced to Zabbix in 2015, he soon began to call himself a Zabbix enthusiast. In 2017, he passed the certification exams for Zabbix Specialist and Zabbix Professional, and in 2019, he went to Zabbix SIA in Latvia for Zabbix Certified Expert training, returning home with the title of Zabbix Certified Expert.
I'd like to thank God first, for His almighty guidance on whatever decisions I make. I would like to thank my wife, Fernanda, and my three daughters, Tata, Nana, and Duda, for their daily support and patience. And to the awesome Zabbix team, for making this incredible software.
Welcome to Zabbix 6 IT Infrastructure Monitoring Cookbook. IT infrastructure ranges from Windows and Linux to networking and development, and basically anything that runs on computer hardware. In this book, we will go over various topics useful to anyone in IT that wants to use Zabbix to monitor their IT infrastructure.
Monitoring systems are often overlooked within IT organizations, but they can provide an overview that will save you time, money, and headaches. This book is for IT engineers that want to learn about Zabbix 6 and how to use it to bring their IT environments to the next level.
Chapter 1, Installing Zabbix and Getting Started Using the Frontend, covers how to set up Zabbix, optionally with HA. We will also work our way through the Zabbix frontend.
Chapter 2, Getting Things Ready with Zabbix User Management, covers how to set up your first users, user groups, and user roles.
Chapter 3, Setting Up Zabbix Monitoring, covers how to set up almost any type of monitoring within Zabbix.
Chapter 4, Working with Triggers and Alerts, covers how to set up triggers and get alerts from them.
Chapter 5, Building Your Own Structured Templates, covers how to build templates that are structured, which will work wonders for keeping your Zabbix setup organized.
Chapter 6, Visualizing Data, Inventory, and Reporting, covers how to visualize data in graphs, maps, and dashboards. It also covers how to use the Zabbix inventory, reporting, and business service monitoring functionality.
Chapter 7, Using Discovery for Automatic Creation, covers how to use Zabbix discovery for automatic host creation as well as items, triggers, and more with agents, SNMP, WMI, and JMX.
Chapter 8, Setting Up Zabbix Proxies, teaches you how to set up Zabbix proxies correctly for use in a production environment.
Chapter 9, Integrating Zabbix with External Services, teaches you how to integrate Zabbix with external services for alerting.
Chapter 10, Extending Zabbix Functionality with Custom Scripts and the Zabbix API, covers how to extend Zabbix functionality by using custom scripts and the Zabbix API.
Chapter 11, Maintaining Your Zabbix Setup, covers how to maintain a Zabbix setup and keep its performance up over time.
Chapter 12, Advanced Zabbix Database Management, teaches you how to manage Zabbix databases for an advanced setup.
Chapter 13, Bringing Zabbix to the Cloud with Zabbix Cloud Integration, covers how to use Zabbix in the cloud with services such as AWS, Azure, and Docker.
You should have a good basis in IT to understand the terminology used in this book. This book is best for people with at least a starting knowledge of monitoring systems, Linux, and network engineering.
Make sure you have a virtualization environment ready to create virtual machines for use with the recipes. VirtualBox, VMware, or any type of client/hypervisor will do.
Throughout the book, we will make use of VIM to edit files, so make sure to install it. If you do not feel comfortable using VIM, you can substitute the command for NANO or anything else you prefer.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book's GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
You can download the example code files for this book from GitHub at:
https://github.com/PacktPublishing/Zabbix-6-IT-Infrastructure-Monitoring-Cookbook
If there's an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at:
https://github.com/PacktPublishing/
Check them out!
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here:
https://static.packt-cdn.com/downloads/9781803246918_ColorImages.pdf
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "It's important to back up all of our Zabbix configuration data, which is located in the /etc/zabbix/ folder."
A block of code is set as follows:
# MariaDB Server
# To use a different major version of the server, or to pin to a specific minor version, change URI below.
deb [arch=amd64] http://downloads.mariadb.com/MariaDB/ mariadb-10.5/repo/ubuntu xenial main
Any command-line input or output is written as follows:
systemctl start mariadb
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: "Then we navigate to Monitoring | Hosts and click on Latest data for the Zabbix server host."
Tips or Important Notes
Appear like this.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Once you've read Zabbix 6 IT Infrastructure Monitoring Cookbook - Second Edition, we'd love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we're delivering excellent quality content.
Zabbix 6 is like a continuation of Zabbix 5, as this time around we aren't looking at big UI changes. However, in Zabbix 6, you will still find a lot of improvements, both to the UI and core components. For example, the introduction of high availability for the Zabbix server. We will detail all of the important changes throughout the book.
In this chapter, we will install the Zabbix server and explore the Zabbix UI to get you familiar with it. We will go over finding your hosts, triggers, dashboards, and more to make sure you feel confident diving into the deeper material later on in this book. The Zabbix UI has a lot of options to explore, so if you are just getting started, don't get overwhelmed. It's quite structurally built and once you get the hang of it, I am confident you will find your way without issues. You will learn all about these subjects in the following recipes:
Installing the Zabbix serverSetting up the Zabbix frontendEnabling Zabbix server high availabilityUsing the Zabbix frontendNavigating the Zabbix frontendWe'll be starting this chapter with an empty Linux (virtual) machine. Feel free to choose a RHEL- or Debian-based Linux distribution. We will then set up a Zabbix server from scratch on this host.
So before jumping in, make sure you have your Linux host at the ready.
Before doing anything within Zabbix, we need to install it and get ready to start working with it. In this recipe, we are going to discover how to install Zabbix server 6.
Before we actually install the Zabbix server, we are going to need to fulfill some prerequisite requirements. We will be using MariaDB mostly throughout this book. MariaDB is popular and a lot of information is available on the use of it with Zabbix.
At this point, you should have a prepared Linux server in front of you running either a RHEL- or Debian-based distribution. I'll be installing CentOS and Ubuntu 20.04 on my server; let's call them lar-book-centos and lar-book-ubuntu.
When you have your server ready, we can start the installation process.
For RHEL-based systems:
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
dnf clean all
For Ubuntu systems:
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu20.04_all.deb
dpkg -i zabbix-release_6.0-1+ubuntu20.04_all.deb
apt update
Now that the repository is added, let's add the MariaDB repository on our server:wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
./mariadb_repo_setup
Then install and enable it using the following commands:For RHEL-based systems:
dnf install mariadb-server
systemctl enable mariadb
systemctl start mariadb
For Ubuntu systems:
apt install mariadb-server
systemctl enable mariadb
systemctl start mariadb
After installing MariaDB, make sure to secure your installation with the following command:/usr/bin/mariadb-secure-installation
Make sure to answer the questions with yes (Y) and configure a root password that's secure.Run through the secure installation setup and make sure to save your password somewhere. It's highly recommended to use a password vault.Now, let's install our Zabbix server with MySQL support.For RHEL-based systems:
dnf install zabbix-server-mysql zabbix-sql-scripts
For Ubuntu systems:
apt install zabbix-server-mysql zabbix-sql-scripts
With the Zabbix server installed, we are ready to create our Zabbix database. Log in to MariaDB with the following:mysql -u root -p
Enter the password you set up during the secure installation and create the Zabbix database with the following commands. Do not forget to change password in the second command:create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@localhost identified by 'password';
grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
flush privileges;
quit
Tip
For those who might require it, Zabbix does also support utf8mb4 now. We've changed utf8 to utf8mb4 in the command above and everything will work. For a reference, check the Zabbix support ticket here: https://support.zabbix.com/browse/ZBXNEXT-3706.
Now we need to import our Zabbix database scheme to our newly created Zabbix database:zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -u zabbix -p zabbix
Important Note
At this point, it might look like you are stuck and the system is not responding. Do not worry though as it will just take a while to import the SQL scheme.
We are now done with the preparations for our MariaDB side and are ready to move on to the next step, which will be configuring the Zabbix server:
The Zabbix server is configured using the Zabbix server config file. This file is located in /etc/zabbix/. Let's open this file with our favorite editor; I'll be using Vim throughout the book:vim /etc/zabbix/zabbix_server.conf
Now, make sure the following lines in the file match your database name, database user username, and database user password:DBName=zabbix
DBUser=zabbix
DBPassword=password
Tip
Before starting the Zabbix server, you should configure SELinux or AppArmor to allow the use of the Zabbix server. If this is a test machine, you can use a permissive stance for SELinux or disable AppArmor, but it is recommended to not do this in production.
All done; we are now ready to start our Zabbix server:systemctl enable zabbix-server
systemctl start zabbix-server
Check whether everything is starting up as expected with the following:systemctl status zabbix-server
Alternatively, monitor the log file, which provides a detailed description of the Zabbix startup process:tail -f /var/log/zabbix/zabbix_server.log
Most of the messages in this file are fine and can be ignored safely, but make sure to read well and see if there are any issues with your Zabbix server starting.The Zabbix server is the main process for our Zabbix setup. It is responsible for our monitoring, problem alerting, and a lot of the other tasks described in this book. A complete Zabbix stack consists of at least the following:
A database (MySQL, PostgreSQL, or Oracle)A Zabbix serverApache or NGINX running the Zabbix frontend with PHP 7.2+, but PHP 8 is currently not supportedWe can see the components and how they communicate with each other in the following figure:
Figure 1.1 – Zabbix setup communications diagram
We've just set up the Zabbix server and database; by running these two, we are basically ready to start monitoring. The Zabbix server communicates with the Zabbix database to write collected values to it.
There is still one problem though: we cannot configure our Zabbix server to do anything. For this, we are going to need our Zabbix frontend, which we'll set up in the next recipe.
The Zabbix frontend is the face of our server. It's where we will configure all of our hosts, templates, dashboards, maps, and everything else. Without it, we would be blind to what's going on, on the server side. So, let's set up our Zabbix frontend in this recipe.
We are going to set up the Zabbix frontend using Apache. Before starting with this recipe, make sure you are running the Zabbix server on a Linux distribution of your choice. I'll be using the lar-book-centos and lar-book-ubuntu hosts in these recipes to show the setup process on CentOS 8 and Ubuntu 20.
For RHEL-based systems:
dnf install zabbix-web-mysql zabbix-apache-conf
For Ubuntu systems:
apt install zabbix-frontend-php zabbix-apache-conf
Tip
Don't forget to allow ports 80 and 443 in your firewall if you are using one. Without this, you won't be able to connect to the frontend.
Restart the Zabbix components and make sure they start up when the server is booted with the following.For RHEL-based systems:
systemctl enable httpd php-fpm
systemctl restart zabbix-server httpd php-fpm
For Ubuntu systems:
systemctl enable apache2
systemctl restart zabbix-server apache2
We should now be able to navigate to our Zabbix frontend without any issues and start the final steps to set up the Zabbix frontend.Let's go to our browser and navigate to our server's IP. It should look like this:http://<your_server_ip>/zabbix
We should now see the following web page:Figure 1.2 – The Zabbix welcome screen
If you don't see this web page, it's possible you have missed some steps in the setup process. Retrace your steps and double-check your configuration files; even the smallest typo could prevent the web page from serving.
Let's continue by clicking Next step on this page, which will serve you with the next page:Figure 1.3 – The Zabbix installation pre-requisites page
Every single option here should be showing OK now; if not, fix the mistake it's showing you. If everything is OK, you may proceed by clicking Next step again, which will take you to the next page:Figure 1.4 – The Zabbix installation DB connection page
Here, we need to tell our Zabbix frontend where our MySQL database is located. Since we installed it on localhost, we just need to make sure we issue the right database name, database user username, and database user password.This should make the Zabbix frontend able to communicate with the database. Let's proceed by clicking Next step again:Figure 1.5 – The Zabbix installation server details page
Next up is the Zabbix server configuration. Make sure to name your server something useful or something cool. For example, I've set up a production server called Meeseeks because every time we got an alert, we could make Zabbix say "I'm Mr. Meeseeks look at me." But something like zabbix.example.com also works.
Let's name our server, set up the time zone to match our own time zone and proceed to the next step:Figure 1.6 – The Zabbix installation summary page
Verify your settings and proceed to click Next step one more time.Figure 1.7 – The Zabbix installation finish page
You have successfully installed the Zabbix frontend. You may now click the Finish button and we can start using the frontend. You'll be served with a login page where you can use the following default credentials:Username: Admin
Password: zabbix
Now that we've installed our Zabbix frontend, our Zabbix setup is complete and we are ready to start working with it. Our Zabbix frontend will connect to our database to edit the configuration values of our setup, as we can see in the following figure:
Figure 1.8 – Zabbix setup communications diagram
The Zabbix frontend will also talk to our Zabbix server, but this is just to make sure the Zabbix server is up and running. Now that we know how to set up the Zabbix frontend, we can start using it. Let's check this out after the next recipe.
Zabbix provides a very convenient setup guide, which contains a lot of detail regarding the installation of Zabbix. I would always recommend keeping this page open during a Zabbix installation, as it contains information like the link to the latest repository. Check it out here:
https://www.zabbix.com/download
Zabbix 6 is here, with one of the most anticipated features of all time. High availability will bring your Zabbix setup to the next level by making sure that if one of your Zabbix servers is having issues, another one will take over.
A great thing about this implementation is that it supports an easy proprietary way to put one to many Zabbix servers in a cluster. A great way of making sure your monitoring stays in the air at all times (or at least as much as possible).
Now I do have to be honest, we cannot do anything like load balancing yet. But that is included on the Zabbix roadmap using the Zabbix proxies in a later version. Keep an eye out for any updates regarding that here:
https://www.zabbix.com/roadmap
Before getting started, please note that creating a high availability setup is considered an advanced topic. It might be more difficult than other recipes in this chapter.
For this setup, we will need three new virtual machines, as we are going to create a split Zabbix setup, unlike the setup that we created in the first recipe of this chapter. Let's take a look at how I have named our three new virtual machines and what their IP addresses will be:
lar-book-ha1 (192.168.0.1)lar-book-ha2 (192.168.0.2)lar-book-ha-db (192.168.0.10)Two of these servers will run our Zabbix server cluster and a Zabbix frontend. The other server is just for our MySQL database. Please take note that the IP addresses used in the example may be different for you. Use the correct ones for your environment.
We will also need a virtual IP address for our cluster nodes. We will use 192.168.0.5 in the example.
Tip
In our setup, we are using only one MySQL Zabbix database. For making sure all parts of Zabbix are set up as highly available, it might be worth looking into setting up MySQL in a master/master setup. This would be a great combination with the Zabbix server's high availability.
This cookbook will NOT use SELinux or AppArmor, so make sure to disable those or add the correct policies before using this guide. Additionally, this guide also does not detail how to set up your firewall, so make sure to do this beforehand as well.
For your convenience, we've split this How to do it… section into three parts. One is setting up the database, the other is setting up the Zabbix server cluster, and the last is how to set up the Zabbix frontend redundantly. The How it works… section will then provide an explanation about the entire setup.
Let's start with setting up our Zabbix database, ready to be used in a highly available Zabbix server setup:
Log in to lar-book-ha-db and install the MariaDB repository with the following command on RedHat based systems:wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
./mariadb_repo_setup
Then, let's install the MariaDB server application with the following command.For RHEL-based systems:
dnf install mariadb-server
systemctl enable mariadb
systemctl start mariadb
For Ubuntu systems:
apt install mariadb-server
systemctl enable mariadb
systemctl start mariadb
After installing MariaDB, make sure to secure your installation with the following command:/usr/bin/mariadb_secure_installation
Make sure to answer the questions with yes (Y) and configure a root password that's secure. It's highly recommended to use a password vault for storing it.Now let's create our Zabbix database for our Zabbix servers to connect to. Log in to MariaDB with the following command:mysql -u root -p
Enter the password you set up during the secure installation and create the Zabbix database with the following commands. Do not forget to change the password in the second, third, and fourth commands:create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@'192.168.0.1' identified by 'password';
create user zabbix@'192.168.0.2' identified by 'password';
create user zabbix@'192.168.0.5' identified by 'password';
grant all privileges on zabbix.* to 'zabbix'@'192.168.0.1' identified by 'password';
grant all privileges on zabbix.* to 'zabbix'@'192.168.0.2' identified by 'password';
grant all privileges on zabbix.* to 'zabbix'@'192.168.0.5' identified by 'password';
flush privileges;
quit
Lastly, we need to import the initial Zabbix database configuration, but for that, we need to install the Zabbix repository.For RHEL-based systems:
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
dnf clean all
For Ubuntu systems:
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu20.04_all.deb
dpkg -i zabbix-release_6.0-1+ubuntu20.04_all.deb
apt update
Then, we need to install the SQL scripts Zabbix module.For RHEL-based systems:
dnf install zabbix-sql-scripts
For Ubuntu systems:
apt install zabbix-sql-scripts
Then, we issue the following command, which might take a while so be patient until it is done:zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uroot -p zabbix
Setting up the cluster nodes works in the same way as setting up any new Zabbix server. The only difference is that we will need to specify some new configuration parameters.
Let's start by adding the Zabbix 6.0 repository to our systems lar-book-ha1 and lar-book-ha2:rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
dnf clean all
For Ubuntu systems, use the following command:
wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu20.04_all.deb
dpkg -i zabbix-release_6.0-1+ubuntu20.04_all.deb
apt update
Now let's install the Zabbix server application with the following command.For RHEL-based systems:
dnf install zabbix-server-mysql
For Ubuntu systems:
apt install zabbix-server-mysql
We will now edit the Zabbix server configuration files, starting with lar-book-ha1. Issue the following command:vim /etc/zabbix/zabbix_server.conf
Then, add the following lines to allow a database connection:DBHost=192.168.0.10
DBPassword=password
To enable high availability on this host, add the following lines in the same file:HANodeName=lar-book-ha1
To make sure our Zabbix frontend knows where to connect to if there is a node fail over, fill in the following:NodeAddress=192.168.0.1
Save the file and let's do the same for our lar-book-ha2 host by editing its file:vim /etc/zabbix/zabbix_server.conf
Then, add the following lines to allow a database connection:DBHost=192.168.0.10
DBPassword=password
To enable high availability on this host, add the following lines in the same file:HANodeName=lar-book-ha2
To make sure our Zabbix frontend knows where to connect to if there is a node fail over, fill in the following:NodeAddress=192.168.0.2
Save the file and let's start our Zabbix server:systemctl enable zabbix-server
systemctl start zabbix-server
To make sure our frontend is also set up in such a way that if one Zabbix server has issues it fails over, we will set them up with keepalived. Let's see how we can do this.
Let's start by logging in to both lar-book-ha1 and lar-book-ha2 and installing keepalived.For RHEL-based systems:
dnf install -y keepalived
For Ubuntu systems:
apt install keepalived
Then, on lar-book-ha1, edit the keepalived configuration with the following command:vim /etc/keepalived/keepalived.conf
Delete everything from this file and add the following text to the file:vrrp_track_process chk_apache_httpd {
process httpd
weight 10
}
vrrp_instance ZBX_1 {
state MASTER
interface ens192
virtual_router_id 51
priority 244
advert_int 1
authentication {
auth_type PASS
auth_pass password
}
track_process {
chk_apache_httpd
}
virtual_ipaddress {
192.168.0.5/24
}
}
Do not forget to update password to something secure and edit the interface ens192 to your own interface name/number. For Ubuntu, change httpd to apache2.Important Note
In the previous file, we specified virtual_router_id 51. make sure the virtual router ID 51 isn't used anywhere in the network yet. If it is, simply change the virtual router ID throughout this recipe.
On lar-book-ha2, edit the same file with the following command:vim /etc/keepalived/keepalived.conf
Delete everything from the file with dG and this time we will add the following information:vrrp_track_process chk_apache_httpd {
process httpd
weight 10
}
vrrp_instance ZBX_1 {
state BACKUP
interface ens192
virtual_router_id 51
priority 243
advert_int 1
authentication {
auth_type PASS
auth_pass password
}
track_process {
chk_apache_httpd
}
virtual_ipaddress {
192.168.0.5/24
}
}
Once again, do not forget to update password to something secure and edit the interface ens192 to your own interface name/number. For Ubuntu, change httpd to apache2.Now let's install the Zabbix frontend with the following command.For RHEL-based systems:
dnf install httpd zabbix-web-mysql zabbix-apache-conf
For Ubuntu systems:
apt install apache2 zabbix-frontend-php zabbix-apache-conf
Start the web server and keepalived to make your Zabbix frontend available with the following command:systemctl enable httpd keepalived
systemctl start httpd keepalived
Then, we are ready to configure our Zabbix frontend. Navigate to your virtual IP address (in the example IP case, http://192.168.0.5/zabbix) and you will see the following page:Figure 1.9 – The Zabbix initial configuration window
Click on Next step twice until you see the following page:Figure 1.10 – The Zabbix database configuration window for lar-book-ha1
Make sure to fill in Database host with the IP address of our Zabbix MariaDB database (192.168.0.10). Then, fill in the database password for our zabbix database user.Then, for the last step, for our first node, set up the Zabbix server name as lar-book-ha1 and select your time zone as seen in the following screenshot.Figure 1.11 – The Zabbix server settings window for lar-book-ha1
Then click Next step and Finish.Now we need to do the same thing to our second frontend. Log in to lar-book-ha1 and issue the following.On RHEL-based systems:
systemctl stop httpd
For Ubuntu systems:
systemctl stop apache2
When navigating to your virtual IP (in the example IP case, http://192.168.0.5/zabbix), you will see the same configuration wizard again.Fill out the database details again:Figure 1.12 – The Zabbix database configuration window for lar-book-ha2
Then make sure to set up the Zabbix server name as lar-book-ha2 as seen in the screenshot.Figure 1.13 – The Zabbix server settings window for lar-book-ha2
Now we need to reenable the lar-book-ha1 frontend by issuing the following.On RHEL-based systems:
systemctl start httpd
For Ubuntu systems:
systemctl start apache2
That should be our last step. Everything should now be working as expected. Make sure to check your Zabbix server log file to see if the HA nodes are running as expected.
Now that we have done it, how does the Zabbix server actually work in a high availability mode? Let's start by checking out the Reports | System information page in our Zabbix frontend.
Figure 1.14 – The Zabbix server system information with HA information
We can now see that we have some new information available. For example, the High availability cluster parameter. This parameter is now telling us if high availability is enabled or not and what the fail over delay is. In our case, this is 1 minute, meaning that it could take up to 1 minute before fail over is initiated.
Furthermore, we can see every single node in our cluster. As Zabbix now supports one to many nodes in a cluster, we can see every single one taking part in our cluster right here. Let's take a look at the setup we have built:
Figure 1.15 – The Zabbix server HA setup
As you can see in the setup, we have connected our two Zabbix server nodes lar-book-ha1 and lar-book-ha2 to our single Zabbix database lar-book-ha-db. Because our Zabbix database is our single source of truth, it can be used to keep our cluster configuration as well. In the end, everything Zabbix does is always kept in the database, from host configuration to history data to the high availability information. That's why building a Zabbix cluster is as simple as putting the HANodeName in the Zabbix server configuration file.
We also included the NodeAddress parameter in the configuration file. This parameter is used by the Zabbix frontend to make sure that our system information (widget) and Zabbix server are not running frontend notification work. The NodeAddress parameter will tell the frontend what IP address to connect to for each respective server once it becomes the active Zabbix server.
To take things a bit further, I have added a simple keepalived setup to this installation as well. Keepalived is a way to build simple VRRP fail over setups between Linux servers. In our case, we have entered the VIP as 192.168.0.5 and added the chk_apache_httpd process monitoring to determine when to fail over. Our fail over works as follows:
lar-book-ha1 has priority 244
lar-book-ha2 has priority 243
If HTTPd or Apache 2 is running on our node, that adds a weight of 10 to our priority, leading to the total priority of 254 and 253, respectively. Now let's imagine that lar-book-ha1 no longer has the web server process running. That means its priority drops to 244, which is lower than 253 on lar-book-ha2, which does have the web server process running.
Whichever host has the highest priority is the host that will have the VIP 192.168.0.5, meaning that host is running the Zabbix frontend which will be served.
Combining these two ways of setting up high availability, we have just created redundancy for two of the parts that make up our Zabbix setup, making sure we can keep outages to a minimum.
Now you may wonder, what if I wanted to go further in terms of setting up high availability. First, the Zabbix high availability feature is built to be simple and understandable to the entire Zabbix user base. Meaning that as of now, you might not see the same amount of features you would get with a third-party implementation.
Nevertheless, the new Zabbix server high availability feature has proved itself to be a long-awaited feature that really adds something to the table. If you want to run a high availability setup like this, the best way to add one more level of complexity to high availability is a MySQL master/master setup. Setting up the Zabbix database with high availability, which is the main source of truth, will make sure that your Zabbix setup really is reliable in as many ways as possible. For more information regarding MariaDB replication, check out the documentation here: https://mariadb.com/kb/en/standard-replication/.
If this is your first time using Zabbix, congratulations on getting to the UI. If you are a returning Zabbix user, there have been some changes to the Zabbix 6 UI that you might notice. We'll be going over some of the different elements that we can find in the Zabbix frontend so that during this book, you'll feel confident in finding everything you need.
To get started with the Zabbix UI, all we need to do is log in to the frontend. You will be served with the following page at the IP on which your server is running the Zabbix frontend:
Figure 1.16 – The Zabbix login screen
Make sure you log in to the Zabbix frontend with the default credentials:
Username: AdminPassword: zabbixTip
Just like in Linux, Zabbix is case-sensitive in most places. When entering your username, make sure to include the right cases; otherwise, you won't be able to log in!
After you log in, you'll be served with the default page, which is the default dashboard. This is what Zabbix has called Global view and it provides us with a nice overview of what's going on. We can completely customize this and all the other dashboards that Zabbix supplies, but it's a good idea to familiarize yourself with the default setup before building something new:
Figure 1.17 – The Global view dashboard
So, let's get