Skip to content

Instantly share code, notes, and snippets.

@maborak
Last active November 22, 2021 17:30
Show Gist options
  • Save maborak/e857c40d6c5759b213131c92f0192bc8 to your computer and use it in GitHub Desktop.
Save maborak/e857c40d6c5759b213131c92f0192bc8 to your computer and use it in GitHub Desktop.
Compile Zabbix 5.4 in Ubuntu 21.10

Install required packages

  1. apt-get update
  2. apt-get install git libpcre2-8-0 wget build-essential automake pkg-config autoconf autogen vim libmysqlclient-dev libxml2-dev libsnmp-dev libssh2-1-dev libopenipmi-dev libevent-dev libcurl4-openssl-dev libpcre3-dev unixodbc-dev golang-go openjdk-17-jdk libldap2-dev libgnutls28-dev libmodbus-dev libmysqlclient-dev net-tools

Compile Zabbix from source

  1. wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.7.tar.gz
  2. tar xvfz zabbix-5.4.7.tar.gz
  3. cd zabbix-5.4.7
  4. ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-ssh2 --with-unixodbc --enable-proxy --enable-java --enable-webservice --enable-ipv6 --with-ldap --enable-agent2 --with-openssl --with-libmodbus --prefix=/var/lib/zabbix
  5. make
  6. make install
  7. Copy Zabbix UI (Web Interface) cp -Rfv ~/zabbix-5.4.7/ui/ /var/lib/zabbix_ui

Install zabbix-server SystemD Service

  1. sudo addgroup --system --quiet zabbix

  2. sudo adduser --quiet --system --disabled-login --ingroup zabbix --home /var/lib/zabbix --no-create-home zabbix

  3. sudo mkdir -m u=rwx,g=rwx,o= -p /var/lib/zabbix

  4. sudo chown zabbix:zabbix /var/lib/zabbix

  5. Create the service zabbix-server in SystemD

    sudo tee /etc/systemd/system/zabbix-server.service <<EOF
    [Unit]
    Description=Zabbix Server (MySQL/MariaDB)
    Documentation=man:zabbix_server
    After=network.target mysql.service
    
    [Service]
    Type=simple
    User=zabbix
    Group=zabbix
    ExecStart=/var/lib/zabbix/sbin/zabbix_server --foreground
    ExecReload=/var/lib/zabbix/sbin/zabbix_server -R config_cache_reload
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
  6. Configure Server Conf file: /var/lib/zabbix/etc/zabbix_server.conf

    Example: Configuration File Options

    LogType=file
    LogFile=/tmp/zabbix_server.log
    ListenIP=127.0.0.1
    ListenPort=9997
    DebugLevel=3
    DBHost=localhost
    DBName=zabbix
    DBUser=zabbix
    DBPassword=xuechae1wahc8Jee8ceeni
    StartPollers=10
    StartPreprocessors=10
    StartPollersUnreachable=10
    StartPingers=10
    StartDiscoverers=10
    StartHTTPPollers=10
    StartTimers=10
    StartAlerters=10
    CacheSize=500M
    StartDBSyncers=4
    HistoryCacheSize=160M
    HistoryIndexCacheSize=114M
    TrendCacheSize=114M
    Timeout=4
    LogSlowQueries=3000
    StartLLDProcessors=10
    StatsAllowedIP=127.0.0.1
    StartReportWriters=2
    WebServiceURL=http://localhost:9998/report
    
  7. sudo systemctl daemon-reload

  8. sudo systemctl start zabbix-server

  9. sudo systemctl enable zabbix-server

  10. Verify: sudo systemctl status -l zabbix-server

Notes

  1. GnuTLS is not compatible with zabbix-agent2
  2. Proceed with the Database Configuration to be used by Zabbix-Server
  3. Adjust the Zabbix-Server configuration file: vim /var/lib/zabbix/etc/zabbix_server.conf
  4. Check the Zabbix-Server log file: tail -f /tmp/zabbix_server.log

Install MySQL Server

  1. sudo apt-get install mariadb-server mariadb-common

Create Database Credentials

  1. mysql -uroot -p<password>
  2. create database zabbix character set utf8 collate utf8_bin;
  3. create user 'zabbix'@'localhost' identified by '<password>';
  4. grant all privileges on zabbix.* to 'zabbix'@'localhost';
  5. flush privileges;
  6. quit;

Import Zabbix Schema

  1. mysql -uzabbix -p<password> zabbix < ~/zabbix-5.4.7/database/mysql/schema.sql
  2. mysql -uzabbix -p<password> zabbix < ~/zabbix-5.4.7/database/mysql/images.sql
  3. mysql -uzabbix -p<password> zabbix < ~/zabbix-5.4.7/database/mysql/data.sql

By default Ubuntu 21.10 will install PHP 8.0

Install Packages

  1. sudo apt -y install software-properties-common
  2. sudo add-apt-repository ppa:ondrej/php
  3. sudo apt update
  4. sudo apt-get install php7.4 php7.4-fpm php7.4-cli php7.4-json php7.4-common php7.4-ldap php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath php-pear php7.4-amqp php7.4-zmq nginx
  5. sudo systemctl stop apache2
  6. sudo systemctl disable apache2
  7. sudo systemctl restart php7.4-fpm
  8. sudo systemctl enable nginx
  9. sudo systemctl start nginx

Configure VirtualHost

  1. Create the file /etc/nginx/sites-enabled/zabbix with the content
    server {
         listen 80;
         root /var/lib/zabbix_ui;
         index index.php index.html index.htm index.nginx-debian.html;
         server_name 41013e43741c.mylabserver.com;
         server_name monitor.truckspyinfra.com;
         if ($request_uri ~ "^[^?]*?//") {
             rewrite "^" $scheme://$host$uri permanent;
         }
         location / {
                 try_files $uri $uri/ =404;
         }
         location ~ \.php$ {
                 include snippets/fastcgi-php.conf;
                 fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
         }
    }
    
    Replace 41013e43741c.mylabserver.com with your ServerName
  2. Tune-up /etc/php/7.4/fpm/php.ini and restart php-fom with: sudo systemctl restart php7.4-fpm
  3. nginx -t
  4. sudo systemctl restart nginx

Install Required Packages

  1. sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
  2. sudo bash -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list"
  3. sudo apt install google-chrome-stable

Install the Service

  1. Create zabbix-webservice service in SystemD
sudo tee /etc/systemd/system/zabbix-webservice.service <<EOF
  [Unit]
  Description=Zabbix Web Service
  After=network.target mysql.service

  [Service]
  Type=simple
  User=zabbix
  Group=zabbix
  ExecStart=/var/lib/zabbix/sbin/zabbix_web_service -c /var/lib/zabbix/etc/zabbix_web_service.conf
  Restart=always

  [Install]
  WantedBy=multi-user.target
EOF
  1. Configure WebService Conf file: /var/lib/zabbix/etc/zabbix_web_service.conf

    Example: Configuration File Options

    LogType=console
    DebugLevel=4
    AllowedIP=127.0.0.1,::1
    ListenPort=9998
    
  2. Enable service: sudo systemctl enable zabbix-webservice

  3. Start service: sudo systemctl start zabbix-webservice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment