I’m old fashion and in some cases I like to compile my stuff, Zabbix is one of these cases. You can add/remove features directly with ./configure, and mess around with some timeouts of zabbix_server and zabbix_agentd for example. In this tutorial, we will not change anything on the source code.

We are going install Zabbix version 2.4.6 with MySQL, Nginx and PHP-FPM. This is the stack of what I use in production environments.

Kurt Telep just created a Vagrantfile based on this tutorial, check it out here. Thanks Kurt for the contribution.

Configure the external repositories and install dependencies

[root@vagrant-centos67 ~]# mkdir -p /opt/sources/zabbix
[root@vagrant-centos67 ~]# cd /opt/sources
[root@vagrant-centos67 ~]# yum install -y wget
[root@vagrant-centos67 ~]# wget https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
[root@vagrant-centos67 ~]# rpm -ivh mysql-community-release-el6-5.noarch.rpm

# Create Nginx REPO
vi /etc/yum.repos.d/nginx.repo

# Add the following below:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

# Update and install required packages
yum update -y
yum install -y mysql-server php-mysql php-bcmath php-gd php-fpm php-xml php-ldap php-mbstring wget libcurl-devel openldap-devel java-1.7.0-openjdk-devel net-snmp-devel iksemel-devel libxml2-devel mysql-devel nginx vim

Download and install Zabbix

We are compiling Zabbix with java, jabber, libcurl, snmp and ldap support, for more options(IPMI for example) please run ./configure –help

[root@vagrant-centos67 opt]# cd /opt/sources/zabbix
[root@vagrant-centos67 zabbix]# wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.4.6/zabbix-2.4.6.tar.gz
[root@vagrant-centos67 zabbix]# tar zxvf zabbix-2.4.6.tar.gz 
[root@vagrant-centos67 zabbix]# cd zabbix-2.4.6
[root@vagrant-centos67 zabbix-2.4.6]# ./configure --enable-server --enable-agent --prefix=/usr/local --sysconfdir=/etc --enable-java --with-mysql --with-jabber --with-libcurl --with-net-snmp --with-ldap --with-iconv --with-libxml2

Configuration:

  Detected OS:           linux-gnu
  Install path:          /usr/local
  Compilation arch:      linux

  Compiler:              gcc
  Compiler flags:        -g -O2  -I/usr/include/mysql -g  -fstack-protector  -m64 -fPIC  -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing     -I/usr/include/libxml2   -I/usr/include/rpm -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include   -I/usr/include  -I/yes/include

  Enable server:         yes
  Server details:
    With database:         MySQL
    WEB Monitoring:        cURL
    Native Jabber:         yes
    SNMP:                  yes
    IPMI:                  no
    SSH:                   no
    ODBC:                  no
    Linker flags:          -rdynamic  -L/yes/lib    -L/usr/lib64/mysql        -L/usr/lib64   -L/usr/lib 
    Libraries:             -lm -ldl -lrt  -lresolv    -lmysqlclient     -liksemel -lxml2    -lnetsnmp   -lldap -llber   -lcurl

  Enable proxy:          no

  Enable agent:          yes
  Agent details:
    Linker flags:          -rdynamic  -L/yes/lib  -L/usr/lib 
    Libraries:             -lm -ldl -lrt  -lresolv   -lldap -llber   -lcurl

  Enable Java gateway:   yes
  Java gateway details:
    Java compiler:         javac
    Java archiver:         jar

  LDAP support:          yes
  IPv6 support:          no

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

make
make install


# Create group/user for Zabbix
groupadd zabbix
useradd -g zabbix zabbix

Configure MySQL

We will not make any configuration on MySQL, but keep in mind that in production environment you want to configure InnoDB, replication and other goodies.


[root@vagrant-centos67 zabbix]# /etc/init.d/mysqld start


PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/bin/mysqladmin -u root password 'new-password'
  /usr/bin/mysqladmin -u root -h vagrant-centos67.vagrantup.com password 'new-password'
...

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

# Add a password for root user
[root@vagrant-centos67 zabbix-2.4.6]# mysqladmin -uroot password 'topsecret'
Warning: Using a password on the command line interface can be insecure.

# Create database for Zabbix and populate it with the .sql files
[root@vagrant-centos67 zabbix-2.4.6]# cd /opt/sources/zabbix/zabbix-2.4.6/database/mysql/
[root@vagrant-centos67 zabbix-2.4.6]# mysql -uroot -ptopsecret

create database zabbix;
use zabbix;
source schema.sql;
source data.sql;
source images.sql;

Configure Zabbix Server and copy start scripts

cp /opt/sources/zabbix/zabbix-2.4.6/misc/init.d/fedora/core5/zabbix_server /etc/init.d/
cp /opt/sources/zabbix/zabbix-2.4.6/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/

# Configure /etc/zabbix_server.conf
For this tutorial we will only change the line 102 to DBPassword=topsecret

/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start

# Check is Zabbix server is ok and running
[root@vagrant-centos67 zabbix-2.4.6]# cat /tmp/zabbix_server.log 
  6880:20151007:134754.283 Starting Zabbix Server. Zabbix 2.4.6 (revision 54796).
  6880:20151007:134754.283 ****** Enabled features ******
  6880:20151007:134754.283 SNMP monitoring:           YES
  6880:20151007:134754.283 IPMI monitoring:            NO
  6880:20151007:134754.283 WEB monitoring:            YES
  6880:20151007:134754.283 VMware monitoring:         YES
  6880:20151007:134754.283 Jabber notifications:      YES
  6880:20151007:134754.283 Ez Texting notifications:  YES
  6880:20151007:134754.283 ODBC:                       NO
  6880:20151007:134754.283 SSH2 support:               NO
  6880:20151007:134754.283 IPv6 support:               NO
  6880:20151007:134754.283 ******************************
  6880:20151007:134754.283 using configuration file: /etc/zabbix_server.conf
  6880:20151007:134754.593 current database version (mandatory/optional): 02040000/02040000
  6880:20151007:134754.594 required mandatory version: 02040000
  6880:20151007:134754.657 server #0 started [main process]
  6882:20151007:134754.664 server #1 started [configuration syncer #1]
  6885:20151007:134754.673 server #4 started [poller #2]
  6886:20151007:134754.674 server #5 started [poller #3]
  6888:20151007:134754.675 server #7 started [poller #5]
  6889:20151007:134754.675 server #8 started [unreachable poller #1]
  6890:20151007:134754.675 server #9 started [trapper #1]
  6892:20151007:134754.677 server #11 started [trapper #3]
  6893:20151007:134754.677 server #12 started [trapper #4]
  6894:20151007:134754.689 server #13 started [trapper #5]
  6895:20151007:134754.689 server #14 started [icmp pinger #1]
  6896:20151007:134754.690 server #15 started [alerter #1]
  6897:20151007:134754.690 server #16 started [housekeeper #1]
  6898:20151007:134754.690 server #17 started [timer #1]
  6899:20151007:134754.690 server #18 started [http poller #1]
  6901:20151007:134754.691 server #20 started [history syncer #1]
  6903:20151007:134754.691 server #22 started [history syncer #3]
  6906:20151007:134754.691 server #25 started [proxy poller #1]
  6904:20151007:134754.691 server #23 started [history syncer #4]
  6905:20151007:134754.691 server #24 started [escalator #1]
  6907:20151007:134754.692 server #26 started [self-monitoring #1]
  6884:20151007:134754.692 server #3 started [poller #1]
  6883:20151007:134754.692 server #2 started [db watchdog #1]
  6891:20151007:134754.692 server #10 started [trapper #2]
  6887:20151007:134754.693 server #6 started [poller #4]
  6902:20151007:134754.693 server #21 started [history syncer #2]
  6900:20151007:134755.315 server #19 started [discoverer #1]
[root@vagrant-centos67 zabbix-2.4.6]# 

Configure Nginx


mkdir -p /var/www/zabbix

[root@vagrant-centos65 mysql]# cp -r -p /opt/sources/zabbix/zabbix-2.4.6/frontends/php/* /var/www/zabbix/
[root@vagrant-centos65 mysql]# chown nginx. /var/www/zabbix/*

# Edit the file /etc/nginx/nginx.conf and paste the content below


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;
    gzip on;
    gzip_static on;
    gzip_comp_level 2;
    gzip_min_length 20240;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_disable "MSIE [1-6]\.";

    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m;

}


# Edit the file /etc/nginx/conf.d/default.conf with the content

upstream php5-fpm-sock {
    server unix:/var/run/php-fpm/php-fpm.socket;
}

server {
    server_name localhost;
    set $cache_uri $request_uri;

    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
      set $cache_uri 'null cache';
    }
    if ($query_string != "") {
      set $cache_uri 'null cache';
    }

    root /var/www/zabbix;
	error_log  /var/log/nginx/error.log;
	access_log  /var/log/nginx/access.log  main;
 
    location / {
        index index.html index.htm index.php;
	proxy_read_timeout 600;
    }

    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
        access_log        off;
        log_not_found     off;
        expires           360d;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        set $skip_cache 1;
        if ($cache_uri != "null cache") {
           add_header X-Cache-Debug "$cache_uri $cookie_nocache $arg_nocache$arg_comment $http_pragma $http_authorization";
          set $skip_cache 0;
        }
        fastcgi_cache_bypass $skip_cache;
#        fastcgi_cache microcache;
        fastcgi_cache_key $scheme$host$request_uri$request_method;
        fastcgi_cache_valid any 8m;
        #fastcgi_cache_use_stale updating;
        fastcgi_cache_bypass $http_pragma;
        fastcgi_cache_use_stale updating error timeout invalid_header http_500;
        fastcgi_pass php5-fpm-sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/zabbix$fastcgi_script_name;
	fastcgi_read_timeout 14400;
    }
}

Configure PHP and PHP-FPM

# Edit the file /etc/php.ini and correct the values as following

post_max_size 16M	
max_execution_time 300
max_input_time 300
date.timezone = America/Sao_Paulo (In my case)


# Configure PHP-FPM edit the file /etc/php-fpm.d/www.conf

[www]
listen = /var/run/php-fpm/php-fpm.socket
listen.backlog = -1
listen.owner = nginx
listen.group = nginx
listen.mode=0660

user = nginx
group = nginx
#request_slowlog_timeout = 10s
#slowlog = /var/log/php-fpm/slowlog-site.log
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 20
pm.start_servers = 6
pm.min_spare_servers = 4
pm.max_spare_servers = 7
pm.max_requests = 150
pm.status_path = /status
request_terminate_timeout = 600s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes
env[HOSTNAME] = $HOSTNAME
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

There is a bug in Zabbix when you install from source. Just run this code to fix it:

mkdir -p /var/lib/php/session 
chown nginx. /var/lib/php/session

Start nginx/php-fpm and proceed to install

/etc/init.d/nginx start
/etc/init.d/php-fpm start

Try access http://localhost on your browser

Finish the installation

We are almost done, now we just need to configure zabbix(generate the config file), just follow the screenshots. The process is NNF, if you have any questions ask on the comments.

If you get the error below it’s probably because you forgot to configure php.ini file or to reload nginx/php-fpm

And we are done! We have Zabbix installed using a MySQL database and Nginx/PHP-FPM serving the frontend app.