Building Zabbix server - linux-on-ibm-z/docs GitHub Wiki

Building Zabbix server

Below versions of Zabbix server are available in respective distributions at the time of creation of these build instructions:

  • RHEL (8.8, 8.10) have 6.0.29
  • RHEL (9.2, 9.4) have 6.0.30
  • SLES 15 SP5 has 4.0.50
  • Ubuntu 20.04 has 4.0.17
  • Ubuntu 22.04 has 5.0.17

The instructions provided below specify the steps to build Zabbix server version 6.0.31 on Linux on IBM Z for following distributions:

  • RHEL (8.8, 8.10, 9.2, 9.4)
  • SLES (12 SP5, 15 SP5)
  • Ubuntu (20.04, 22.04, 24.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.

  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Step 1: Build using script

If you want to build Zabbix server using manual steps, go to STEP 2.

Use the following commands to build Zabbix server using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Zabbix/6.0.31/build_zabbixserver.sh

# Build Zabbix server
bash build_zabbixserver.sh

If the build completes successfully, go to STEP 7. In case of error, check logs for more details or go to STEP 2 to follow manual build steps.

Step 2: Install dependencies

export SOURCE_ROOT=/<source_root>/
cd $SOURCE_ROOT
  • RHEL (8.8, 8.10)

    sudo subscription-manager repos --enable=codeready-builder-for-rhel-8-s390x-rpms
    cat > MariaDB.repo <<'EOF'
    # MariaDB 10.11 RedHatEnterpriseLinux repository list - created 2023-07-14 14:59 UTC
    # https://mariadb.org/download/
    [mariadb]
    name = MariaDB
    # rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
    # baseurl = https://rpm.mariadb.org/10.11/rhel/$releasever/$basearch
    baseurl = https://mirror.its.dal.ca/mariadb/yum/10.11/rhel/$releasever/$basearch
    module_hotfixes = 1
    # gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgkey = https://mirror.its.dal.ca/mariadb/yum/RPM-GPG-KEY-MariaDB
    gpgcheck = 1
    EOF
    sudo mv MariaDB.repo /etc/yum.repos.d/
    sudo yum install -y initscripts httpd tar wget curl vim gcc make net-snmp net-snmp-devel php-mysqlnd git \
        httpd php libcurl-devel libxml2-devel php-xml php-gd php-bcmath php-mbstring php-ldap php-json libevent-devel \
        pcre-devel policycoreutils-python-utils automake pkgconfig libcmocka-devel libyaml-devel perl-YAML-LibYAML \
        libpath_utils-devel perl-IPC-Run3 perl-Path-Tiny php-fpm MariaDB-server MariaDB-client mysql-devel
    sudo yum groupinstall -y 'Development Tools'
  • RHEL (9.2, 9.4)

    sudo dnf install -y initscripts httpd tar wget curl vim gcc make net-snmp net-snmp-devel php-mysqlnd mysql-libs git \
        php libcurl-devel libxml2-devel php-xml php-gd php-bcmath php-mbstring php-ldap php-json libevent-devel \
        pcre-devel policycoreutils-python-utils automake pkgconfig libcmocka-devel libyaml-devel perl-YAML-LibYAML \
        libpath_utils-devel perl-IPC-Run3 perl-Path-Tiny mariadb mariadb-server mysql-devel perl-Time-HiRes
    sudo yum groupinstall -y 'Development Tools'
  • SLES 12 SP5

    sudo zypper install -y wget tar curl vim gcc7 gcc7-c++ make net-snmp net-snmp-devel net-tools git apache2 apache2-devel \
        apache2-mod_php72 php72 php72-mysql php72-xmlreader php72-xmlwriter php72-gd php72-bcmath php72-mbstring \
        php72-ctype php72-sockets php72-gettext php72-ldap libcurl-devel libxml2 libxml2-devel openldap2-devel openldap2 \
        libevent-devel pcre-devel automake libyaml-devel perl-YAML-LibYAML perl-IPC-Run3 cmake glibc-locale libmysqld-devel \
        libnghttp2-devel which gzip libopenssl-devel ncurses-devel bison boost-devel check-devel gawk pam-devel patch
    curl -L https://cpanmin.us | sudo perl - --self-upgrade
    sudo cpanm Path::Tiny
    export LC_CTYPE="en_US.UTF-8"
    
    #switch to GCC 7
    sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-7 40
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 40
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 40
    sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-7 40
  • SLES 15 SP5

    sudo zypper install -y wget tar curl vim gcc make net-snmp net-snmp-devel net-tools git apache2 apache2-devel mariadb \
        libmariadbd-devel apache2-mod_php8 php8 php8-mysql php8-xmlreader php8-xmlwriter php8-gd php8-bcmath php8-mbstring \
        php8-ctype php8-sockets php8-gettext libcurl-devel libxml2-2 libxml2-devel openldap2-devel php8-ldap \
        libevent-devel pcre-devel awk gzip automake cmake libyaml-devel perl-YAML-LibYAML perl-Path-Tiny perl-IPC-Run3 \
        glibc-locale
    export LC_CTYPE="en_US.UTF-8"
  • Ubuntu 20.04

    sudo apt-get update
    sudo apt-get -y install wget curl vim gcc make pkg-config snmp snmptrapd ceph locales libmariadbd-dev libxml2-dev \
      libsnmp-dev libcurl4 libcurl4-openssl-dev git apache2 php php-mysql libapache2-mod-php mysql-server php7.4-xml \
      php7.4-gd php-bcmath php-mbstring php7.4-ldap libevent-dev libpcre3-dev automake pkg-config libcmocka-dev \
      libyaml-dev libyaml-libyaml-perl libpath-tiny-perl libipc-run3-perl build-essential
  • Ubuntu 22.04

    sudo apt-get update
    sudo apt-get -y install wget curl vim gcc make pkg-config snmp snmptrapd ceph locales libmariadbd-dev libxml2-dev \
      libsnmp-dev libcurl4 libcurl4-openssl-dev git apache2 php php-mysql libapache2-mod-php mysql-server php8.1-xml \
      php8.1-gd php-bcmath php-mbstring php8.1-ldap libevent-dev libpcre3-dev automake pkg-config libcmocka-dev \
      libyaml-dev libyaml-libyaml-perl libpath-tiny-perl libipc-run3-perl build-essential
  • Ubuntu 24.04

    sudo apt-get update
    sudo apt-get -y install wget curl vim gcc make pkg-config snmp snmptrapd ceph locales libmariadbd-dev libxml2-dev \
      libsnmp-dev libcurl4 libcurl4-openssl-dev git apache2 php php-mysql libapache2-mod-php mysql-server php8.3-xml \
      php8.3-gd php-bcmath php-mbstring php8.3-ldap libevent-dev libpcre3-dev automake pkg-config libcmocka-dev \
      libyaml-dev libyaml-libyaml-perl libpath-tiny-perl libipc-run3-perl build-essential
  • Set locale (Ubuntu Only)

    sudo locale-gen en_US en_US.UTF-8
    sudo dpkg-reconfigure -f noninteractive locales  
    export LANG='en_US.UTF-8'
    export LANGUAGE='en_US.UTF-8'
  • Build and install cmocka (SLES)

    cd "$SOURCE_ROOT"
    git clone https://gitlab.com/cmocka/cmocka.git
    cd cmocka
    git checkout cmocka-1.1.5
    mkdir -p build
    cd build
    cmake -DCMAKE_INSTALL_PREFIX=/usr ..
    sudo make install
  • Build and install MariaDB (SLES 12 SP5)

    sudo mv /etc/my.cnf /etc/my.cnf.old    # if /etc/my.cnf already exists
    
    # Download mariadb
    cd "$SOURCE_ROOT"
    git clone https://github.com/MariaDB/server.git mariadb_server
    cd mariadb_server
    git checkout mariadb-10.10.2
    git submodule update --init --recursive
    # Build and install mariadb
    mkdir build  && cd build
    cmake "$SOURCE_ROOT"/mariadb_server
    make
    sudo make install
    printf -- "Build mariadb success\n"
     
    export PATH=$PATH:/usr/sbin
    sudo groupadd mysql || true
    sudo useradd -g mysql mysql || true
    cd /usr/local/mysql
    sudo chown -R mysql .
    sudo chmod -R o+rwx .
    sudo scripts/mysql_install_db --user=mysql
    sudo cp support-files/mysql.server /etc/init.d/mysql
    
    # Create symlinks
    sudo ln -sf /usr/local/mysql/bin/mysqladmin /usr/bin/
    sudo ln -sf /usr/local/mysql/bin/mysqld_safe /usr/bin/
    sudo ln -sf /usr/local/mysql/bin/mysql /usr/bin/

Step 3: Enable PHP support by modifying Apache configuration file

  • RHEL

    • /etc/httpd/conf/httpd.conf

      cd /etc/httpd/conf/
      sudo chmod 766 httpd.conf
      echo "ServerName localhost" >> httpd.conf
      echo "AddType application/x-httpd-php .php" >> httpd.conf
      echo "<Directory />" >> httpd.conf
      echo "DirectoryIndex index.php" >> httpd.conf
      echo "</Directory>" >> httpd.conf
      sudo chmod 644 httpd.conf
  • SLES

    • /etc/apache2/httpd.conf

      cd /etc/apache2/
      sudo chmod 766 httpd.conf
      echo "ServerName localhost" >> httpd.conf
      echo "AddType application/x-httpd-php .php" >> httpd.conf
      echo "<Directory />" >> httpd.conf
      echo "DirectoryIndex index.php" >> httpd.conf
      echo "</Directory>" >> httpd.conf
      echo "LoadModule php7_module /usr/lib64/apache2/mod_php7.so" >> httpd.conf # (SLES 12 SP5)
      echo "LoadModule php_module /usr/lib64/apache2/mod_php8.so" >> httpd.conf # (SLES 15 SP5)
      sudo chmod 644 httpd.conf
  • Ubuntu

    • /etc/apache2/apache2.conf

       cd /etc/apache2/
       sudo chmod 766 apache2.conf
       echo "ServerName localhost" >> apache2.conf
       echo "AddType application/x-httpd-php .php" >> apache2.conf
       echo "<Directory />" >> apache2.conf
       echo "DirectoryIndex index.php" >> apache2.conf
       echo "</Directory>" >> apache2.conf
       sudo chmod 644 apache2.conf

Step 4: Download and install Zabbix server

  • Create a zabbix user required to start Zabbix server daemon

    • RHEL, SLES

      sudo groupadd --system zabbix
      sudo useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
    • Ubuntu

      sudo addgroup --system --quiet zabbix
      sudo adduser --quiet --system --disabled-login --ingroup zabbix --home /var/lib/zabbix --no-create-home zabbix
  • Download Zabbix server

    cd $SOURCE_ROOT
    git clone https://github.com/zabbix/zabbix.git
    cd zabbix
    git checkout 6.0.31
    export CFLAGS="-std=gnu99"
    ./bootstrap.sh tests
  • Build and install Zabbix server

    cd $SOURCE_ROOT/zabbix
    ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
    make
    make dbschema
    sudo make install
  • Run Tests (optional)

    cd $SOURCE_ROOT/zabbix
    make tests
  • Install Zabbix web interface

    • RHEL

      cd $SOURCE_ROOT/zabbix/ui/
      sudo mkdir -p /var/www/html/zabbix
      sudo cp -rf * /var/www/html/zabbix/
      sudo chown -R apache:apache /var/www/html/zabbix/conf
    • SLES

      cd $SOURCE_ROOT/zabbix/ui/
      sudo mkdir -p /srv/www/htdocs/zabbix
      sudo cp -rf * /srv/www/htdocs/zabbix
      sudo chown -R wwwrun:www /srv/www/htdocs/zabbix/conf
    • Ubuntu

      cd $SOURCE_ROOT/zabbix/ui/
      sudo mkdir -p /var/www/html/zabbix
      sudo cp -rf * /var/www/html/zabbix/
      sudo chown -R www-data:www-data /var/www/html/zabbix/conf

Step 5: Prerequisites to start Zabbix server

  • Start httpd and mysql or mariadb servers

    • RHEL

      sudo service httpd start
      sudo service mariadb start        # (RHEL 8.x, 9.x)
    • SLES

      sudo service apache2 restart
      sudo mysqld_safe --user=mysql &   # (SLES 12 SP5)
      sudo service mariadb restart      # (SLES 15 SP5)
    • Ubuntu

      sudo service apache2 start
      sudo service mysql stop
      sudo usermod -d /var/lib/mysql/ mysql
      sudo service mysql start
  • Create database and grant privileges to zabbix user

    • RHEL (8.x, 9.x), SLES, Ubuntu (22.04, 24.04)

       sudo mysql -e "create user 'zabbix'@'localhost'"
       sudo mysql -e "create database zabbix character set utf8 collate utf8_bin"
       sudo mysql -e "grant all privileges on zabbix.* to 'zabbix'@'localhost'"
    • Ubuntu 20.04

      sudo mysql -e "create user 'zabbix'@'localhost' identified with mysql_native_password"
      sudo mysql -e "create database zabbix character set utf8 collate utf8_bin"
      sudo mysql -e "grant all privileges on zabbix.* to 'zabbix'@'localhost'"
  • Populate database with initial load

    cd $SOURCE_ROOT/zabbix/database/mysql
    sudo mysql -e "SET GLOBAL log_bin_trust_function_creators = 1"  # (Ubuntu)
    sudo mysql -uzabbix zabbix < schema.sql
    sudo mysql -uzabbix zabbix < images.sql
    sudo mysql -uzabbix zabbix < data.sql

Step 6: Change php.ini file

  • RHEL (8.x, 9.x)

    • /etc/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php.ini
      sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Kolkata/g' /etc/php.ini
  • SLES 12 SP5

    • /etc/php7/apache2/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php7/apache2/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php7/apache2/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php7/apache2/php.ini
  • SLES 15 SP5

    • /etc/php8/apache2/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php8/apache2/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php8/apache2/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php8/apache2/php.ini
  • Ubuntu 20.04

    • /etc/php/7.4/apache2/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/7.4/apache2/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php/7.4/apache2/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php/7.4/apache2/php.ini
  • Ubuntu 22.04

    • /etc/php/8.1/apache2/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/8.1/apache2/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php/8.1/apache2/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php/8.1/apache2/php.ini
      sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Kolkata/g' /etc/php/8.1/apache2/php.ini
  • Ubuntu 24.04

    • /etc/php/8.3/apache2/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/8.3/apache2/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php/8.3/apache2/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php/8.3/apache2/php.ini
      sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Kolkata/g' /etc/php/8.3/apache2/php.ini

Step 7: Start Zabbix server

  • Please edit /usr/local/etc/zabbix_server.conf and add the appropriate location depending on where the mysql or mariadb installation creates the socket.

    DBSocket=/<mysql_sock_location>/  # (e.g. DBSocket=/tmp/mysql.sock)
  • Restart http service and start Zabbix server

    • RHEL

      sudo service httpd restart
      sudo service php-fpm restart
      zabbix_server
    • SLES

      sudo service apache2 restart
      PATH=$PATH:/usr/local/sbin/ zabbix_server
    • Ubuntu

      sudo service apache2 restart
      zabbix_server

Step 8: Configure through online console

  • After starting Zabbix server, direct your Web browser to the Zabbix Console by using the following URL:

    http://<HOST_IP>/zabbix
    
  • Follow the prompts to finish configuration. Please take note of the following caveats.

    • Change Database host from localhost to 127.0.0.1 if you get the error "Error connecting to database: No such file or directory".

    • On RHEL, the firewall may be configured to not allow connections in. If you cannot connect to the site please change the firewall to allow those connections:

      sudo firewall-cmd --add-service={http,https} --permanent
      sudo firewall-cmd --add-port={10051/tcp,10050/tcp} --permanent
      sudo firewall-cmd --reload
    • On RHEL, SELinux may get in the way of completing the web installation:

      • If the web installation is getting access denied on the database please run the following commands:

        sudo setsebool -P httpd_can_connect_zabbix 1
        sudo setsebool -P zabbix_can_network 1
        sudo setsebool -P httpd_can_network_connect_db 1
      • If the web installation cannot create the config file try disabling SELinux temporarily:

        sudo su
        # disable SELinux
        setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
        exit

        At this point, you should go back to the web installation, it should now be able to create the configuration file. Once that's done please follow these steps:

        sudo su
        # re-enable SELinux
        setenforce 1 && sed -i 's/^SELINUX=.*/SELINUX=enforcing/g' /etc/selinux/config
        exit
        # create a policy with exceptions for the things zabbix needed and apply it
        sudo grep "denied.*zabbix" /var/log/audit/audit.log | audit2allow -M zabbix_policy
        sudo semodule -i zabbix_policy.pp
    • If you get an error 'DBType not set' after setup, click retry to reload config file. To avoid the error, wait 5 seconds before clicking 'finish' at the end.

    • Login to Zabbix using below default credentials.

       User     : Admin
       Password : zabbix
      

References:

⚠️ **GitHub.com Fallback** ⚠️