Zabbix Cookbook

4.3 (4 reviews total)
By Patrik Uytterhoeven
  • Instant online access to over 8,000+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Zabbix Configuration

About this book

This book will teach you the skills required to successfully set up and configure a Zabbix server. We will guide you through the interface setup and explain all the features available in Zabbix.

You will begin with learning the Zabbix installation and configuration steps in detail, and then move on to exploring its interface and architecture. You will then work with groups, users, and permissions. The book will then take you through monitoring and testing with Zabbix. Followed by this, you will gain insights into using templates, and also create impressive graphs and maps for data visualization and reporting. Towards the end of the book, you will learn how to maintain, upgrade, and troubleshoot your Zabbix infrastructure.

Publication date:
March 2015
Publisher
Packt
Pages
260
ISBN
9781784397586

 

Chapter 1. Zabbix Configuration

In this chapter we will cover the following topics:

  • Server installation and configuration

  • Agent installation and configuration

  • Frontend installation and configuration

  • Installing Zabbix from source

  • Installing the server in a distributed setup

 

Introduction


We will begin with the installation and configuration of a Zabbix server, Zabbix agent, and web interface. We will make use of our package manager for the installation. Not only will we show you how to install and configure Zabbix, we will also show you how to compile everything from source. We will also cover the installation of the Zabbix server in a distributed way.

 

Server installation and configuration


Here we will explain how to install and configure the Zabbix server, along with the prerequisites.

Getting ready

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.

How to do it...

The following steps will guide you through the server installation process:

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

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

Tip

There is a bit of a controversy around MySQL that was acquired by Oracle some time ago. Since then, most of the original developers left and forked the project. Those forks have also made major improvements over MySQL. It could be a good alternative to make use of MariaDB or Percona. In Red Hat Enterprise Linux (RHEL) 7.x, MySQL has been replace already by MariaDB.

http://www.percona.com/.

https://mariadb.com/.

http://www.zdnet.com/article/stallman-admits-gpl-flawed-proprietary-licensing-needed-to-pay-for-mysql-development/.

The following steps will show you how to install the MySQL server and the Zabbix server with a MySQL connection:

# yum install mysql-server zabbix-server-mysql
# yum install mariadb-server zabbix-server-mysql (for RHEL 7)
# service mysqld start
# systemctl start mariadb.service (for RHEL 7)
# /usr/bin/mysql_secure_installation

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:

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

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

  3. After the root password is set, MySQL will prompt you to remove anonymous users. You can select Yes and let MySQL remove them.

  4. We also don't need any remote login of root users, so best is to disallow remote login for the root user as well.

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

# mysql -u root -p

mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to [email protected] identified by '<some-safe-password>';
mysql> exit;

# cd /usr/share/doc/zabbix-server-mysql-2.4.x/create
# mysql -u zabbix -p zabbix < schema.sql
# mysql -u zabbix -p zabbix < images.sql
# mysql -u zabbix -p zabbix < data.sql

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!

  1. Now let's edit the Zabbix server configuration file and add our database settings in it:

    # vi /etc/zabbix/zabbix_server.conf
    DBHost=localhost
    DBName=zabbix
    DBUser=zabbix
    DBPassword=<some-safe-password>
  2. Let's start our Zabbix server and make sure it will come online together with the MySQL database after reboot:

    # service zabbix-server start
    # chkconfig zabbix-server on
    # chkconfig mysqld on
    

    On RHEL 7 this will be:

    # systemctl start zabbix-server
    # systemctl enable zabbix-server
    # systemctl enable mariadb
    
  3. Check now if our server was started correctly:

    # tail /var/log/zabbix/zabbix_server.log
    

    The output would look something like this:

    # 1788:20140620:231430.274 server #7 started [poller #5]
    # 1804:20140620:231430.276 server #19 started [discoverer #1]

    If no errors where displayed in the log, your zabbix-server is online. In case you have errors, they will probably look like this:

      1589:20150106:211530.180 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)
      1589:20150106:211530.180 database is down: reconnecting in 10 seconds

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

    # -A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT
    

    People making use of RHEL 7 have firewall and need to run following commands instead.

    # firewall-cmd --permanent --add-port=10051/tcp
    
  4. 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.

    # service iptables restart
    # firewall-cmd --reload (For users of RHEL 7)
    

    Always check if the ports 10051 and 10050 are also in your /etc/services file both server and agent are IANA registered.

How it works...

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.

There's more...

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:

zabbix_server -c <config file>
 

Agent installation and configuration


In this section, we will explain you the installation and configuration of the Zabbix agent. The Zabbix agent is a small piece of software about 700 KB in size. You will need to install this agent on all your servers to be able to monitor the local resources with Zabbix.

Getting ready

In this recipe, to get our Zabbix agent installed, we need to have our server with the Zabbix server up and running as explained in Server installation and configuration. In this setup, we will install our agent first on the Zabbix server. We just make use of the Zabbix server in this setup to install a server that can monitor itself. If you monitor another server then there is no need to install a Zabbix server, only the agent is enough.

How to do it...

Installing the Zabbix agent is quite easy once our server has been set up. The first thing we need to do is install the agent package.

Installing the agent packages can be done by running yum as we have already added the repository to our package manager in the previous recipe Server installation and configuration. In case you have skipped it, then go back and add the Zabbix repository to your package manager.

  1. Install the Zabbix agent from the package manager:

    # yum install zabbix-agent
    
  2. Open the correct port in your firewall. The Zabbix server communicates to the agent if the agent is passive. So, if your agent is on a server other than Zabbix, then we need to open the firewall on port 10050. (We shall further explain active and passive agents in Chapter 4).

  3. Edit the firewall, open the file /etc/sysconfig/iptables and add the following after the line with dport 22 in the next line:

    # -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
    
  4. Users of RHEL 7 can run:

    # firewall-cmd --permanent --add-port=10050/tcp
    
  5. Now that the firewall is adjusted, you can restart the same:

    # service iptables restart
    # firewall-cmd --reload (if you use RHEL 7)
    

    The only thing left to do is edit the zabbix_agentd.conf file, start the agent, and make sure it starts after a reboot.

  6. Edit the Zabbix agent configuration file and add or change the following settings. We will see later in Chapter 4 the difference between active and passive; for now just fill in both variables.

    # vi /etc/zabbix/zabbix_agentd.conf
    Server=<ip of the zabbix server>
    ServerActive=<ip of the zabbix server>
    

    That's all for now in order to edit in the zabbix_agentd.conf file.

  7. Now, let's start the Zabbix agent:

    # service zabbix-agent start
    # systemctl start zabbix-agent (if you use RHEL 7)
    
  8. And finally make sure that our agent will come online after a reboot:

    # chkconfig zabbix-agent on
    # systemctl enable zabbix-agent (for RHEL 7 users)
    
  9. Check again that there are no errors in the log file from the agent:

    # tail /var/log/zabbix/zabbix_agentd.log
    

How it works...

The agent we have installed is installed from the Zabbix repository on the Zabbix server, and communicates to the server on port 10051 if we make use of an active agent. If we make use of a passive agent, then our Zabbix server will talk to the Zabbix agent on port 10050. Remember that our agent is installed locally on our host; so all communication stays on our server. This is not the case if our agent is installed on another server instead of our Zabbix server. We have edited the configuration file from the agent and changed the Server and ServerActive options. Our Zabbix agent is now ready to communicate with our Zabbix server. Based on the two parameters we have changed, the agent knows what the IP is from the Zabbix server.

The difference between passive and active modes is that the client in passive mode will wait for the Zabbix server to ask for data from the Zabbix agent.

The agent in active mode will ask the server first what it needs to monitor and pull this data from the Zabbix server. From that moment on, the Zabbix agent will send the values by itself to the server at regular intervals.

