Sunday, July 8, 2012

Install Zabbix 2.0.1 server from source on Ubuntu Server usingPostgreSql

Sunday, July 08, 2012 Posted by Andre Broers , , ,
For my Home network (one dual core esxi server with 9 Linux instances and 1 windows xp instance) I'm in need of a good service monitor. My choice is Zabbix. But after installing from the ubuntu packages I discovered it was a fairly old version at this moment. Time to install from source.

First some decissions I prefer

I create a single ubuntu server virtual machine for this installation. It is called mon01 (from monitor). I prefer PostgreSql above MySql so that is my preferred database and luckily Zabbix can deal with it. Although I have a separate database virtual machine for PostgreSql I prefer to have my complete monitor service on a single virtual machine. The only exception I make is for the frontend which I will install on my Nginx/PHP web virtual machine, but it can simply be installed on the same mon01 virtual machine. Also I like to install my own software builds to install in the home directory of the user that builds it. I create a user for zabbix and when I configure I will give it a prefix in the home directory of the user zabbix. Just to keep the distro clean.

Let's start

The first thing to do is install the dependencies that zabbix needs to build. Luckily this are all default ubuntu packages.
sudo apt-get install build-essential postgresql libpq-dev snmp libsnmp-dev snmpd libcurl4-openssl-dev fping libiksemel3 libiksemel-dev libssh2-1-dev libopenipmi-dev

After this create a new user to run the zabbix environment.
sudo adduser zabbix

Now switch to this new user.
sudo su - zabbix

Get the latest source from the zabbix website: (zabbix-2.0.1.tar.gz)

Extract the source.

tar zxvpf zabbix-2.0.1.tar.gz

Now it is time to create the postgres database. First logout the zabbix user and than switch to the postgres user.

broersa@mon01:~$ sudo su - postgres
postgres@mon01:~$ psql -U postgres
psql (9.1.4)
Type "help" for help.

postgres=# create user zabbix with password 'xxxx';
postgres=# create database zabbix owner zabbix;
postgres=# \q

 Now we need to edit the following file to set the postgresql access for user zabbix.

 vi /etc/postgresql/9.1/main/pg_hba.conf

 Add the following two lines at the start of the file:

local   zabbix  zabbix  md5
host    zabbix  zabbix  md5

replace the ip address with the address of the frontend server.

Now we need to bounce the postgres server. Execute the following as a superuser:

sudo service postgresql restart

You can test your connection to the server by logging in as the postgres user and connect to the zabbix database:

broersa@mon01:~$ sudo su - postgres
postgres@mon01:~$ psql -U zabbix zabbix
Password for user zabbix:
psql (9.1.4)
Type "help" for help.

zabbix=> \q

When this succeeds we can continue to create and fill the database schema:

sudo su - postgres

cd ~zabbix/zabbix-2.0.1/database/postgresql/

cat schema.sql | psql -U zabbix zabbix
cat images.sql | psql -U zabbix zabbix
cat data.sql | psql -U zabbix zabbix

Now we can switch back to the zabbix user and start building the code:

sudo su - zabbix
cd zabbix-2.0.1
./configure --prefix=/home/zabbix/server --enable-server --enable-ipv6 --with-postgresql --with-jabber --with-libcurl --with-net-snmp --with-ssh2 --with-openipmi
make install

Now we have the server part in ~zabbix/server and the configuration file in ~zabbix/server/etc/zabbix/zabbix_server.conf

Edit this file and set the database settings.

The last step to get the server running is creating an start stop file so the server is started automaticly at a reboot.

First thing to do is create the file /etc/init.d/zabbixserver :

sudo vi /etc/init.d/zabbixserver

Add the following:

# Starts and stops zabbix_agentd

case "$1" in

        start-stop-daemon --start --exec ~zabbix/server/sbin/zabbix_server



        start-stop-daemon --stop --exec ~zabbix/server/sbin/zabbix_server

        $0 stop
        $0 start

             if pidof -o %PPID ~zabbix/server/sbin/zabbix_server > /dev/null; then
                     echo "Running"
                     exit 0
                     echo "Not running"
                     exit 1

        echo "Usage: $0 {start|stop|restart|status}"
        exit 1

Change the mode of the file and take care that it will get started at system boot. It will automatically get started as the zabbix user.

sudo chmod 755 /etc/init.d/zabbixserver
sudo update-rc.d zabbixserver defaults

 To start the server execute the following:

sudo service zabbixserver start

You can view the log in /tmp

This is the server part, in my next posts I will cover the agents and the frontend.