Zabbix

Introduction
Zabbix is able to monitor your applications, network and servers.

After installation, Zabbix supports checks of ~100 network protocols. Further protocol checks can be added using shell-, C- or perl-scripts. Zabbix understands SNMP. It can create graphs of network-, cpu- or harddisk-load, and so on. Many of these checks are done with agent software which is available for many platforms including Linux, Solaris, AIX, HP-UX, BSD, Windows, and Mac OS. Different views of a network can be defined for checks and documentation.

Prerequisites
Zabbix can use a number of database backends. This HOWTO focuses on using Zabbix with MySQL (HOWTO MySQL), but you can also use PostgreSQL or Oracle.

The only frontend currently available for Zabbix is the PHP-based web frontend, so you'll need a PHP compatible web server, such as Apache2 or lighttpd.

At present, Zabbix 1.8.x is still listed in the unstable branch on Gentoo, as such, you will need to add some keywords, and of course since this is Gentoo, you will need to add a few USE flags

Use Flags
Much of the USE flag information is directly from Zabbix's wiki; however, this is not an exhaustive listing of all available use flags for these packages.

When selecting USE flag for the database, select exactly one database type out of these: mysql oracle postgres sqlite3

MySQL (dev-db/mysql)


 * : This provides support for berkley DB, which, while not required for Zabbix is very much recommended for MySQL and PHP.
 * : Adds some extra engines to mysql, for zabbix the most useful one would be the partitions which allow you to split up a table into multiple files based on some criteria, very useful for logging tables.
 * : Make tables contain up to 1.844E+19 rows instead of the normal limit of 2^32 rows, if you expect allot of logs or otherwise the data in zabbix to become large this flag may be useful.

TODO: Add appropriate flags for oracle / postgres / sqlite3

PHP (dev-lang/php)


 * : Tells PHP to build the mod_php support.
 * : Zabbix needs this.
 * : Tells PHP to use Berkeley DB for non MySQL bindings
 * : Tells PHP to support file compression. This is optional, but I recommend it.
 * : This tells PHP to support graphics creation. This is required by Zabbix for maps, graphs, and SLA support.
 * : Tells PHP to add support for GDBM. Not required, but helpful to have, just in case.
 * : This tells PHP to add support for MySQL and is required to use Zabbix UI, if you are using MySQL database.
 * : This adds support for Perl Compatible Regular Expressions. Not required yet, but strongly recommend for compatibility with future features for Zabbix.
 * : This adds readline support. Not really needed unless you plan to learn to write PHP.
 * : This adds session support. This is a must. If this is left out, MySQL servers melt under load as multiple people look through Zabbix data and graphs.
 * : This adds SSL support for PHP. There are various patches out there for Zabbix that take advantage of this, but Zabbix itself does not require this. The Zabbix team recommends using it.
 * : See session above.
 * : This adds tokenization support. Not required yet, but strongly recommend for compatibility with future features for Zabbix. When needed, it will be very helpful if you ever want to dig through Zabbix and customize it.
 * : This add unicode support. It is not really required if you are going to run Zabbix in English mode, but if you plan to use other languages it is required.
 * : This adds basic XML parsing support to PHP and is required by Zabbix 1.4.x
 * & : For Zabbix version 2.0 these modules are required and are separate from the xml USE flag.
 * : This provides basic deflate and gzip support to PHP which improves performance of your web server, so I recommend adding it.

If you intend to use SQLite3, also enable these:


 * :This adds support for SQLite(2).
 * :This is needed to extend SQLite support also for SQLite3.

Apache (www-servers/apache)


 * : This forces Apache to be compiled with Apache 2 compliance. Not needed, but it is recommended.
 * : This provides SSL support, again, not needed, but recommended.
 * : This tells Apache to support threads as well. Without this, PHP will be unable to support threads or sessions. See warning above, under sessions

SNMP (net-analyzer/net-snmp)


 * : This provides a perl API into SNMP.
 * : This provides support for SNMPv2 and SNMPv3, as such it is required if you wish to support those versions.

Zabbix (net-analyzer/zabbix)


 * : Installs the monitoring agent.
 * : Enables support for checking content on homepages.
 * : Installs the web frontend for Zabbix.
 * : Support for IPv6 addressing
 * : Enables support for notices sent via Jabber.
 * : LDAP support for login.
 * : Allows MySQL database support for use with the Zabbix server.
 * : Intelligent Platform Management Interface specification, a standard which defines a set of common interfaces to a computer system which system administrators can use to monitor system health and manage the system.
 * : Allows Oracle database support for use with the Zabbix server.
 * : Allows PostgreSQL database support for use with the Zabbix server.
 * : Installs the Zabbix polling server.
 * : Allows the Zabbix server to poll devices using SNMP. It is recommended to use this as it provides useful features.
 * : Allows SQLite version 3 database support for use with the Zabbix server.
 * : Allows the Zabbix server to poll devices using SSH.
 * : This gives the Zabbix frontend virtual server support.

Install and Configure the Required Packages
Unless this is a brand new install of Gentoo, you will most likely need to re-emerge some of your packages to properly support any changes you make above to your use flags. To do this, simply execute the following command as root;

Once that is complete, we can emerge Zabbix. To emerge Zabbix, please execute the following command;

At this point, we have all of the key components we need to get Zabbix working. Now we need to configure the system to use it. If you already have MySQL up and running you can skip the next part, likewise, if you already have Apache up and hosting PHP, you can skip the Apache portion.

MySQL
When you emerge MySQL, you get the binaries, however, the database is non-existent. In this section, we will get MySQL ready to accept the Zabbix Database, but we will not install the Zabbix Database just yet.

If you were to run the command, it will print out something similar to the following;

MySQL datadir is empty or invalid Please check your my.cnf : /etc/mysql/my.cnf

This means that MySQL has been installed, but that it is missing the MySQL data directory. We can create that with the following command;

At this point the database is now ready and we can move on to the next part. Configuring Apache to support PHP.

Apache
The first thing we need to do is configure Apache to support PHP. By Default, Apache will only load modules if it is told to do so at run time. We do this by passing defines to the start script. Under Gentoo, this is handled by the file.

When you edit this file, you will find a line that looks something like the following:

If you are using PHP5, you will change it to look like this:

PHP5
We need to edit. This file contains various PHP configuration information and some basic directives that are callable within PHP. For our needs, we will just focus on the configuration options needed by Zabbix.

The first option to check on is the engine option. By default, this will be set to On, however, I have seen some people's systems where this was set to off. If off, please set this to on, or Apache will never be able to call PHP.

The next option is max_execution time. By default this is set to 30 seconds, and for most sites, this will be sufficient, if they wish to use Zabbix 1.1.x, however, for large deployments and Zabbix 1.3.x / 1.4.x, this period is simply too low, especially when deal with tens of thousands of triggers. Zabbix 1.3.x requires this value to be set 300+ seconds, personally, I recommend doubling that.

The next option that we are concerned with is a bit of a gotcha. By default PHP is configured to use only 8M RAM for script and script memory, which is fine if you are only planning to generate single items graphs, or list out a couple hundred items, however, once you try to go over 4 items in a graph, or list out 3K+ items, PHP will begin crashing. Alexei recommend setting this value to no less than 32M, personally, I recommend setting this to 128M, assuming you can spare that much of course. The option for this is memory_limit.

Finally, we want to limit the number of links from the UI to the DB. The option mysql.max_links is set to -1 by default. Instead we want to change to this to 3x the number of users who will be on the system at any one time.

Preparing Database, Frontend, And Server
There are three main steps in this part, installing the schema / data, configuring the UI, and finally configuring the Zabbix server.

Create the database
Perform the following on your database of choice. The instructions here are for MySQL; however, installation for other databases are very similar. Zabbix ships with .sql files to create the schema and populate it with data for us, so just use the corresponding files like we do in the following examples.

To create the database and create a Zabbix user with necessary permissions in the Zabbix DB:

mysql> CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; mysql> USE zabbix; mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by ' '; mysql> flush privileges; mysql> quit

When emerging zabbix with the } USE flag, portage placed a copy of the Schema file in. Now that we have our user and DB created, let's load the schema:

Edit /etc/mysql/my.cnf

There are a couple settings that need to be changed from Gentoo's default. The first is the bin log rotation setting. It is not rotated by default, and can quickly fill up your partition. The bin logs keep track of all actions that may change data (INSERT, UPDATE, DELETE, etc) and are primarily used to restore the database after a corruption (see the MySQL binary log documentation for more info). To delete the log every two days, add the following line to under the mysqld section. Though not recommended, some users forgo the previous step and turn off the bin log completely. If you feel the logs are unnecessary then comment out the log-bin line.

The other setting that needs to be changed is the InnoDB data file size. Be careful at modifying these values, specially if you have other applications using InnoDB. Before modifying these values, have a look at Adding, Removing, or Resizing InnoDB Data and Log Files.

After a few days, this will lead to errors with the data history and graphs. Your requirements may vary, but replacing the above with the following should be sufficient.

(Note: You may have to remove either or both ibdata1 or ibdata2 to get MySQL to work after changing the above line.) Credit for tracking down the above fix belongs to http://jon.netdork.net/2005/11/09/argh-table-full-1114/ For additional information read http://dev.mysql.com/doc/refman/5.0/en/innodb-configuration.html You may want to change the max size setting to fit your installation.

Configure the Web Interface
Install the Zabbix frontend in a vhost:

For example:

Will install zabbix under (host admin, directory zabbix).

In the directory where Zabbix has been installed, copy into  and modify the parameters to suit your needs.

Zabbix requires that PHP be configured in a specific way. Edit

And restart Apache so that it sees these changes.

You should now be able to get to a login screen under http://$vhost/$dir. The initial credentials are 'Admin' and zabbix as a password.

Updated: If you for some reasons don't want to change default config, you can do that in a very intelligent way - put the file .htaccess in /zabbix/ folder on web:

dont forget to change timezone, etc..

Configure the Zabbix Server
Now we need to configure the Zabbix server daemon to use the new schema. When we emerged the zabbix-server, it created a new directory called. Inside this directory is the file we want to edit next,. This file tells the Zabbix server daemon various things it needs to run, and most importantly how to connect to the database. The following parameters should be changed:

Configure Fping
Finally, we need to configure fping, so that Zabbix can use it. To do this, execute the following commands:

Next, tell the Zabbix server daemon where to find fping in the file:

Start Zabbix
On all machines you wish to monitor, you need to modify the files in. In particular, you need to point the Server= line to the IP address of the server where you are running the Zabbix server. In addition, each client running zabbix-agentd needs to have its hostname defined to a unique value (usually the simple hostname, fully qualified hostnames break remote command functionality).

Furthermore, the ListenIP=127.0.0.1 should be commented out on all clients where the server and front end are not running locally.

Add the daemons to the default runlevel

On all machines:

On the Zabbix server machine:

Start them

In case mysql and apache2 have not started, start them:

If everything works, set the daemons to start automatically on reboot:

User-Defined Monitored Parameters
Users can define their own monitored parameters in. You can check the the output of a zabbix item with zabbix_get. For example, to see if sshd is running, you should issue the following command:

To use the parameters below, just copy and paste them into your and restart zabbix-agentd.

Apache Webserver
You can monitor the apache webserver using the examples below. All of them require mod_status (it comes with apache by default and its trivial to enable).

Alternatively, you could get the values from apache status page at once, improving performance. See this post in zabbix forums.

Troubleshooting

 * server running: To make sure Zabbix is working, start by looking at the Reports page from the top menu. The "ZABBIX Server is running" line should say "YES". If it doesn't, try the command 'rc-status' and make sure zabbix-server is listed as 'started'. If not, try '/etc/init.d/zabbix-server start'.
 * ssh: If zabbix wrongly reports ssh is not running, make sure you have "ListenAddress 127.0.0.1" in as zabbix tries to connect to 127.0.0.1.
 * apache: If zabbix wrongly reports apache is not running, it could be the case that the apache process has the name of apache2 instead of the zabbix default httpd. Change the item configuration from  proc.num[httpd]  to  proc.num[apache2] .