So when we use a passive agent the Zabbix server pulls the data from the agent where a active agent pushes the data to the server.

We did not change the hostname item in the zabbix_agentd.conf file, a parameter we normally need to change and give the host a unique name. In our case the name in the agent will already be in the Zabbix server that we have installed, so there is no need to change it this time.

There's more...

Just like our server, the agent has a plenty more options to set in its configuration file. So open the file again and have a look at what else we can adjust. In the following URLs you will find all options that can be changed in the Zabbix agent configuration file for Unix and Windows:

https://www.zabbix.com/documentation/2.4/manual/appendix/config/zabbix_agentd.

https://www.zabbix.com/documentation/2.4/manual/appendix/config/zabbix_agentd_win.

 

Frontend installation and configuration


In this recipe, we will finalize our setup with the installation and configuration of the Zabbix web interface. Our Zabbix configuration is different from other monitoring tools such as Nagios in the way that the complete configuration is stored in a database. This means, that we need a web interface to be able to configure and work with the Zabbix server. It is not possible to work without the web interface and just make use of some text files to do the configuration. It is however possible to work with the API, but that is something we will see later in Chapter 10.

Getting ready

To be successful with this installation, you need to have installed the Zabbix server, as explained previously. It's not necessary to have the Zabbix client installed but it is recommended. This way, we can monitor our Zabbix server because we have a Zabbix agent running on our Zabbix server. This can be useful in monitoring your own Zabbix servers health status, as we will see later.

How to do it...

  1. The first thing we need to do is go back to our prompt and install the Zabbix web frontend packages.

    # yum install zabbix-web zabbix-web-mysql
    
  2. With the installation of our Zabbix-web package, Apache was installed too, so we need to start Apache first and make sure it will come online after a reboot:

    # chkconfig httpd on; service start httpd
    # systemctl start httpd; systemctl enable httpd (for RHEL 7)
    
  3. Remember we have a firewall, so the same rule applies here. We need to open the port for the web server to be able to see our Zabbix frontend. Edit the /etc/sysconfig/iptables firewall file and add after the line with dport 22 in the next line:

    # -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
    

    Tip

    If iptables is too intimidating for you, then an alternative could to make use of Shorewall. http://www.cyberciti.biz/faq/centos-rhel-shorewall-firewall-configuration-setup-howto-tutorial/.

    Users of RHEL 7 can run the following lines:

    # firewall-cmd --permanent --add-service=http
    

    The following screenshot shows the firewall configuration:

  4. Now that the firewall is adjusted, you can save and restart the firewall:

    # iptables-save
    # service iptables restart
    # firewall-cmd --reload (If you run RHEL 7)
    
  5. Now edit the Zabbix configuration file with the PHP setting. Uncomment the option for the timezone and fill in the correct timezone:

    # vi /etc/httpd/conf.d/zabbix.conf
    php_value date.timezone Europe/Brussels
    
  6. It is now time to reboot our server and see if everything comes back online with our Zabbix server configured like we intended it to. The reboot here is not necessary but it's a good test to see if we did a correct configuration of our server:

    # reboot
    
  7. Now let's see if we get to see our Zabbix server. Go to the URL of our Zabbix server that we just have installed:

    # http://<ip of the Zabbix server>/zabbix
    
  8. On the first page, we see our welcome screen. Here, we can just click Next:

    Tip

    The standard Zabbix installation will run on port 80, although It isn't really a safe solution. It would be better to make use of HTTPS. However, this is a bit out of the scope of this book but could be done with not too much extra work and would make Zabbix more safe. http://wiki.centos.org/HowTos/Https.

  9. Next screen, Zabbix will do a check of the PHP settings. Normally they should be fine as Zabbix provides a file with all correct settings. We only had to change the timezone parameter, remember? In case something goes wrong, go back to the zabbix.conf file and check the parameters:

  10. Next, we can fill in our connection details to connect to the database. If you remember, we did this already when we installed the server. Don't panic, it's completely normal. Zabbix, as we will see later, can be setup in a modular way so the frontend and the server both need to know where the database is and what the login credentials are. Press Test connection and when you get an OK just press Next again:

  11. Next screen, we have to fill in some Zabbix server details. Host and port should already be filled in; if not, put the correct IP and port in the fields. The field Name is not really important for the working of our Zabbix server but it's probably better to fill in a meaningful name here for your Zabbix installation:

  12. Now our setup is finished, and we can just click Next till we get our login screen. The Username and Password are standard the first time we set up the Zabbix server and are Admin for Username and zabbix for the Password:

How it works...

For the frontend, we had to install the web interface package from our Zabbix repository. For the web interface to work, we had to install a web server; one of the dependencies of Zabbix is the Apache web server. It is possible that in other repositories, this is not the case, so always make sure that Apache or some other web server is installed. The installed frontend is written in PHP.

To be able to connect to the web interface from another system, we had to open the firewall port on our Zabbix server, this was port 80.

Because the Zabbix setup can be modular, the frontend needs to know the location, the username and password of the database, and also the location of the Zabbix server and the correct port the Zabbix server communicates through. Normally, the standard port of the Zabbix server is 10051 and in our case everything is installed locally so localhost can be used.

If you make use of SELinux, you need to alter some of its settings or else, Zabbix will not work. Either you disable SELinux completely in the /etc/selinux/config file by replacing the SELINUX=enforcing parameter to SELINUX=permissive parameter. Once this is done, you run from the command line setenforce 0. Another option is to configure SELinux and this is the safest way. This can be done by running the following commands from the prompt:

setsebool -P zabbix_can_network on   (for the agent)
setsebool -P httpd_can_network_connect  on  (for the server)
setsebool -P httpd_can_network_connect_db  on (for the server)

There's more...

Of course there is more to the frontend that can be tweaked. In case we want to edit the frontend configuration, it can be done under the /usr/share/zabbix/include/defines.inc.php file.

Here is a list of the most important things that can be altered. A complete list can be found in the Zabbix online documentation.

https://www.zabbix.com/documentation/2.4/manual/web_interface/definitions.

Parameter

Option

ZBX_LOGIN_ATTEMPTS

Number of login attempts before ZBX_LOGIN_BLOCK is activated

ZBX_LOGIN_BLOCK

Number of seconds to wait after too many login attempts

ZBX_MIN_PERIOD

Min zoom period for graphs

ZBX_MAX_PERIOD

Max zoom period for graphs

ZBX_PERIOD_DEFAULT

Default graph period in seconds

GRAPH_YAXIS_SIDE_DEFAULT

Default side for the Y axis; can be changed from left to right

ZBX_WIDGET_ROWS

Popup row limit

ZBX_UNITS_ROUNDOFF_THRESHOLD

Threshold value for roundoff constants

ZBX_UNITS_ROUNDOFF_UPPER_LIMIT

Number of digits after comma, when value is greater than roundoff threshold

ZBX_UNITS_ROUNDOFF_LOWER_LIMIT

Number of digits after comma, when value is less than roundoff threshold

ZBX_HISTORY_DATA_UPKEEP

Number of days, which will reflect on frontend choice when deciding which history or trends table to process

 

Installing Zabbix from source


We will now show you how to install Zabbix from source. Remember that for production, it's always better to install from the Zabbix repository or another repository such as Extra Packages for Enterprise Linux (EPEL). First of all, it will make your life easier when you want to upgrade but also when you want to remove some software. Maintainers of Zabbix packages in repositories such as EPEL are always in contact with Zabbix developers and improving the packages. If you compile it by yourself, chances are that you will miss something and will have to do it over later when your setup is already in production.

So why compile, you would think. Well if you can't wait for the latest and greatest new features then it can be a good thing to compile Zabbix in a test environment and try it out. Also, if you or some customer is in high need of one of the new features, it can be an option but then you really have to know what you are doing. Performance can also be a consideration.

Tip

If you consider compiling from source, take a checklist with you that lists all options that you need.

Getting ready

To get started with our compilation, we need of course, an operating system and the Zabbix source code. In this case, I will show you how to compile on Red Hat or CentOS 6.x.

For our setup we will need a local working MySQL server with a working Zabbix database and a web server properly configured.

Note

You can also look in the Zabbix online manual under Installation | Installation from sources. https://www.zabbix.com/documentation/2.4/manual/installation/install.

How to do it...

  1. First we download the Zabbix source code which can be obtained from the Zabbix website. When going to download, click on download again; Zabbix stable source is the first on top. Save the file in the /usr/src folder.

  2. Next thing of course, is the extraction of the tar.gz file we have downloaded. This can be done with tar. For example:

    # tar -zxvf zabbix-2.4.x.tar.gz
    
  3. We now have a folder that contains the Zabbix source code. For example: the /usr/src/zabbix-2.4.x folder.

  4. We need to install Apache, MySQL, PHP, and some other libraries for our server. This can be done with:

    # yum install httpd php php-mysql php-bcmath php-mbstring php- gd php-xml mysql mysql-server -y
    

    Tip

    Zabbix supports the following versions: MySQL 5.03 or higher, PostgreSQL 8.1 or higher, Apache 1.3.12 or higher, PHP 5.3 or higher. A full list can be found here:

    https://www.zabbix.com/documentation/2.4/manual/installation/requirements.

  5. We also need a user and a group for the Zabbix server to run as since we don't want to run our server as root. So we will create a group and a user Zabbix first:

    # groupadd zabbix
    # useradd -g zabbix zabbix
    
  6. To be able to start the compilation process, we need to install some extra packages on our system before we can begin, of course:

    # yum install gcc mysql-devel libxml2-devel net-snmp-devel curl-devel unixODBC-devel OpenIPMI-devel libssh2-devel iksemel-devel openldap-devel
    
  7. For some packages you probably have to add the EPEL repository to your setup. https://fedoraproject.org/wiki/EPEL.

  8. To get a list of all options supported when compiling we have to run next command in the extracted folder:

    # ./configure --help
    
  9. To compile the sources for a Zabbix server, you could run something like the following line. Options depend on your installation:

    # ./configure --enable-server --enable-agent --with-mysql -- enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 -- with-openipmi --with-unixodbc --with-ssh2 --with-ldap --with- jabber
    
  10. If finished correctly, you will get a message telling you to run 'make install' now. If you get an error, you probably have to install a missing development library. The last line will tell you what is missing:

    # make install
    
  11. The compiler will be running for sometime depending on the speed of your system; just let it run till it stops. It will stop after sometime and when there are no errors at the end, your Zabbix server will be compiled.

  12. You need to configure database connection settings, and so on. just like we did with the installation from the Zabbix server from package. The standard location of the configuration files and the Zabbix server can be found under:

    # /usr/local/etc/ → Zabbix configuration files
    # /usr/local/sbin/ → Zabbix server
    

    Tip

    If you want to change the location of the Zabbix server installation you could make use of the –prefix=/PATH option when compiling.

    If you have issues don't forget to disable SELinux or better still, put proper SELinux permissions.

    The -j option can be used to speed up compiling when running make on a multicore computer such as make -j 4.

    http://stackoverflow.com/questions/414714/compiling-with-g-using-multiple-cores.

  13. As you probably have noticed, there are no init scripts when you compile from source. This is something you will have to create by yourself. Or you could use the ones provided by Zabbix. Those can be found under the /usr/src/zabbix-2,4,x/misc/init.d file.

  14. Now we also need to install the Zabbix frontend. The most easiest way is to copy the files into a sub directory of the HTML root:

    # mkdir /var/www/html/zabbix
    # cd /usr/src/zabbix-2.4.x/frontends/php
    # cp -a . /var/www/html/zabbix
    # chown -R –no-dereference apache:apache /var/www/html/zabbix
  15. Best is to create a zabbix.conf file for Apache in the /etc/httpd/conf.d/ folder:

    <Directory "/var/www/html/zabbix">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    
        php_value max_execution_time 300
        php_value memory_limit 128M
        php_value post_max_size 16M
        php_value upload_max_filesize 2M
        php_value max_input_time 300
        php_value date.timezone Europe/Brussels
    </Directory>

