Install Zabbix Server on Ubuntu 22.04

|
Last Updated:
|
|

In this guide, we are going to learn how to install Zabbix server on Ubuntu 22.04. Zabbix is an enterprise class monitoring solution for any kind of IT infrastructure, services, applications, cloud resources.

Install Zabbix Server on Ubuntu 22.04

Zabbix can be built from the source code or can be installed from Zabbix repository.

Install and Buld Zabbix from Source on Ubuntu 22.04

As of this writing, there are no Zabbix server repositories for Ubuntu 22.04. Only available for agents. As a result, we will built and install Zabbix server from sources.

Zabbix is a PHP based app. Hence, you need to install LAMP stack.

We tried PHP 8.1 and we experienced a lot of Frontend errors! As such, we are using PHP 7.4 in this guide. PHP 7.4 is provided by Ondrej PHP PPA repositories.

apt install software-properties-common -y
add-apt-repository ppa:ondrej/php --yes &> /dev/null
apt update
apt install build-essential libmariadb-dev sudo libxml2-dev \
php7.4 php7.4-gd php7.4-xml php7.4-bcmath php7.4-mbstring libapache2-mod-php7.4 \
php7.4-ldap php7.4-mysql apache2 mysql-server snmp libsnmp-dev \
libcurl4-openssl-dev libevent-dev libpcre3-dev libxml2-dev \
libmariadb-dev libopenipmi-dev pkg-config libssh2-1-dev libldap-dev

Create Zabbix Database and Database User

Login to MariaDB server and create a database and a database user for Zabbix. The database user should have all the privileges on the zabbix database.

mysql -u root -p
create database zabbixdb character set utf8 collate utf8_bin;
create user zabbixadmin@localhost identified by 'P@SSw0RD';
grant all on zabbixdb.* to zabbixadmin@localhost;
flush privileges;
quit

Create Zabbix User System Account

A Zabbix system account is required for running Zabbix daemons. Hence you can create it by running the command below;

sudo useradd -r -d /var/lib/zabbix -s /sbin/nologin -M zabbix
mkdir -m u=rwx,g=rwx,o= -p /var/lib/zabbix
chown zabbix:zabbix /var/lib/zabbix

Download Zabbix Source Code

Navigate to Zabbix download page and download the latest and stable Zabbix source archive. You can simply get the download link and use wget command download it.

wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.4.tar.gz

Extract Zabbix Source Code

Navigate to the directory in which you downloaded Zabbix source code and extract it.

tar xzf zabbix-6.0.4.tar.gz

Configure Zabbix Sources

Navigate to extracted Zabbix source directory and run the configure script to adapt Zabbix to the system. This step may fail if one of the required dependencies is not installed. In this guide, we are going to configure Zabbix server and agent and enable support for MariaDB database backend.

cd zabbix-6.0.4
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 \
--with-net-snmp --with-libcurl --with-libxml2 --with-ssh2 --with-net-snmp \
--with-ldap

If the configure script completes successfully, you should see a summary of configuration.


Configuration:

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

  Compiler:              cc
  Compiler flags:         -g -O2  

  Library-specific flags:
    database:              -I/usr/include/mariadb -I/usr/include/mariadb/mysql   
    libXML2:               -I/usr/include/libxml2
    Net-SNMP:               -I/usr/local/include -I/usr/lib/x86_64-linux-gnu/perl/5.34/CORE -I. -I/usr/include
    libssh2:               -I/usr/include
    LDAP:                  -I/usr/include

  Enable server:         yes
  Server details:
    With database:         MySQL
    WEB Monitoring:        cURL
      SSL certificates:      /usr/local/share/zabbix/ssl/certs
      SSL keys:              /usr/local/share/zabbix/ssl/keys
    SNMP:                  yes
    IPMI:                  no
    SSH:                   yes (libssh2)
    TLS:                   no
    ODBC:                  no
    Linker flags:           -L/usr/lib/x86_64-linux-gnu   -L/usr/lib/x86_64-linux-gnu/     -L/usr/lib       -L/usr/lib  -rdynamic     
    Libraries:              -lmariadb       -lnetsnmp -lssh2   -lz -lpthread -levent  -lldap -llber   -lcurl -lm   -lxml2   -lpcre 
    Configuration file:    /usr/local/etc/zabbix_server.conf
    External scripts:      /usr/local/share/zabbix/externalscripts
    Alert scripts:         /usr/local/share/zabbix/alertscripts
    Modules:               /usr/local/lib/modules

  Enable proxy:          no

  Enable agent:          yes
  Agent details:
    TLS:                   no
    Modbus:                no
    Linker flags:              -L/usr/lib  -rdynamic     
    Libraries:              -lz -lpthread  -lldap -llber   -lcurl -lm   -lxml2   -lpcre 
    Configuration file:    /usr/local/etc/zabbix_agentd.conf
    Modules:               /usr/local/lib/modules

  Enable agent 2:        no

  Enable web service:    no

  Enable Java gateway:   no

  LDAP support:          yes
  IPv6 support:          yes

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*                                  *
***********************************************************

Compile and Install Zabbix 4.x from Sources on Debian 10 Buster

Next, run the command below to compile and install Zabbix

sudo make install

Zabbix configuration files will be installed on /usr/local/etc directory.

Configuring Zabbix on Ubuntu 22.04

To begin with, configure Zabbix database connection details.

Open the configuration file, /usr/local/etc/zabbix_server.conf, and replace the values for DBNameDBUserDBPassword with what you set while creating database. Uncomment the line # DBHost=localhost.

