{"id":12705,"date":"2022-05-12T20:13:37","date_gmt":"2022-05-12T17:13:37","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12705"},"modified":"2024-03-09T13:42:14","modified_gmt":"2024-03-09T10:42:14","slug":"install-zabbix-server-on-ubuntu","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-zabbix-server-on-ubuntu\/","title":{"rendered":"Install Zabbix Server on Ubuntu 22.04"},"content":{"rendered":"\n

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

Install Zabbix Server on Ubuntu 22.04<\/h2>\n\n\n\n

Zabbix can be built from the source code or can be installed from Zabbix repository.<\/p>\n\n\n\n

Install and Buld Zabbix from Source on Ubuntu 22.04<\/h3>\n\n\n\n

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

Zabbix is a PHP based app. Hence, you need to install LAMP stack.<\/p>\n\n\n\n

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.<\/p>\n\n\n\n

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

Create Zabbix Database and Database User<\/h3>\n\n\n\n

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.<\/p>\n\n\n\n

mysql -u root -p<\/code><\/pre>\n\n\n\n
create database zabbixdb character set utf8 collate utf8_bin;<\/code><\/pre>\n\n\n\n
create user zabbixadmin@localhost identified by 'P@SSw0RD';<\/code><\/pre>\n\n\n\n
grant all on zabbixdb.* to zabbixadmin@localhost;<\/code><\/pre>\n\n\n\n
flush privileges;\nquit<\/code><\/pre>\n\n\n\n

Create Zabbix User System Account<\/h3>\n\n\n\n

A Zabbix system account is required for running Zabbix daemons. Hence you can create it by running the command below;<\/p>\n\n\n\n

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

Download Zabbix Source Code<\/h3>\n\n\n\n

Navigate to Zabbix download page<\/a> and download the latest and stable Zabbix source archive. You can simply get the download link and use wget<\/strong> command download it.<\/p>\n\n\n\n

wget https:\/\/cdn.zabbix.com\/zabbix\/sources\/stable\/6.0\/zabbix-6.0.4.tar.gz<\/code><\/pre>\n\n\n\n

Extract Zabbix Source Code<\/h3>\n\n\n\n

Navigate to the directory in which you downloaded Zabbix source code and extract it.<\/p>\n\n\n\n

tar xzf zabbix-6.0.4.tar.gz<\/code><\/pre>\n\n\n\n

Configure Zabbix Sources<\/h3>\n\n\n\n

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.<\/p>\n\n\n\n

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

If the configure script completes successfully, you should see a summary of configuration.<\/p>\n\n\n\n

\nConfiguration:\n\n  Detected OS:           linux-gnu\n  Install path:          \/usr\/local\n  Compilation arch:      linux\n\n  Compiler:              cc\n  Compiler flags:         -g -O2  \n\n  Library-specific flags:\n    database:              -I\/usr\/include\/mariadb -I\/usr\/include\/mariadb\/mysql   \n    libXML2:               -I\/usr\/include\/libxml2\n    Net-SNMP:               -I\/usr\/local\/include -I\/usr\/lib\/x86_64-linux-gnu\/perl\/5.34\/CORE -I. -I\/usr\/include\n    libssh2:               -I\/usr\/include\n    LDAP:                  -I\/usr\/include\n\n  Enable server:         yes\n  Server details:\n    With database:         MySQL\n    WEB Monitoring:        cURL\n      SSL certificates:      \/usr\/local\/share\/zabbix\/ssl\/certs\n      SSL keys:              \/usr\/local\/share\/zabbix\/ssl\/keys\n    SNMP:                  yes\n    IPMI:                  no\n    SSH:                   yes (libssh2)\n    TLS:                   no\n    ODBC:                  no\n    Linker flags:           -L\/usr\/lib\/x86_64-linux-gnu   -L\/usr\/lib\/x86_64-linux-gnu\/     -L\/usr\/lib       -L\/usr\/lib  -rdynamic     \n    Libraries:              -lmariadb       -lnetsnmp -lssh2   -lz -lpthread -levent  -lldap -llber   -lcurl -lm   -lxml2   -lpcre \n    Configuration file:    \/usr\/local\/etc\/zabbix_server.conf\n    External scripts:      \/usr\/local\/share\/zabbix\/externalscripts\n    Alert scripts:         \/usr\/local\/share\/zabbix\/alertscripts\n    Modules:               \/usr\/local\/lib\/modules\n\n  Enable proxy:          no\n\n  Enable agent:          yes\n  Agent details:\n    TLS:                   no\n    Modbus:                no\n    Linker flags:              -L\/usr\/lib  -rdynamic     \n    Libraries:              -lz -lpthread  -lldap -llber   -lcurl -lm   -lxml2   -lpcre \n    Configuration file:    \/usr\/local\/etc\/zabbix_agentd.conf\n    Modules:               \/usr\/local\/lib\/modules\n\n  Enable agent 2:        no\n\n  Enable web service:    no\n\n  Enable Java gateway:   no\n\n  LDAP support:          yes\n  IPv6 support:          yes\n\n***********************************************************\n*            Now run 'make install'                       *\n*                                                         *\n*            Thank you for using Zabbix!                  *\n*                                  *\n***********************************************************\n<\/code><\/pre>\n\n\n\n

Compile and Install Zabbix 4.x from Sources on Debian 10 Buster<\/h3>\n\n\n\n

Next, run the command below to compile and install Zabbix<\/p>\n\n\n\n

sudo make install<\/code><\/pre>\n\n\n\n

Zabbix configuration files will be installed on \/usr\/local\/etc<\/strong> directory.<\/p>\n\n\n\n

Configuring Zabbix on Ubuntu 22.04<\/h3>\n\n\n\n

To begin with, configure Zabbix database connection details.<\/p>\n\n\n\n

Open the configuration file, \/usr\/local\/etc\/zabbix_server.conf<\/code><\/strong>, and replace the values for DBName<\/strong>, DBUser<\/strong>, DBPassword<\/strong> with what you set while creating database. Uncomment the line # DBHost=localhost<\/strong><\/code>.<\/p>\n\n\n\n

vim \/usr\/local\/etc\/zabbix_server.conf<\/code><\/pre>\n\n\n\n
\n...\nDBHost=localhost<\/strong>\n...\nDBName=zabbixdb\n<\/strong>...\nDBUser=zabbixadmin\n<\/strong>...\nDBPassword=P@SSw0RD\n<\/strong>...\n<\/code><\/pre>\n\n\n\n

Change Zabbix Server Log Directory<\/h3>\n\n\n\n

By default, Zabbix writes its log file to \/tmp<\/strong> directory. Change it on the configuration file such that it writes it to \/var\/log<\/strong>.<\/p>\n\n\n\n

LogFile=\/var\/log\/zabbix_server.log<\/code><\/pre>\n\n\n\n

Save and exit the configuration file (:wq! or ZZ<\/code><\/strong>).<\/p>\n\n\n\n

Now, create this log file and set the ownership to Zabbix user.<\/p>\n\n\n\n

touch \/var\/log\/zabbix_server.log\nchown zabbix:zabbix \/var\/log\/zabbix_server.log<\/code><\/pre>\n\n\n\n

Import Zabbix Default Database and Initial Data<\/h3>\n\n\n\n

The Zabbix default MySQL database and initial data for each kind of database backend is located under the database<\/strong> subdirectory on the Zabbix source directory,<\/p>\n\n\n\n

cd ~\/zabbix-6.0.4\/database\/mysql\/<\/code><\/pre>\n\n\n\n
ls -1 *.sql<\/code><\/pre>\n\n\n\n
data.sql\ndouble.sql\nhistory_pk_prepare.sql\nimages.sql\nschema.sql<\/code><\/pre>\n\n\n\n

Begin by importing the database schema, Images.sql and then data.sql.<\/p>\n\n\n\n

mysql -u zabbixadmin -p zabbixdb < schema.sql<\/code><\/pre>\n\n\n\n
mysql -u zabbixadmin -p zabbixdb < images.sql<\/code><\/pre>\n\n\n\n
mysql -u zabbixadmin -p zabbixdb < data.sql<\/code><\/pre>\n\n\n\n

Running Zabbix Server and Agent<\/h3>\n\n\n\n

Create a systemd service for Zabbix server.<\/p>\n\n\n\n

\ncat > \/etc\/systemd\/system\/zabbix-server.service << EOL\n[Unit]\nDescription=Zabbix Server\nAfter=syslog.target network.target mariadb.service\n \n[Service]\nType=oneshot\nUser=zabbix\nExecStart=\/usr\/local\/sbin\/zabbix_server\nExecReload=\/usr\/local\/sbin\/zabbix_server -R config_cache_reload\nRemainAfterExit=yes\nPIDFile=\/var\/run\/zabbix\/zabbix_server.pid\n \n[Install]\nWantedBy=multi-user.target\nEOL\n<\/code><\/pre>\n\n\n\n

Create a systemd service for Zabbix agent<\/p>\n\n\n\n

\ncat >  \/etc\/systemd\/system\/zabbix-agent.service << EOL\n[Unit]\nDescription=Zabbix Agent\nAfter=syslog.target network.target\n \n[Service]\nType=oneshot\nUser=zabbix\nExecStart=\/usr\/local\/sbin\/zabbix_agentd\nRemainAfterExit=yes\nPIDFile=\/var\/run\/zabbix\/zabbix_agent.pid\n \n[Install]\nWantedBy=multi-user.target\nEOL\n<\/code><\/pre>\n\n\n\n

Reload systemd configuration<\/p>\n\n\n\n

systemctl daemon-reload<\/code><\/pre>\n\n\n\n

Start and enable Zabbix server,agent deamon to run on system start.<\/p>\n\n\n\n

systemctl enable --now zabbix-server zabbix-agent<\/code><\/pre>\n\n\n\n

If firewall is running, open TCP port 10051 for remote connection.<\/p>\n\n\n\n

ufw allow 10051\/tcp<\/code><\/pre>\n\n\n\n

Installing Zabbix Frontend on Ubuntu 22.04<\/h3>\n\n\n\n

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

Create Zabbix Web root directory.<\/p>\n\n\n\n

mkdir \/var\/www\/html\/zabbix<\/code><\/pre>\n\n\n\n

Next, copy Zabbix PHP files.<\/p>\n\n\n\n

cp -a ~\/zabbix-6.0.4\/ui\/* \/var\/www\/html\/zabbix\/<\/code><\/pre>\n\n\n\n

Set the user and group ownership of the Zabbix directory to www-data<\/strong>.<\/p>\n\n\n\n

chown -R www-data:www-data \/var\/www\/html\/zabbix\/<\/code><\/pre>\n\n\n\n

Configure Zabbix Frontend<\/h3>\n\n\n\n

Update the PHP configurations by making the following changes<\/p>\n\n\n\n