How it works...

The downloaded source code from Zabbix will be extracted first in a folder. To be able to run the Zabbix server as a standard user and not as root, we need to create a group and a user. In this case, we added a group zabbix and created a user zabbix and linked the user to the same group.

We then downloaded the development libraries and our gcc compiler so that we were able to compile the Zabbix server from the source code.

The same thing can be done for the Zabbix agent and the Zabbix proxy, except that only other compiling options are needed.

There's more...

Since Zabbix 2.2, there is the possibility to monitor virtual machines in VMware. For this to work, it is necessary to give the --with-libxml2 option when compiling, else this functionality will not work.

When compiling an agent, we can make use of the same source code we have downloaded for the compilation of the Zabbix server. The only thing we need to do now, is launch.

# ./configure --enable-agent

When compiling fails, chances that you are missing some development libraries for one of the new options you have added are great. If you are not sure what option has caused this, then it can make sense to remove some options and start over. Later if compiling works, you can then add the new options again, one by one, to see where it fails. Zabbix also provides a URL with information on how to install from source:

https://www.zabbix.com/documentation/2.4/manual/installation/install.

 

Installing the server in a distributed setup


Next, we will see how to install the Zabbix server in a distributed way. This means that we will install all three components on different servers. In big setups, this can be a win as the frontend, Zabbix server, and database will have their own hardware.

Getting ready

For this setup to work, we need three machines, all with the latest version from Red Hat 6.x or CentOS 6.x with proper host name resolution, either by Domain Name System (DNS) or by host file. In this setup, I will talk about the setup of the server, db, and frontend. This time, we will disable SELinux on all machines as it is slightly more complicated and out of the scope of this book.

