Building Zabbix for b2

A collection of tips on howto tweak your Bubba.
Post Reply
mountaindude
Posts: 57
Joined: 25 Aug 2007, 11:56

Building Zabbix for b2

Post by mountaindude » 03 Sep 2012, 06:12

Edit 1:
Added info on automatic startup of zabbix on boot.


Edit 2:
Looks like the scripts copied to /etc/init.d messed up things when running apt-get install... and similar commands. Adding INIT blocks fix this. Instructions below updated accordingly.


Ok, so I have a few more computers at home than most people, including a couple of always-on servers that deal with things like email and a home automation system that log environmental data as well as control lights etc. Things that I really want to be up and running 24/7.

After messing around with various monitoring solutions (I kind of like Monit for the simplicity of it, but it is also somewhat limited in what it can do) I figured it was time to go all in and set up a proper monitoring tool.

Nagios has been around for ever, but more recently lots of people speak well about Zabbix. Both would solve 99% of every monitoring problem you could think of, but for various reasons I went with Zabbix.

The big question was whether it would run on a b2. Turns out it does - at least if you don't mind waiting a few seconds for web pages to load. I don't usually fancy waiting, but still find it ok in this case, so it isn't that bad.

The easy way to get started is of course to sudo to root, then do an apt-get install zabbix-server.
Turns out that will give you a very old version. Plan B is to build from source.

Steps to build Zabbix from source on b2 (should work for b3 as well. Pls note that some minor steps might be missing, I am writing some of this from memory...):
------------

I have recently reinstalled my b2 with latest OS, but the locales were not properly set up. Fix this:

Code: Select all

apt-get install debconf
apt-get remove locales-all
apt-get install locales
dpkg-reconfigure locales
Get latest source code (at the time of this writing the latest version is 2.0.2, you should of course get the latest one). Install as root, a dedicated zabbix user will be created later.

Code: Select all

su
cd
mkdir code
cd code
wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.2/zabbix-2.0.2.tar.gz
Install dependencies. You may already have some of the below installed, in that case they will just be skipped.

Code: Select all

apt-get install build-essential mysql-server libmysqlclient15-dev php5 php5-gd php5-mysql snmp libsnmp-dev snmpd libcurl4-openssl-dev fping libiksemel3 libiksemel-dev 
Extract the source, configure & compile it

Code: Select all

tar xvf zabbix-2.0.2.tar.gz
cd zabbix-2.0.2
./configure --enable-server --enable-agent --with-mysql --with-libcurl --with-net-snmp --with-jabber --prefix=/root/code/zabbix-2.0.2 --sysconfdir=/usr/local/etc
make install

Zabbix is now installed, but need to be configured before it can be used

Code: Select all

