Server installation and configuration
Here we will explain how to install and configure the Zabbix server, along with the prerequisites.
To get started with this chapter, we need a properly configured server, with a Red Hat 6.x or 7.x 64-bit OS installed or a derivate such as CentOS. The book was written with version 6 but the commands have been updated for version 7, where needed.
It is possible to get the installation working on other distributions such as SUSE, Debian, Ubuntu, or another Linux distribution, but in this book I will be focusing on Red Hat based systems. I feel that it's the best choice for this book as the OS is not only available for big companies willing to pay Red Hat for support, but also for those smaller companies that cannot afford to pay for it, or for those just willing to test it or run it with community support. Other distros like Debian, Ubuntu, SUSE, OpenBSD will work fine too but the book would end up all cluttered with different kinds of setups for each distro. It is possible to run Zabbix on 32-bit systems, but I will only focus on 64-bit installations as 64-bit is probably what you will run in a production setup. However if you want to try it on 32-bit system, it is perfectly possible with the use of the Zabbix 32-bit binaries.
The following steps will guide you through the server installation process:
- The first thing we need to do is add the Zabbix repository to our package manager on our server so that we are able to download the Zabbix packages to set up our server. To find the latest repository, go to the Zabbix webpage www.zabbix.com and click on Product | Documentation then select the latest version. At the time of this writing, it is version 2.4.
- From the manual, select option 3 Installation, then go to option 3 Installation from packages and follow instructions to install the Zabbix repository. For Zabbix 2.4.x, it will appear like this:
Now that our Zabbix repository is installed, we can continue with our installation. For our Zabbix server to work, we will also need a database for example: MySQL, PostgreSQL, Oracle and a web server for the frontend such as Apache, Nginx, and so on. In our setup, we will install Apache and MySQL as they are better known and easiest to set up. We will later see some alternatives in our book and how to install our server in a distributed way, but for now let's just keep things simple.
The following steps will show you how to install the MySQL server and the Zabbix server with a MySQL connection:
Tip
In this book, we make use of MySQL because it is what most people know best and use most of the time. It is also easier to set up than PostgreSQL for most people. However, a MySQL DB will not shrink in size. It's probably wise to use PostgreSQL instead, as PostgreSQL has a housekeeper process that cleans up the database. However, in very large setups this housekeeper process of PostgreSQL can at times also be the problem of slowness. When this happens, a deeper understanding of how housekeeper works is needed.
MySQL will come and ask us some questions here so make sure you read the next lines before you continue:
- For the MySQL secure installation, we are being asked to give the current root password or press Enter if you don't have one. This is the root password for MySQL and we don't have one yet as we did a clean installation of MySQL. So you can just press Enter here.
- Next question will be to set a root password; best thing is of course, to set a MySQL root password. Make it a complex one and store it safe in a program such as KeePass or Password Safe.
- After the root password is set, MySQL will prompt you to remove anonymous users. You can select Yes and let MySQL remove them.
- We also don't need any remote login of root users, so best is to disallow remote login for the root user as well.
- For our production environment, we don't need any test databases left on our server. So those can also be removed from our machine and finally we do a reload of the privileges.
You can now continue with the rest of the configuration by configuring our database and starting all the services. This way we make sure they will come up again when we restart our server:
Tip
Depending on the speed of your machine, importing the schema could take some time (a few minutes). It's important to not mix the order of the import of the SQL files!
- Now let's edit the Zabbix server configuration file and add our database settings in it:
- Let's start our Zabbix server and make sure it will come online together with the MySQL database after reboot:
On RHEL 7 this will be:
- Check now if our server was started correctly:
The output would look something like this:
If no errors where displayed in the log, your zabbix-server
is online. In case you have errors, they will probably look like this:
In this case, go back to the zabbix_server.conf
file and check the DBHost
, DBName
, DBUser
, and DBPassword
parameters again to see if they are correct.
The only thing that needs to be done is editing the firewalld. Add the following line in the /etc/sysconfig/iptables
file under the line with dport 22
. This can be done with vi or Emacs or another editor such as: the vi /etc/sysconfig/iptables
file. If you would like to know more about iptables have a look at the CentOS wiki (link provided in See also section).
People making use of RHEL 7 have firewall and need to run following commands instead.
- Now that this is done, you can reload the firewall. The Zabbix server is installed and we are ready to continue to the installation of the agent and the frontend.
Always check if the ports 10051
and 10050
are also in your /etc/services
file both server and agent are IANA registered.
The installation we have done here is just for the Zabbix server and the database. We still need to add an agent and a frontend with a web server.
The Zabbix server will communicate through the local socket with the MySQL database. Later, we will see how we can change this if we want to install MySQL on another server than our Zabbix server.
The Zabbix server needs a database to store its configuration and the received data, for which we have installed a MySQL database. Remember we did a create database
and named it zabbix
? Then we did a grant on the zabbix
database and we gave all privileges on this database to a user with the name zabbix
with some free to choose password <some-safe-password>
. After the creation of the database we had to upload three files namely schema.sql
, images.sql
, and data.sql
. Those files contain the database structure and data for the Zabbix server to work. It is very important that you keep the correct order when you upload them to your database. The next thing we did was adjusting the zabbix_server.conf
file; this is needed to let our Zabbix server know what database we have used with what credentials and where the location is.
The next thing we did was starting the Zabbix server and making sure that with a reboot, both MySQL and the Zabbix server would start up again.
Our final step was to check the log file to see if the Zabbix server was started without any errors and the opening of TCP port 10051
in the firewall. Port 10051
is the port being used by Zabbix active agents to communicate with the server. In Chapter 4, we will go deeper and understand the difference of active and passive agents. For now just remember, an agent can be either active or passive in Zabbix.
We have changed some settings for the communication with our database in the /etc/zabbix/zabbix_server.conf
file but there are many more options in this file to set. So let's have a look at which are the other options that we can change. Some of them will probably sound like a foreign language to you but don't worry, it will all become more clear later in this book.
The following URL gives us an overview of all supported parameters in the zabbix_server.conf
file:
https://www.zabbix.com/documentation/2.4/manual/appendix/config/zabbix_server.
You can start the server with another configuration file so you can experiment with multiple configuration settings. This can be useful if you like to experiment with certain options. To do this, run the following command where the <config file>
file is another zabbix_server.conf
file than the original file: