





















































In this article by Patrik Uytterhoeven, author of the book Zabbix Cookbook, we will see the following topics:
(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.
Here we will explain how to install and configure the Zabbix server, along with the prerequisites.
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.
The following steps will guide you through the server installation process:
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.
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:
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!
# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<some-safe-password>
# 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
# 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
# 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.
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.
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>
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.
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.
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.
# yum install zabbix-agent
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
# firewall-cmd --permanent --add-port=10050/tcp
# 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.
# 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.
# service zabbix-agent start # systemctl start zabbix-agent (if you use RHEL 7)
# chkconfig zabbix-agent on # systemctl enable zabbix-agent (for RHEL 7 users)
# tail /var/log/zabbix/zabbix_agentd.log
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.
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.
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.
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.
# yum install zabbix-web zabbix-web-mysql
# chkconfig httpd on; service start httpd # systemctl start httpd; systemctl enable httpd (for RHEL 7)
# -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:
# iptables-save # service iptables restart # firewall-cmd --reload (If you run RHEL 7)
# vi /etc/httpd/conf.d/zabbix.conf php_value date.timezone Europe/Brussels
# reboot
# http://<ip of the Zabbix server>/zabbix
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.
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.
Further resources on this subject: