15 October 2016

Zabbix with MySQL on Ubuntu 16

Thanks to this post by thedutchlab.com and the official docs.

Install required packages

  1. Apache:
    apt-get install libapache2-mod-php7.0 php
  2. Install the missing php packages required on Ubuntu 16/php7:
    apt-get install php7.0-mbstring
    apt-get install php7.0-bcmath
    apt-get install php-xmlwriter
  3. MySQL: See previous post
    apt-get install php-mysql
  4. Zabbix
    apt-get install zabbix-server-mysql zabbix-frontend-php

Create the Database

  1. Refer to my previous post about creating MySQL databases.
  2. Change to the sql directory and unzip the files:
    cd /usr/share/zabbix-server-mysql/
    sudo gunzip *.gz
  3. Install them:
    mysql -u zabbix -p zabbix < schema.sql
    It will prompt for password then take a while
    mysql -u zabbix -p zabbix < images.sql
    mysql -u zabbix -p zabbix < data.sql
  4. Edit the zabbix config (see below)

Modify PHP

post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = "Europe/London"

Modify Zabix Config

  1. Edit the Zabbix Config to add the DB User/Pasword:
    vi /etc/zabbix/zabbix_server.conf
    Set DBPassword
  2. Edit the Zabbix php configuration:
    cp /usr/share/doc/zabbix-frontend-php/examples/zabbix.conf.php.example /etc/zabbix/zabbix.conf.php
    vi /etc/zabbix/zabbix.conf.php
    Set the database PASSWORD
  3. Copy the zabbix apache conf to apache.available:
    cp /usr/share/doc/zabbix-frontend-php/examples/apache.conf /etc/apache2/conf-available/zabbix.conf
    cd /etc/apache2/conf-available/
    a2enconf zabbix.conf
    a2enmod alias
    service apache2 restart
  4. Edit the Zabbix configuration:
    vi /etc/default/zabbix-server

Modify the php file for php7

You'll get an error about always_populate_raw_post_data but this is deprecated below php 7
  1. vi /usr/share/zabbix/include/classes/setup/CFrontendSetup.php
  2. Find the line: if (version_compare(PHP_VERSION, '5.6'
  3. Change to: if (version_compare(PHP_VERSION, '7.1'

Re-Start the Services

sudo service zabbix-server restart
sudo service apache2 restart

Install Agent on Minions

  1. apt-get update
    apt-get install zabbix-agent
  2. vi /etc/zabbix/zabbix_agentd.conf
    Amend Server=localhost replacing the IP address of your Zabbix install
  3. /etc/init.d/zabbix-agent start

Load the web Interface

wget http://localhost/zabbix

Default username/password: Admin/zabbix


Test PHP

  1. vi /var/www/html/test.php
  2. http://<host IP>/test.php
    Should Return: PHP Version 7.0.8-0ubuntu0.16.04.3... etc
  3. Try it in the zaabix directory:
    cp /var/www/html/test.php /usr/share/zabbix/test.php
  4. Turn on display errors:
    vi /etc/php/7.0/cli/php.ini
    display_errors        on
  5. Restart apache

Output PHP errors:

Wrap your error-ing script in a try catch:
     // existing code
} catch(Error $e) {
     echo $e->getMessage();

Also can try outputting error log to file:
error_log = /var/log/php_errors.log
touch the file:
touch /var/log/php_errors.log
chown www-data: /var/log/php_errors.log
chmod +rw /var/log/php_errors.log
tail /var/log/php_errors.log

Zabbix Server Log

vi /var/log/zabbix-server/zabbix_server.log

Also Check

  • Apache errors: /var/log/apache2/error.log
  • Error 500: Probably a problem with apache-php
  • Error 404: Re-check the installation steps, you have missed something as the web server/site doesn't exist.
  • If it's giving php errors like: Minimum required size of PHP post is 16M then check the php.ini file: if it has any syntax errors it will revert to defaults:
    cp /usr/lib/php/7.0/php.ini-production vi/etc/php/7.0/apache/php.ini

No comments:

Post a Comment