Skip to content

Building Zabbix server

aborkar-ibm edited this page Aug 8, 2022 · 63 revisions

Building Zabbix server

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

  • Ubuntu 18.04 has 3.0.12
  • Ubuntu 20.04 has 4.0.17
  • RHEL 8.x has 4.0.29
  • SLES 15 SP3 has 3.0.31

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

  • RHEL (7.8, 7.9, 8.4, 8.5)
  • SLES (12 SP5, 15 SP3)
  • Ubuntu (18.04, 20.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/5.0.20/build_zabbixserver.sh

# Build zabbix server
bash build_zabbixserver.sh

If the build completes successfully, go to STEP 8. 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>/
  • RHEL (7.8, 7.9)

     sudo yum install -y initscripts httpd tar wget curl vim gcc pcre pcre-devel make net-snmp net-snmp-devel httpd-devel mariadb mariadb-server mariadb-devel mariadb-libs git libcurl-devel libxml2-devel libjpeg-devel libpng-devel freetype freetype-devel openldap openldap-devel libevent-devel sqlite-devel policycoreutils-python libyaml-devel perl-IPC-Run3
     sudo yum install -y bzip2-devel curl-devel enchant-devel gmp-devel krb5-devel postgresql-devel aspell-devel cyrus-sasl-devel sqlite-devel libXpm-devel libxslt-devel recode-devel readline-devel openssl-devel gdbm-devel libdb-devel openldap openldap-devel autoconf automake patch curl pkgconfig libtool gcc-c++ bison openssl aspell
     curl -L http://cpanmin.us | sudo perl - --self-upgrade
     sudo /usr/local/bin/cpanm YAML::XS
     sudo /usr/local/bin/cpanm Path::Tiny
  • RHEL (8.4, 8.5)

    sudo subscription-manager repos --enable=codeready-builder-for-rhel-8-s390x-rpms
    sudo yum install -y initscripts httpd tar wget curl vim gcc make net-snmp net-snmp-devel mariadb mariadb-server mysql-devel php-mysqlnd mysql-libs 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
    sudo yum groupinstall -y 'Development Tools'
  • SLES 12 SP5

    sudo zypper install -y wget tar curl vim gcc make net-snmp net-snmp-devel mariadb libmysqld-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
    curl -L http://cpanmin.us | sudo perl - --self-upgrade
    sudo cpanm Path::Tiny
    export LC_CTYPE="en_US.UTF-8"
  • SLES 15 SP3

    sudo zypper install -y wget tar curl vim gcc make net-snmp net-snmp-devel mariadb libmysqld-devel net-tools git apache2 apache2-devel apache2-mod_php7 php7 php7-mysql php7-xmlreader php7-xmlwriter php7-gd php7-bcmath php7-mbstring php7-ctype php7-sockets php7-gettext libcurl-devel libxml2 libxml2-devel openldap2-devel openldap2 php7-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 18.04

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

    sudo apt-get update
    sudo apt-get -y install wget curl vim gcc make pkg-config snmp snmptrapd ceph 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
    
    
  • Build and install cmocka ( SLES and RHEL 7.x)

    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
  • Other dependencies RHEL 7.x

    For RHEL 7, we need to install the following additional dependency:

    • CMake 3.12.4

      cd $SOURCE_ROOT
      wget https://github.com/Kitware/CMake/releases/download/v3.12.4/cmake-3.12.4.tar.gz
      tar xzf cmake-3.12.4.tar.gz
      cd cmake-3.12.4
      ./bootstrap
      make
      sudo make install
    • set up env variables and links

      export PATH=${PATH}:/usr/local/bin:/usr/local/sbin
      export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
      export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib64:/usr/local/lib:/usr/lib64
      sudo ln -s /usr/lib64/libldap* /usr/lib/
      sudo ln -s /usr/lib64/liblber.so /usr/lib/
    • libzip rel-1-4-0

      cd $SOURCE_ROOT
      git clone https://github.com/nih-at/libzip
      cd libzip/
      git checkout rel-1-4-0
      mkdir build && cd build
      cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
      make
      sudo make install
    • tidy-html5 5.6.0

      cd $SOURCE_ROOT
      git clone https://github.com/htacg/tidy-html5.git
      ls
      cd tidy-html5/
      git checkout 5.6.0
      cd build/cmake/
      cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
      make
      sudo make install
    • onigurama v6.9.5

      cd $SOURCE_ROOT
      git clone https://github.com/kkos/oniguruma
      cd oniguruma/
      git checkout v6.9.5
      autoreconf -vfi
      ./configure --prefix=/usr/local
      make
      sudo make install
    • icu release-55-1

      cd $SOURCE_ROOT
      wget https://github.com/unicode-org/icu/archive/release-55-1.tar.gz
      ls
      tar xzf release-55-1.tar.gz
      cd icu-release-55-1/icu4c/source
      ./configure --prefix=/usr/local
      CFLAGS=-D__USE_XOPEN2K8 CXXFLAGS=-D__USE_XOPEN2K8 make
      sudo make install
    • PHP-7.4.11

      cd $SOURCE_ROOT
      wget https://www.php.net/distributions/php-7.4.11.tar.gz
      tar xzf php-7.4.11.tar.gz
      cd php-7.4.11
      
      curl -sSL https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/PHP/7.4.11/patch/nan.diff | patch -p1
      curl -sSL https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/PHP/7.4.11/patch/infinity.diff | patch -p1
      curl -sSL https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/PHP/7.4.11/patch/reflection.diff | patch -p1
      
      icupkg -tb ext/intl/tests/_files/resourcebundle/root.res
      icupkg -tb ext/intl/tests/_files/resourcebundle/es.res
      icupkg -tb ext/intl/tests/_files/resourcebundle/res_index.res
      
      ./configure --prefix=/usr/local --without-pcre-jit --without-pear --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd \
      --with-pgsql --with-pdo-pgsql --with-pdo-sqlite --with-readline --with-gettext --with-apxs2=/usr/bin/apxs \
      --enable-gd --with-jpeg --with-freetype --with-xpm --with-kerberos --with-openssl --with-ldap \
      --with-xsl --with-xmlrpc --with-bz2 --with-gmp --with-zip --with-mhash --disable-inline-optimization \
      --enable-intl --enable-fpm --enable-exif --enable-xmlreader --enable-sockets --enable-ctype \
      --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-shmop --enable-pcntl --enable-mbstring --enable-soap \
      --enable-bcmath --enable-calendar --enable-ftp --enable-zend-test=shared --with-curl=/usr \
      --with-zlib --with-zlib-dir=/usr/local --with-tidy=/usr/local --with-pspell=/usr --with-enchant=/usr
      
      make
      sudo make install
      
      sudo install -m644 php.ini-production /usr/local/lib/php.ini
      sudo sed -i "s@php/includes\"@&\ninclude_path = \".:/usr/local/lib/php\"@" /usr/local/lib/php.ini
      sudo sed -i "s/;mysqli.allow_local_infile = On/mysqli.allow_local_infile = On/" /usr/local/lib/php.ini
      sudo sed -i "s/;opcache.enable=1/opcache.enable=1/" /usr/local/lib/php.ini
      sudo sed -i "s/;opcache.enable_cli=0/opcache.enable_cli=1/" /usr/local/lib/php.ini

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
      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

    • Ubuntu

      sudo addgroup --system --quiet zabbix
      sudo adduser --quiet --system --disabled-login --ingroup zabbix --home /var/lib/zabbix --no-create-home zabbix
    • RHEL, SLES

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

    cd $SOURCE_ROOT
    git clone https://github.com/zabbix/zabbix.git
    cd zabbix
    git checkout 5.0.20
    ./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

    • 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
    • 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

Step 5: Prerequisites to start Zabbix server

  • Start httpd and mysql servers

    • Ubuntu

      sudo service apache2 start
      sudo service mysql stop
      sudo usermod -d /var/lib/mysql/ mysql
      sudo service mysql start
    • SLES

      sudo service apache2 restart
      sudo service mariadb restart
    • RHEL

      sudo service httpd start
      sudo service mariadb start
  • Start MySQL/MariaDB service in a directory with proper permissions.

    Note: For reference, click here for MySQL and here for MariaDB.

  • Create database and grant privileges to zabbix user

    • 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'"
    • RHEL, SLES, Ubuntu (18.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'"
  • Populate database with initial load

    cd $SOURCE_ROOT/zabbix/database/mysql
    sudo mysql -uzabbix zabbix < schema.sql
    sudo mysql -uzabbix zabbix < images.sql
    sudo mysql -uzabbix zabbix < data.sql
  • Turn off javascript pre-processing to circumvent crash due to duktape module

    sudo mysql -e "update zabbix.items set status=1 where itemid in (select itemid from zabbix.item_preproc where type=21)"

Step 6: Change php.ini file

  • Ubuntu (18.04)

    • /etc/php/7.2/apache2/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/7.2/apache2/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php/7.2/apache2/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /etc/php/7.2/apache2/php.ini
      sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Kolkata/g' /etc/php/7.2/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
      sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Kolkata/g' /etc/php/7.4/apache2/php.ini
  • RHEL (7.x)

    • /usr/local/lib/php.ini

      sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/lib/php.ini
      sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /usr/local/lib/php.ini
      sudo sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /usr/local/lib/php.ini
      sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Kolkata/g' /usr/local/lib/php.ini
  • RHEL (8.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

    • /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

Step 7: Start Zabbix server

  • Restart http service and start Zabbix server

    • RHEL

      sudo service httpd restart
      sudo service php-fpm restart   # (RHEL 8.x)
      zabbix_server
    • Ubuntu

      sudo service apache2 restart
      zabbix_server
    • SLES

      sudo service apache2 restart
      PATH=$PATH:/usr/local/sbin/ 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
      

Reference:

Clone this wiki locally