mkdir /usr/share/zabbix/
cp -a ./frontends/php/* /usr/share/zabbix/
mv /usr/share/zabbix/conf/zabbix.conf.php.example /usr/share/zabbix/conf/zabbix.conf.php

Zabbix stores all configuration parameters etc in a database. In this case we're using MySql, but PostgreSQL and other dbs are also supported.
First, create a MySQL user for Zabbix. Pls refer to MySQL docs if unsure how this is done.
Next, edit Zabbix config file as follows (this will use the MySQL instance on the b2 itself)

Code: Select all

nano /usr/share/zabbix/conf/zabbix.conf.php

<?php
// Zabbix GUI configuration file
global $DB;

$DB["TYPE"]                             = 'MYSQL';
$DB["SERVER"]                   = 'localhost';
$DB["PORT"]                             = '3306';
//$DB["PORT"]                           = '0';
$DB["DATABASE"]                 = 'zabbix';
$DB["USER"]                             = 'zabbix';
$DB["PASSWORD"]                 = '<ZabbixPwdHere>';
// SCHEMA is relevant only for IBM_DB2 database
$DB["SCHEMA"]                   = '';

$ZBX_SERVER                             = 'localhost';
$ZBX_SERVER_PORT                = '10051';
$ZBX_SERVER_NAME                = '';

$IMAGE_FORMAT_DEFAULT   = IMAGE_FORMAT_PNG;
?>

Start MySQL client to set up the db there

Code: Select all

mysql -u'zabbix' -p'<ZabbixPwdHere>'
mysql> create database zabbix character set utf8;
mysql> quit;
Set up the db schema and set access rights to it

Code: Select all

cd  database/mysql
cat schema.sql | mysql -u'zabbix' -p'<ZabbixPwdHere>' zabbix
cat images.sql | mysql -u'zabbix' -p'<ZabbixPwdHere>' zabbix
cat data.sql | mysql -u'zabbix' -p'<ZabbixPwdHere>' zabbix

mysql -e"grant all privileges on zabbix.* to zabbix@localhost identified by '<ZabbixPwdHere>';"
mysql -u'zabbix' -p'<ZabbixPwdHere>'
FLUSH PRIVILEGES;
quit;



Edit services config file, add to the /etc/services file

Code: Select all

nano /etc/services
zabbix-agent 10050/tcp Zabbix Agent
zabbix-agent 10050/udp Zabbix Agent
zabbix-trapper 10051/tcp Zabbix Trapper
zabbix-trapper 10051/udp Zabbix Trapper

Binaries should now be in /usr/local/sbin, if not copy them there.
Also, copy Zabbix init.d scripts to proper location

Code: Select all

cp /root/code/zabbix-2.0.2/sbin/* /usr/local/sbin
cp /root/code/zabbix-2.0.2/misc/init.d/debian/* /etc/init.d
Modify /etc/init.d/zabbix-server and /etc/init.d/zabbix-agent so they begin as follows. Just add the following at the beginning of each file, leave the rest of the files as they were.
/etc/init.d/zabbix-server:

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides: zabbix-server
# Required-Start: 
# Required-Stop: 
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Zabbix Server
# Description: Zabbix server
### END INIT INFO
/etc/init.d/zabbix-agent:

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides: zabbix-agent 
# Required-Start:
# Required-Stop: 
# Default-Start: 2 3 4 5 
# Default-Stop: 0 1 6
# Short-Description: Zabbix Server
# Description: Zabbix server
### END INIT INFO 

Copy Zabbix server and agent config files to proper location (note: Zabbix 2.x use /usr/local/etc rather than /etc/zabbix, as described here)

Code: Select all

cp -r conf/* /usr/local/etc
Configure MySQL parameters in usr/local/etc/zabbix_server.conf. Options to configure are DBHost, DBUser and DBPassword. No editing needed in /etc/zabbix/zabbix_agentd.conf

Code: Select all

nano usr/local/etc/zabbix_server.conf

Create zabbix Linux user, add to admin group.

Code: Select all

adduser zabbix
enter in new password & confirm

adduser zabbix admin

Almost there. Start the daemons and check log files for errors

Code: Select all

/etc/init.d/zabbix-server start
/etc/init.d/zabbix-agent star

tail -n 25 /tmp/zabbix_server.log

Time to set up the web UI

Code: Select all

mkdir /home/zabbix/public_html
cp -R frontends/php/* /home/zabbix/public_html/

nano /etc/apache2/sites-enabled/000-default
(Enter into this file)

Alias /zabbix /home/zabbix/public_html/
<Directory /home/zabbix/public_html>
  AllowOverride FileInfo AuthConfig Limit Indexes
  Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
  <Limit GET POST OPTIONS PROPFIND>
    Order allow,deny
    Allow from all
  </Limit>
  <LimitExcept GET POST OPTIONS PROPFIND>
    Order deny,allow
    Deny from all
  </LimitExcept>
</Directory>
Adjust php.ini and update as needed, time zone names available here.

Code: Select all

nano /etc/php5/apache2/php.ini

max_execution_time = 300 ; Maximum execution time of each script, in seconds
date.timezone = <YourTimezoneHere>
Restart Apache

Code: Select all

sudo /etc/init.d/apache2 restart
Open a web browser, go to http://<serverip>/zabbix. You should now see a "Welcom to Zabbix 2.0 setup" screen.
The web based setup complained about max_input_time and post_max_size php options being too low. Increase them as needed, then restart apache again to make the changes take effect.

You should now be able to log in with username=Admin, pwd=zabbix


Assuming you got this far - this is where the fun begins. Zabbix is EXTREMELY customizable. There are plenty of online resources for doing this, with the forums and wiki at www.zabbix.com being useful starting points.


Finally, you might want to change so that the Zabbix daemon and agent starts automatically at boot.
The convenient little rcconf utility let you do that in a menu driven way.


Good luck!


There wasn't any perfect guide for all of the above online, the following ones were helpful though:
http://sigign.blogspot.se/2011/05/insta ... ueeze.html
http://www.zabbix.com/wiki/howto/instal ... ntuinstall
http://tipstricks.itmatrix.eu/?p=407
Last edited by mountaindude on 07 Sep 2012, 17:35, edited 4 times in total.

theWebalyst
Posts: 96
Joined: 27 May 2010, 14:53

Re: Building Zabbix for b2

Post by theWebalyst » 03 Sep 2012, 06:38

I set Zabbix on my b3 up a while ago and had it monitoring some websites and test monitoring some of my local network.

I gather it is very capable, but it is a nightmare trying to understand how to configure.

Not for the faint hearted!

Sounds like you are well acquanted with this kind of stuff.

Good luck!

Mark

mountaindude
Posts: 57
Joined: 25 Aug 2007, 11:56

Re: Building Zabbix for b2

Post by mountaindude » 03 Sep 2012, 07:03

theWebalyst wrote: I gather it is very capable, but it is a nightmare trying to understand how to configure.
Agreed, in particular the terminology used in Zabbix is a bit unusual at times, but I was pretty much up to speed after a few hours of google-supported configuration. Not too bad for such a powerful platform I'd say.

mountaindude
Posts: 57
Joined: 25 Aug 2007, 11:56

Re: Building Zabbix for b2

Post by mountaindude » 06 Sep 2012, 04:34

Just got my B3 yesterday, and it looks like the repos only contain Zabbix 1.8 for the B3 platform.
Thus, for now you'll need to build from source if you want to use the latest and greatest Zabbix (2.0.2) on your B3.

/Göran

Post Reply