How to do it...

  1. First thing to do is add on every host the Zabbix repository from Zabbix like we have done with our server installation. Remember the repository can be found in the Zabbix installation manual under installation from package.

  2. On the DB server we install, of course, the MySQLserver:

    # yum install  mysql-server
    # service mysqld start
    # /usr/sbin/mysql_secure_installation (same options as before)
    # chkconfig mysqld on
    
  3. Open the firewall on the database server and disable SELinux on all servers:

    # iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp -- dport 3306 -j ACCEPT
    # iptables save
    # service iptables restart
    # vi /etc/selinux/config
    
  4. Change the next value to permissive:

    # SELINUX=permissive
    
  5. Reboot the database server so that SELinux is disabled or type from the prompt:

    # setenforce 0
    
  6. Next thing we do is create our database and grant rights to it. When granting rights, don't forget to give rights to the Zabbix user from the Zabbix server as our connection is not alone from localhost but also from the server:

    # mysql -u root -p
    mysql> create database zabbix character set utf8 collate utf8_bin;
    mysql> grant all privileges on zabbix.* to [email protected] identified by 'some_password';
    mysql> grant all privileges on zabbix.* to [email protected] identified by 'some_password';
    mysql> grant all privileges on zabbix.* to [email protected] identified by 'some_password';
    mysql> exit
    
  7. Next thing we have to do is upload the correct schemas for the Zabbix installation. For this, we have to copy the schemas from the Zabbix server or install the zabbix-mysql-server package:

    # cd /usr/share/doc/zabbix-server-mysql-2.4.x/create
    # mysql -uroot zabbix < schema.sql
    # mysql -uroot zabbix < images.sql
    # mysql -uroot zabbix < data.sql
    
  8. Now on the server, install the Zabbix server:

    # yum install zabbix-server zabbix-server-mysql
    # chkconfig zabbix-server on
    
  9. Edit the Zabbix server configuration file:

    # vi /etc/zabbix/zabbix_server.conf
    DBHost=<ip of the db>
    DBName=zabbix
    DBUser=zabbix
    DBPassword=<some password>
    #DBSocket=/var/lib/mysql/mysql.sock (put this in comment) DBPort=3306
    
  10. Start the Zabbix server and check the log file if there are no errors logged:

    # service zabbix-server start
    # tail /var/log/zabbix/zabbix_server.log
    
  11. Open port 10051 on the firewall:

    # iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp -- dport 10051 -j ACCEPT
    # iptables save
    # service iptables restart
    
  12. Install the frontend on the server:

    # yum install zabbix-web-mysql
    # chkconfig httpd on
    
  13. Uncomment the timezone value and replace Riga with your location:

    # vi /etc/httpd/conf.d/zabbix.conf
    php_value date.timezone Europe/Riga
    
  14. Open port 80 on the firewall:

    # iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp -- dport 80 -j ACCEPT
    # iptables save
    # service iptables restart
    # service httpd start
    
  15. Now let's open our browser and go to the frontend server:

    # http://frontend/zabbix
    

    After the first screens with the PHP option check if we get our screen with the connection settings for the database. Fill in the name or IP of our DB server with the DB name, username, and password:

    Test the connection to the database, in case of problems, you could try to connect from the shell:

    # mysql -h <db ip> -u<username> -p<password> <db name>
    

    Or try to telnet

    # telnet <db ip> <port>  EX: telnet 192.168.1.5 3306
    

    When the connection tests are fine you can just click Next. This will bring us to the connection screen of the server as you can see in next screenshot.

  16. In the location of hostname, we have to fill in the hostname of our Zabbix server. The port is the port the server uses for the communication. Remember we have opened it in our firewall before? The port 10051 is the standard port but can be changed in the zabbix_server.conf file in case you want to change this:

    For the name, we can give anything that makes sense for our setup. Now when we click Next, our Zabbix server is up and running and we can log in with the standard login and password: Admin / zabbix.

How it works...

Our Zabbix server, database and frontend are all installed on different servers. Because the database needs to be able to communicate with our server we had to open port 3306 in our firewall and grant the permissions, so that the server and frontend had rights to connect to our database.

The Zabbix server communicates on port 10051, so for the server, we had to open this port in the firewall on the Zabbix server.

Our frontend needs a web server so Apache was installed automatically when we installed the Zabbix package. To be able to see the Zabbix frontend, we had to open port 80 in the firewall.

As the frontend is not aware that we have installed a distributed setup we had to tell the frontend that our database was installed on another location and the same was done for the Zabbix server:

There's more...

For the port of the database we did not put in 3306 port but 0. This way Zabbix knows that we have used the standard port. In case you changed it in your setup, you have to add the correct port instead of 0.

In case you edit the /etc/httpd/conf.d/zabbix.conf configuration file instead of making changes from the web interface, make sure that you don't remove the 0. If the port is empty, the configuration will not work.

Another issue occurs if Zabbix itself is down. Some companies make use of a small extra Zabbix server that monitors the Zabbix server. This is an easy, not too expensive option.

The setup of Zabbix as a virtual machine is also an option. Just make sure that the database in that case is on dedicated storage as a virtualized database on shared storage is not a good idea.

Yet another solution could be to build a cluster. The Zabbix server itself does not support a cluster setup but it can be done manually. There are several guides on how to do this available on the www.zabbix.org webpage.

About the Author

  • Patrik Uytterhoeven

    Patrik Uytterhoeven has over 16 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 training and public demonstrations around the world, from Belgium to 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, both published by Packt Publishing.

    Browse publications by this author

Latest Reviews

(4 reviews total)
Zelfde als voorgaande. ,.
It allows you to see book's sample pages quite well
Good book, decently illustrated for its difficulty level.

Recommended For You

Book Title
Access this book, plus 8,000 other titles for FREE
Access now