ag@linux:~$

history 26 of 36

Install Zabbix from Source on CentOS 6.3

My steps for compiling Zabbix server and agent on CentOS 6.3, creating its MySQL database and copying the PHP web frontend into Apache.

Written

From my Linux study notes, 2016. Some commands and versions here are old, so please reuse them carefully. Anything marked "added later", and the notes at the end, explain what has changed since.

Here are my simple steps to install Zabbix on a CentOS machine. Zabbix is a monitoring system: the server collects data from agents running on the machines you want to watch, and a PHP web frontend shows the results.

Before you start

  • Run the commands as root (or with sudo).

  • You need a MySQL server for the Zabbix database. Step 1 installs the MySQL client and development files only. On CentOS 6 the server package is mysql-server and its service is mysqld:

    Terminal window
    yum install mysql-server
    service mysqld start
    chkconfig mysqld on
  • You also need Apache and PHP for the web frontend (yum install httpd php).

  • Use a test server first.

Install Zabbix

  1. Install the build dependencies:

    Terminal window
    yum install zlib-devel mysql-devel glibc-devel curl-devel gcc automake mysql libidn-devel openssl-devel net-snmp-devel rpm-devel OpenIPMI-devel

    The -devel packages contain the header files the compiler needs for the features enabled in step 6 (MySQL, SNMP, curl, IPMI).

  2. Install the EPEL repository:

    Terminal window
    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

    Correction: this is the release package for EPEL 5 (CentOS/RHEL 5, 32-bit), not CentOS 6, and that download address no longer exists. On CentOS 6 you need the EPEL 6 release package instead. Where the epel-release package is offered by your system’s own repositories, this is the simplest way to get it:

    Terminal window
    yum install epel-release

    CentOS 6 and EPEL 6 are both end of life, so these repositories have been moved to archive servers and this step may fail today. See the notes at the end.

  3. Install iksemel, which Zabbix uses for Jabber (XMPP) notifications:

    Terminal window
    yum --enablerepo=epel install iksemel iksemel-devel
  4. Download the Zabbix installation file from www.zabbix.com/download, or:

    Terminal window
    wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8.1/zabbix-1.8.1.tar.gz?use_mirror=freefr

    Because of the ?use_mirror=freefr part, wget may save the file with that text in its name. Adding -O zabbix-1.8.1.tar.gz saves it with a clean name:

    Terminal window
    wget -O zabbix-1.8.1.tar.gz "http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8.1/zabbix-1.8.1.tar.gz?use_mirror=freefr"

    The original post goes straight to cd without extracting the archive. Extract it first:

    Terminal window
    tar xzf zabbix-1.8.1.tar.gz
  5. Go into the source folder:

    Terminal window
    cd zabbix.1.2.3

    Correction: the folder name must match the version you downloaded. For the file above it is:

    Terminal window
    cd zabbix-1.8.1
  6. Configure the build with the server, the agent and the features you need:

    Terminal window
    ./configure --enable-server --with-mysql --with-net-snmp --with-jabber --with-libcurl --with-openipmi --enable-agent
    • --enable-server and --enable-agent build the Zabbix server and the agent.
    • --with-mysql stores data in MySQL.
    • --with-net-snmp, --with-jabber, --with-libcurl and --with-openipmi turn on SNMP checks, Jabber alerts, web checks and IPMI checks.

    If configure stops with an error, it usually names the missing -devel package.

  7. Install make if it is not already installed:

    Terminal window
    yum install make
  8. Compile:

    Terminal window
    make
  9. Install:

    Terminal window
    make install

Create the database

  1. Log in to MySQL (mysql -u root -p) and create the database:

    create database your_username character set utf8;

    Correction: this should be the database name, not the username, so that it matches the next command:

    create database your_database character set utf8;
  2. Create the Zabbix database user and give it access:

    grant all privileges on your_database.* to 'your_username'@'localhost' identified by 'your_password';

    Type exit to leave MySQL.

  3. Import the SQL files from the downloaded files. Check where they are: the folder depends on the Zabbix version (look under the create folder in the source).

    Terminal window
    mysql your_database < mysql.sql
    mysql your_database < data.sql
    mysql your_database < images_mysql.sql

    Import them in this order: the first file creates the tables, the others fill them. If MySQL asks for a login, add -u your_username -p. Run each command from the folder that holds that file, or give the full path to the file.

Configure Zabbix

  1. Create the config folder, go back to the top of the Zabbix source folder and copy the sample config files:

    Terminal window
    mkdir /etc/zabbix
    cd ../..
    cp misc/conf/{zabbix_server.conf,zabbix_agentd.conf} /etc/zabbix

    cd ../.. goes up two levels, which takes you from the SQL folder in step 12 back to the source folder. Run pwd to check you are in the zabbix-1.8.1 folder before copying.

  2. Edit the server config and enter your MySQL information:

    Terminal window
    vi /etc/zabbix/zabbix_server.conf

    The settings to change are the database ones, for example:

    DBName=your_database
    DBUser=your_username
    DBPassword=your_password

Install the web frontend

  1. Install the PHP modules the frontend needs:

    Terminal window
    yum install php-mysql php-gd php-bcmath php-mbstring php-xml
  2. Copy the frontend files into Apache’s web folder:

    Terminal window
    cp -r frontends/php/ /var/www/html/
  3. Rename the folder so the frontend is at /zabbix:

    Terminal window
    mv /var/www/html/php/ /var/www/html/zabbix
  4. Edit the PHP settings:

    Terminal window
    nano /etc/php.ini

    Add (or change) the following values:

    max_execution_time = 600
    memory_limit = 256M
    post_max_size = 32M
    mbstring.func_overload = 2

    Restart Apache afterwards so PHP picks up the changes:

    Terminal window
    service httpd restart

My original notes stop here. The next stage is to open http://your-server-ip/zabbix in a browser to finish the frontend setup, and to start the Zabbix server and agent. Check the Zabbix documentation for your version for those steps.

Notes for today

  • CentOS 6 reached end of life on 30 November 2020. Rocky Linux and AlmaLinux are the common free replacements; Debian and Ubuntu are alternatives.

  • Zabbix 1.8 is very old. Current Zabbix releases are normally installed from the official Zabbix package repositories rather than compiled by hand. Follow the instructions for your system at https://www.zabbix.com/documentation/.

  • PHP: mbstring.func_overload was deprecated in PHP 7.2 and removed in PHP 8.0, so leave that line out on modern PHP.

  • MySQL 8: GRANT ... IDENTIFIED BY no longer works in MySQL 8.0. Create the user first, then grant:

    CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
    GRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'localhost';
  • Services and packages: service / chkconfig became systemctl start / systemctl enable, and yum became dnf on newer Red Hat-family systems.

  • Security: use a strong password for the database user, and make /etc/zabbix/zabbix_server.conf readable only by root and the Zabbix user, as it contains the database password.