Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

||||||||||||||||||||

xii Preface

Bold: Indicates a new term, an important word, or words that you see onscreen. For
example, words in menus or dialog boxes appear in the text like this: "Then we navigate to
Monitoring | Hosts and click on Latest data for the Zabbix server host."

Tips or important notes


Appear like this.

Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book
title in the subject of your message and email us at customercare@packtpub.com.
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, selecting your
book, clicking on the Errata Submission Form link, and entering the details.
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 copyright@packt.com 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.

Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about
our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.

||||||||||||||||||||
||||||||||||||||||||

Preface xiii

Whether you are a real Zabbix guru or if you've just started working with Zabbix, this
book will include some recipes for everyone. We are going over most of the Zabbix basics
and we are even doing some cool stuff with the Zabbix API in the book.
We decided to write this book because we want to supply you with the Zabbix information
available online and in official Zabbix training in a clear and straightforward way. We've
all been through the process of bookmarking all these amazing community blog posts,
community guides, and even official documentation. Sometimes it can be a bit much,
which is where this book will help. See it as a guide with something for everyone without
the need to Google until your fingers fall off.
Now, even if you are experienced, or have finished this and maybe other books and you've
bookmarked every useful page about Zabbix, you might still not know everything. This is
where we come in. Zabbix is a free product built on an amazing open source community,
but besides that, there are some real Zabbix gurus out there that have decided to make
a living out of it. Our company, Opensource ICT Solutions, comes from these humble
beginnings and we are there to provide our customers with everything they need when it
comes to Zabbix. As a Premium Zabbix partner, we provide the following services:

• Official Zabbix training


• Official Zabbix support
• Zabbix consultancy
• Helpdesk services

So, if you've enjoyed this book, please do think about us and others in our amazing Zabbix
community. Give us a follow on LinkedIn (and other social media) and if you ever need
help, give us a call! We will definitely be ready to help you out with any questions you
might run into.
Brian van Baekel – Founder of Opensource ICT Solutions

WEB: https://oicts.com
EMAIL ADDRESS: info@oicts.com
PHONE: +1-929-377-1253 or +31(0)72 743 65 83

||||||||||||||||||||
||||||||||||||||||||

||||||||||||||||||||
||||||||||||||||||||

1
Getting Started with
Zabbix and User
Management
There have been quite a few changes to the Zabbix UI since 4.4 and earlier in this Zabbix
5 release. This book has been written completely with Zabbix 5, but while reading, you'll
find some information detailing the differences between 4 and 5.
In this chapter, we will 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 actually and once you get the hang of it, I am confident you will find your way
without issues.

||||||||||||||||||||
||||||||||||||||||||

2 Getting Started with Zabbix and User Management

We will also work on creating our first user groups, users, and some advanced user
authentication as a bonus. This way, we will make sure we have a structured Zabbix
setup before continuing on with this book. You will learn all about these subjects in the
following recipes:

• Installing the Zabbix server


• Setting up the Zabbix frontend
• Using the Zabbix frontend
• Navigating the Zabbix frontend
• Creating user groups
• Creating your first users
• Advanced user authentication with SAML

Technical requirements
We'll be starting this chapter with a server that has already been set up. There are a lot
of guides out there detailing how to install a Zabbix server, so if you're not familiar with
doing so, make sure to get started with that first. You can find more information about the
installation here: https://www.zabbix.com/download.
So, before diving into this chapter, make sure you have the following set up:

• A Zabbix server installed from the precompiled Zabbix packages on a Linux


distribution of your choice. I recommend CentOS or Ubuntu, but a distribution
such as Debian or any other will suit you just as well. We'll be using CentOS
throughout the book.
• MariaDB set up to work with your Zabbix server. PostgreSQL is fine as well.
• NGINX or Apache set up to serve the Zabbix frontend.
• A working Zabbix agent to monitor the Zabbix server.

Installing the Zabbix server


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 5.

||||||||||||||||||||
||||||||||||||||||||

Installing the Zabbix server 3

Getting ready
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 an
RHEL- or Debian-based distribution. I'll be installing CentOS 8 and Ubuntu 20 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.

