Skip to content

Instantly share code, notes, and snippets.

@AvasDream
Last active August 16, 2018 11:31
Show Gist options
  • Save AvasDream/bd72ad56531950c6bf167bd349b6cb63 to your computer and use it in GitHub Desktop.
Save AvasDream/bd72ad56531950c6bf167bd349b6cb63 to your computer and use it in GitHub Desktop.
Install Zabbix on Raspberry Pi with apache2/mysql

Raspberry Pi 3 Hardware Setup:

Burn Raspbian Lite to micro SD using dd if=/patch/tp/image of=/path/to/sd/card bs=512 if you are on windows use Etcher. Raspbian Image Download

First configuration of Raspberry Pi:

Note: Not covered is a static IP adress for your raspberry! Check how to do this with your local Router.

Configure Keyboard Layout etc. with raspi-config and change the default password (pi/raspberry). Last but not least enable the SSH Service with sudo update-rc.d ssh enable Now login with your favorite SSH client.

Installing Zabbix and Dependencies:

apt-get update
apt-get install -y \
  build-essential \
  curl \
  mariadb-server \
  libxml2-dev \
  libcurl4-openssl-dev \
  libmariadbclient-dev \
  libsnmp-dev \
  libevent-dev \
  libpcre3-dev \
  snmp-mibs-downloader \
  snmp \
  nginx \
  php7.0-fpm \
  php7.0-mysql \
  php7.0-gd \
  php7.0-mbstring \
  php7.0-bcmath \
  php7.0-xml
  
groupadd zabbix
useradd -g zabbix zabbix

curl -fsSL http://repo.zabbix.com/zabbix/3.2/debian/pool/main/z/zabbix/zabbix_3.2.7.orig.tar.gz | tar zxvf -
cd zabbix-3.2.7
 
./configure \
  --enable-server \
  --enable-agent \
  --with-mysql \
  --with-net-snmp \
  --with-libcurl \
  --with-libxml2
make install

Configure Mysql Database:

mysql -uroot -p "" << EOF
CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix';
EOF
   
mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql

Edit /usr/local/etc/zabbix_server.conf

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

Edit (Autostart) /etc/systemd/system/zabbix-server.service

[Unit]
Description=Zabbix Server
After=syslog.target network.target mysqld.service

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf
ExecReload=/usr/local/sbin/zabbix_server -R config_cache_reload
RemainAfterExit=yes
PIDFile=/run/zabbix/zabbix_server.pid

[Install]
WantedBy=multi-user.target

Edit /etc/systemd/system/zabbix-agent.service:

[Unit]
Description=Zabbix Agent
After=syslog.target network.target network-online.target
Wants=network.target network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/zabbix_agentd -c /usr/local/etc/zabbix_agentd.conf
RemainAfterExit=yes
PIDFile=/var/run/zabbix/zabbix_agentd.pid

[Install]
WantedBy=multi-user.target

Enable & Start zabbix services:

systemctl daemon-reload
systemctl enable zabbix-server
systemctl enable zabbix-agent
systemctl start zabbix-server
systemctl start zabbix-agent

Copy Webfrontend to future apache location:

mkdir -p /var/www/html/zabbix
cp -r frontends/php/* /var/www/html/zabbix/

Install & configure Apache2:

apt-get install apache2 libapache2-mod-php7.0
a2dismod mpm_event
a2enmod mpm_prefork
a2enmod php7.0
chown -R www-data:www-data /var/www/html/zabbix/

Change the apache webroot:

In the file /etc/apache2/sites-enabled/000-default.conf change the line DocumentRoot /var/www/html to DocumentRoot /var/www/html/zabbix

Edit php.ini nano /etc/php/7.0/apache2/php.ini:

In nano you can search with strg + w

post_max_size = 32
max_execution_time = 300
date.timezone = Europe/Berlin
memory_limit = 256M
mbstring.func_overload = 0
upload_max_filesize = 16M
max_input_time = 600

Configure Webfrontend

The Webfrontend checks if all server stuff is ready. If not see php.ini changes above. Note: ldap warning not resolved yet.

There is no need to change values in the default webgui configuration just click through. If zabbix can't create your config file add it manually at sudo nano /var/www/html/zabbix/conf/zabbix.conf.php

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

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = 'localhost';
$DB['PORT']     = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER']     = 'zabbix';
$DB['PASSWORD'] = 'YOURPASSWORD';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

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

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

Now you can login to your zabbix page with the default credentials admin/zabbix

Adding a cronjob for weekly updates:

sudo su
crontab -e

At the end of the cron file add the line 0 7 * * apt-get update && apt-get upgrade -y

fping error

sudo chown root:zabbix /usr/bin/fping
sudo chmod 6755 /usr/bin/fping
sudo chmod +s /usr/bin/fping
sudo service apache2 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment