18 min read

In this article by Patrik Uytterhoeven, author of the book Zabbix Cookbook, we will see the following topics:

  • Server installation and configuration
  • Agent installation and configuration
  • Frontend installation and configuration

(For more resources related to this topic, see here.)

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

It is possible to get the installation working on other distributions such as SUSE, Debian, Ubuntu, or another Linux distribution, but I will be focusing on Red Hat based systems. I feel that it’s the best choice 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. 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.

    Zabbix Configuration

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.

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

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 zabbix@localhost 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

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

    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.

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

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.

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>

See also

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

Getting ready

To be successful with this installation, you need to have installed the Zabbix server. 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.

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

    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:

    Zabbix 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:

    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 but could be done with not too much extra work and would make Zabbix more safe. http://wiki.centos.org/HowTos/Https.

    Zabbix Configuration

  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:

    Zabbix Configuration

  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:

    Zabbix Configuration

  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:

    Zabbix Configuration

  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:

    Zabbix Configuration

Summary

In this article we saw how to install and configure Zabbix server, Zabbix agent, and web interface. We also learnt the commands for MySQL server and the Zabbix server with a MySQL connection. Then we went through the installation and configuration of Zabbix agent. Further we learnt to install the Zabbix web frontend packages and installing the firewall packages.

Finally the we saw the steps for installation and configuration of Zabbix through screenshots. By learning the basics of Zabbix, we can now proceed with this technology.

Resources for Article:


Further resources on this subject:


LEAVE A REPLY

Please enter your comment!
Please enter your name here