How to do it…
1. Let's start by adding the Zabbix 5.0 repo to our system.
For RHEL-based systems, use the following:
rpm -Uvh https://repo.zabbix.com/zabbix/4.5/rhel/8/
x86_64/zabbix-release-4.5-2.el8.noarch.rpm
dnf clean all

For Debian-based systems, use the following:


wget https://repo.zabbix.com/zabbix/4.5/ubuntu/pool/
main/z/zabbix-release/zabbix-release_4.5-1+focal_all.deb
dpkg -i zabbix-release_4.5-1+focal_all.deb
sudo apt update

2. Now that the repo is added, let's install MariaDB on our server.
For RHEL-based systems, use the following:
dnf install mariadb-server
systemctl enable mariadb
systemctl start mariadb

For Debian-based systems, use the following:


apt-get install mariadb-server
systemctl enable mariadb
systemctl start mariadb

||||||||||||||||||||
||||||||||||||||||||

4 Getting Started with Zabbix and User Management

3. After installing MariaDB, make sure to secure your installation with the
following command:
sudo /usr/bin/mysql_secure_installation

4. Run through the secure installation setup and make sure to remember
your password.
5. Now, let's install our Zabbix server with MySQL support.
For RHEL-based systems, use the following:
dnf install zabbix-server-mysql
systemctl enable mariadb
systemctl start mariadb

For Debian-based systems, use the following:


apt-get install zabbix-server-mysql
systemctl enable mariadb
systemctl start mariadb

6. With the Zabbix server installed, we are ready to create our Zabbix database.
Log in to MariaDB with the following:
sudo mysql -u root -p

7. Enter the password you set up during the secure installation and create the Zabbix
database with the following:
create database zabbix character set utf8 collate utf8_
bin;
grant all privileges on zabbix.* to zabbix@localhost
identified by 'password';
flush privileges;
quit

8. Now we need to import our Zabbix database scheme to our newly created
Zabbix database:
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz |
mysql -u zabbix -p zabbix

||||||||||||||||||||
||||||||||||||||||||

Installing the Zabbix server 5

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 at our MariaDB side and are ready to move on to
the next step, which will be configuring the Zabbix server:

1. 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

2. Now, edit the following lines in the file:


DBName=zabbix
DBPassword= password

Tip
Before starting the Zabbix server on a CentOS 8 machine, you should configure
SELinux to allow the use of the Zabbix server. If this is a test machine, you can
use a permissive stance for SELinux, but it might not be smart to use this
in production.

3. All done; we are now ready to start our Zabbix server:


systemctl enable zabbix-server
systemctl start zabbix-server

4. Check whether everything is starting up as expected with the following:


systemctl status zabbix-server

5. Alternatively, monitor the log file, which provides a detailed description of the
Zabbix startup process:
tail -f /var/log/zabbix/zabbix_server.log

||||||||||||||||||||
||||||||||||||||||||

6 Getting Started with Zabbix and User Management

How it works…
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 server
• Apache or NGINX running the Zabbix frontend with PHP 7.2+

We 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.

Setting up the Zabbix frontend


The Zabbix frontend is the face of our server. It's where we will configure all of our hosts,
templates, dashboard, maps, and everything else. Without it, we would be blind to what's
going on on the server side, so let's set it up in this recipe.

||||||||||||||||||||
||||||||||||||||||||

Setting up the Zabbix frontend 7

Getting ready
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.

How to do it…
1. Let's start by installing PHP to our server with the following command.
For RHEL-based systems, use the following:
dnf install php

For Debian-based systems, use the following:


apt-get install php

2. We will need to edit our PHP configuration to use the correct time zone; otherwise,
the Zabbix frontend will not show us the right time values.
For RHEL-based systems, use the following:
vim /etc/php-fpm.d/zabbix.conf

For Debian-based systems, use the following:


vim /etc/zabbix/apache.conf

3. Now, uncomment the following line and set the right time zone for you.
For RHEL-based systems, use the following:
; php_value[date.timezone] = Europe/Riga

For Debian-based systems, use the following:


# php_value date.timezone Europe/Riga

4. Make sure that Apache is installed onto your server with the following.
For RHEL-based systems, use the following:
dnf install httpd

For Debian-based systems, use the following:


apt-get install apache2

Technet24
||||||||||||||||||||

You might also like