vim /usr/local/etc/zabbix_server.conf

...
DBHost=localhost
...
DBName=zabbixdb
...
DBUser=zabbixadmin
...
DBPassword=P@SSw0RD
...

Change Zabbix Server Log Directory

By default, Zabbix writes its log file to /tmp directory. Change it on the configuration file such that it writes it to /var/log.

LogFile=/var/log/zabbix_server.log

Save and exit the configuration file (:wq! or ZZ).

Now, create this log file and set the ownership to Zabbix user.

touch /var/log/zabbix_server.log
chown zabbix:zabbix /var/log/zabbix_server.log

Import Zabbix Default Database and Initial Data

The Zabbix default MySQL database and initial data for each kind of database backend is located under the database subdirectory on the Zabbix source directory,

cd ~/zabbix-6.0.4/database/mysql/
ls -1 *.sql
data.sql
double.sql
history_pk_prepare.sql
images.sql
schema.sql

Begin by importing the database schema, Images.sql and then data.sql.

mysql -u zabbixadmin -p zabbixdb < schema.sql
mysql -u zabbixadmin -p zabbixdb < images.sql
mysql -u zabbixadmin -p zabbixdb < data.sql

Running Zabbix Server and Agent

Create a systemd service for Zabbix server.


cat > /etc/systemd/system/zabbix-server.service << EOL
[Unit]
Description=Zabbix Server
After=syslog.target network.target mariadb.service
 
[Service]
Type=oneshot
User=zabbix
ExecStart=/usr/local/sbin/zabbix_server
ExecReload=/usr/local/sbin/zabbix_server -R config_cache_reload
RemainAfterExit=yes
PIDFile=/var/run/zabbix/zabbix_server.pid
 
[Install]
WantedBy=multi-user.target
EOL

Create a systemd service for Zabbix agent


cat >  /etc/systemd/system/zabbix-agent.service << EOL
[Unit]
Description=Zabbix Agent
After=syslog.target network.target
 
[Service]
Type=oneshot
User=zabbix
ExecStart=/usr/local/sbin/zabbix_agentd
RemainAfterExit=yes
PIDFile=/var/run/zabbix/zabbix_agent.pid
 
[Install]
WantedBy=multi-user.target
EOL

Reload systemd configuration

systemctl daemon-reload

Start and enable Zabbix server,agent deamon to run on system start.

systemctl enable --now zabbix-server zabbix-agent

If firewall is running, open TCP port 10051 for remote connection.

ufw allow 10051/tcp

Installing Zabbix Frontend on Ubuntu 22.04

To install Zabbix Frontend, copy Zabbix PHP configuration files under ui/php/ subdirectory on the source code directory to Zabbix web server root directory.

Create Zabbix Web root directory.

mkdir /var/www/html/zabbix

Next, copy Zabbix PHP files.

cp -a ~/zabbix-6.0.4/ui/* /var/www/html/zabbix/

Set the user and group ownership of the Zabbix directory to www-data.

chown -R www-data:www-data /var/www/html/zabbix/

Configure Zabbix Frontend

Update the PHP configurations by making the following changes

  • Set the minimum size of PHP post data to 16M
sed -i '/post_max_size/s/= 8M/= 16M/' /etc/php/7.4/apache2/php.ini
  • Set PHP max_execution_time to 300s
sed -i 's/max_execution_time = 30/max_execution_time = 300/' /etc/php/7.4/apache2/php.ini
  • Set PHP max_input_time to 300s
sed -i '/max_input_time/s/= 60/= 300/' /etc/php/7.4/apache2/php.ini
  • Configure PHP timezone
sed -i 's/;date.timezone =/date.timezone = Asia\/Nicosia/' /etc/php/7.4/apache2/php.ini

Restart Apache and Proceed to finalize Zabbix Frontend configuration.

systemctl restart apache2

Configure Zabbix Web User Interface

To complete Zabbix installation, navigate to the browser and access your Zabbix server via the address http://<server-IP>/zabbix.

When access the address above, the first page you land on is Zabbix welcome page.

zabbix welcome page

Click Next Step to verify if all the Zabbix requirements have been met.

zabbix pre reqs

Configure Zabbix database connection using the connection details set before.

Install Zabbix Server on Ubuntu 22.04

Setup the Zabbix server details.

Install Zabbix Server on Ubuntu 22.04

On the Pre-installation summary, verify if all the configurations are fine.

Install Zabbix Server on Ubuntu 22.04

If all is well, click Next step to finish the installation. If all is well, you should see Zabbix installation congratulatory message.

Install Zabbix Server on Ubuntu 22.04

You have successfully setup Zabbix Frontend. Click Finish to get to Zabbix login interface.

zabbix login int

The default login credentials are:

  • Username (Note the Upper case A):  Admin
  • Password: zabbix

When you successfully login to Zabbix, you should land on the default dashboard.

zabbix dashboard

Well, there you go.

That concludes our guide on how to install Zabbix Server from Source on Ubuntu 22.04.

Read More on Documentation page.

Other Tutorials;

Install Zabbix Agent on CentOS 7 for Zabbix Monitoring

How to Monitor IT Infrastructure using Checkmk

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

1 thought on “Install Zabbix Server on Ubuntu 22.04”

  1. error : Failed to enable unit: Unit file /etc/systemd/system/zabbix-agent.service is masked.
    when i run this command : systemctl enable –now zabbix-server zabbix-agent

    Reply

Leave a Comment