history 26 of 36
Install Zabbix from Source on CentOS 6.3
My steps for compiling Zabbix server and agent on CentOS 6.3, creating its MySQL database and copying the PHP web frontend into Apache.
Written
- Monitoring and security
- Written for CentOS 6.3
- Written for Zabbix 1.8
- Written for MySQL
From my Linux study notes, 2016. Some commands and versions here are old, so please reuse them carefully. Anything marked "added later", and the notes at the end, explain what has changed since.
Here are my simple steps to install Zabbix on a CentOS machine. Zabbix is a monitoring system: the server collects data from agents running on the machines you want to watch, and a PHP web frontend shows the results.
Before you start
-
Run the commands as root (or with
sudo). -
You need a MySQL server for the Zabbix database. Step 1 installs the MySQL client and development files only. On CentOS 6 the server package is
mysql-serverand its service ismysqld:Terminal window yum install mysql-serverservice mysqld startchkconfig mysqld on -
You also need Apache and PHP for the web frontend (
yum install httpd php). -
Use a test server first.
Install Zabbix
-
Install the build dependencies:
Terminal window yum install zlib-devel mysql-devel glibc-devel curl-devel gcc automake mysql libidn-devel openssl-devel net-snmp-devel rpm-devel OpenIPMI-develThe
-develpackages contain the header files the compiler needs for the features enabled in step 6 (MySQL, SNMP, curl, IPMI). -
Install the EPEL repository:
Terminal window rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpmCorrection: this is the release package for EPEL 5 (CentOS/RHEL 5, 32-bit), not CentOS 6, and that download address no longer exists. On CentOS 6 you need the EPEL 6 release package instead. Where the
epel-releasepackage is offered by your system’s own repositories, this is the simplest way to get it:Terminal window yum install epel-releaseCentOS 6 and EPEL 6 are both end of life, so these repositories have been moved to archive servers and this step may fail today. See the notes at the end.
-
Install
iksemel, which Zabbix uses for Jabber (XMPP) notifications:Terminal window yum --enablerepo=epel install iksemel iksemel-devel -
Download the Zabbix installation file from www.zabbix.com/download, or:
Terminal window wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8.1/zabbix-1.8.1.tar.gz?use_mirror=freefrBecause of the
?use_mirror=freefrpart,wgetmay save the file with that text in its name. Adding-O zabbix-1.8.1.tar.gzsaves it with a clean name:Terminal window wget -O zabbix-1.8.1.tar.gz "http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8.1/zabbix-1.8.1.tar.gz?use_mirror=freefr"The original post goes straight to
cdwithout extracting the archive. Extract it first:Terminal window tar xzf zabbix-1.8.1.tar.gz -
Go into the source folder:
Terminal window cd zabbix.1.2.3Correction: the folder name must match the version you downloaded. For the file above it is:
Terminal window cd zabbix-1.8.1 -
Configure the build with the server, the agent and the features you need:
Terminal window ./configure --enable-server --with-mysql --with-net-snmp --with-jabber --with-libcurl --with-openipmi --enable-agent--enable-serverand--enable-agentbuild the Zabbix server and the agent.--with-mysqlstores data in MySQL.--with-net-snmp,--with-jabber,--with-libcurland--with-openipmiturn on SNMP checks, Jabber alerts, web checks and IPMI checks.
If
configurestops with an error, it usually names the missing-develpackage. -
Install
makeif it is not already installed:Terminal window yum install make -
Compile:
Terminal window make -
Install:
Terminal window make install
Create the database
-
Log in to MySQL (
mysql -u root -p) and create the database:create database your_username character set utf8;Correction: this should be the database name, not the username, so that it matches the next command:
create database your_database character set utf8; -
Create the Zabbix database user and give it access:
grant all privileges on your_database.* to 'your_username'@'localhost' identified by 'your_password';Type
exitto leave MySQL. -
Import the SQL files from the downloaded files. Check where they are: the folder depends on the Zabbix version (look under the
createfolder in the source).Terminal window mysql your_database < mysql.sqlmysql your_database < data.sqlmysql your_database < images_mysql.sqlImport them in this order: the first file creates the tables, the others fill them. If MySQL asks for a login, add
-u your_username -p. Run each command from the folder that holds that file, or give the full path to the file.
Configure Zabbix
-
Create the config folder, go back to the top of the Zabbix source folder and copy the sample config files:
Terminal window mkdir /etc/zabbixcd ../..cp misc/conf/{zabbix_server.conf,zabbix_agentd.conf} /etc/zabbixcd ../..goes up two levels, which takes you from the SQL folder in step 12 back to the source folder. Runpwdto check you are in thezabbix-1.8.1folder before copying. -
Edit the server config and enter your MySQL information:
Terminal window vi /etc/zabbix/zabbix_server.confThe settings to change are the database ones, for example:
DBName=your_databaseDBUser=your_usernameDBPassword=your_password
Install the web frontend
-
Install the PHP modules the frontend needs:
Terminal window yum install php-mysql php-gd php-bcmath php-mbstring php-xml -
Copy the frontend files into Apache’s web folder:
Terminal window cp -r frontends/php/ /var/www/html/ -
Rename the folder so the frontend is at
/zabbix:Terminal window mv /var/www/html/php/ /var/www/html/zabbix -
Edit the PHP settings:
Terminal window nano /etc/php.iniAdd (or change) the following values:
max_execution_time = 600memory_limit = 256Mpost_max_size = 32Mmbstring.func_overload = 2Restart Apache afterwards so PHP picks up the changes:
Terminal window service httpd restart
My original notes stop here. The next stage is to open http://your-server-ip/zabbix in a browser to finish the frontend setup, and to start the Zabbix server and agent. Check the Zabbix documentation for your version for those steps.
Notes for today
-
CentOS 6 reached end of life on 30 November 2020. Rocky Linux and AlmaLinux are the common free replacements; Debian and Ubuntu are alternatives.
-
Zabbix 1.8 is very old. Current Zabbix releases are normally installed from the official Zabbix package repositories rather than compiled by hand. Follow the instructions for your system at https://www.zabbix.com/documentation/.
-
PHP:
mbstring.func_overloadwas deprecated in PHP 7.2 and removed in PHP 8.0, so leave that line out on modern PHP. -
MySQL 8:
GRANT ... IDENTIFIED BYno longer works in MySQL 8.0. Create the user first, then grant:CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';GRANT ALL PRIVILEGES ON your_database.* TO 'your_username'@'localhost'; -
Services and packages:
service/chkconfigbecamesystemctl start/systemctl enable, andyumbecamednfon newer Red Hat-family systems. -
Security: use a strong password for the database user, and make
/etc/zabbix/zabbix_server.confreadable only by root and the Zabbix user, as it contains the database password.