How to install and configure Zabbix-5 on CentOS 7 and Agent on Centos7, Ubuntu18, Suse 15, windows2018

Zabbix is an open-source monitoring software used for collecting metrics from various devices and systems such as networks devices, VM systems, Linux/Windows systems, and cloud services. Zabbix can send notification alerts of issues in any monitored system.

In this tutorial, we shall provide you a guide on installing and configuring Zabbix-5 on CentOS system. Before that let’s take a look at the prerequisites.

Prerequisites

  • Apache web server
  • PHP with required extensions
  • MySQL/ MariaDB server
  • Installing Zabbix on CentOS
  • Login to Terminal as root and start firing up the commands below.

Step 1 – Install yum-utils

# yum install yum-utils

Step 2 – Download and install the Zabbix 5 repository
Use the following commands:

rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

Install Zabbix

#  yum install zabbix-server-mysql zabbix-get zabbix-agent -y

Install Zabbix Front end.

Edit file and enable Zabbix-frontend repository

# vi /etc/yum.repos.d/zabbix.repo

[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1      # Change from 0 to 1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

Enable Redhat Software Collection 

# yum install centos-release-scl -y

Install Zabbix Front end. 

# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl

Step 3 – Install MariaDB

# yum  install mariadb-server -y

Start the MariaDB service.

# systemctl start mariadb

Enable MariaDB on system boot.

# systemctl enable mariadb

Run the following command to secure MariaDB.

# mysql_secure_installation

Add a new root password and continue. Then it will ask a few questions. Type “Y” to agree to that.

Login to DB server and verify.

# mysql -u root -p

Step 4 – Create a Database for Zabbix

You can choose any name for the database in place of fosslinuxzabbix in the below command:

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;

Create a DB user and grant privileges.

MariaDB [(none)]> create user 'zabbix'@'localhost' identified BY 'redhat';

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost ;

Flush privileges.

MariaDB [(none)]> flush privileges;

Step 5 – Configure Zabbix

Generally, Zabbix installation package gives SQL file which includes an initial schema and data for the Zabbix server with MySQL.

Change directory and go the Zabbix directory.

# cd /usr/share/doc/zabbix-server-mysql-5.0.30/

Import the MySQL dump file.

# zcat create.sql.gz | mysql -u zabbix -p zabbix

Now modify the Zabbix configuration file with Database details.

# vi /etc/zabbix/zabbix_server.conf

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=redhat

Then save and exit the file. Start Zabbix service.

# systemctl start zabbix-server

Enable Zabbix on system boot.

# systemctl enable zabbix-server

Check the Zabbix server is running or not by checking the log file

# tail /var/log/zabbix/zabbix_server.log

Edit file and uncomment and set the right timezone for you.

# cat /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf | grep php_value
php_value[session.save_handler] = files
php_value[session.save_path] = /var/opt/rh/rh-php72/lib/php/session/
php_value[max_execution_time] = 300
php_value[memory_limit] = 512M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000
php_value[date.timezone] = Asia/Kolkata

Start/enable the Zabbix server and agent processes: 

# systemctl start zabbix-server zabbix-agent httpd rh-php72-php-fpm mariadb

# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm mariadb

Step 6 – Setup Zabbix

You can access Zabbix using following URL:

http://192.168.2.212/zabbix/

You should see the welcome page.

 


 

Click Next.

Check Of Pre-Requisites

Here you Zabbix will check installed PHP, MySQL/MariaDB versions and parameters, etc.

 


If you see any parameter failing, you have to modify it and refresh the page.


E.g.:- for PHP parameter you have to modify (/etc/php.ini) file. Click Next.

Configure DB Connection

 


Add database details and click Next. Then you will see server details, and you can add any name for “Name”.

Zabbix Server Details

Click Next. You should see the Database details and server details.

Pre-installation Summary

 

Click Next to complete the installation.

 

 Successfully Installed

Click finish to access the login page.

Login Page

 

The default login name is “Admin” and password is “zabbix”. You will go to the Zabbix Dashboard.

Dash Board

 



Step 10 – Monitor Servers with Zabbix Agent

Zabbix Agent collects the data from the client machine and sends them to the Zabbix Server. We will install the Zabbix agent on the Ubuntu machine to monitor it.

Execute following commands to install the agent on Ubuntu 18.04 LTS. As usual, replace the URL with the latest from the official website.

# wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1%2Bbionic_all.deb
# dpkg -i zabbix-release_5.0-1+bionic_all.deb
# apt update

Install agent.

# apt install zabbix-agent2

Execute following commands to install the agent on Centos 7.

# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

# yum install zabbix-agent2

Now modify the agent configuration file.

# vi /etc/zabbix/zabbix_agent2.conf

Modify the following parameters. Replace IP and hostname with yours in the below command:

Server=192.168.2.212
ServerActive=
192.168.2.212
Hostname=client-name

Save and exit the file.

Restart Zabbix agent.

# systemctl restart zabbix-agent2

Enable on system boot.

# systemctl enable zabbix-agent2

Step 11 – Add host to monitor on Zabbix server
Go to Configuration > Hosts > Create host.

Create Host
Then you will get the interface as follows:

 





 

Add New Host
Add Hostname, Visible Name and agent interface IP. Select a group from the list. In our scenario, we are going to monitor the Centos server. So we will select Linux servers from the list.

 





 

Select Group
Select and go to Template Tab. Then click on the select button and select “Template OS Linux” from the list.

Select Template
Click “add,” and it will list linked templates.

 

Add Template
Click on the update button to update.

  


Step 12 – View Graphs

Go to Monitoring > Graphs. You can select needed group, host and graph to display the graphs.

CPU Graph


Memory Usage

 

 



 

Congratulations! You have successfully configured Zabbix server and added hosts to monitor. Let us know your feedback in the comments below.

 

 
To Enable Auto Discovery 
 
Monitoring large environments could be a nightmare without automation. Zabbix provides several ways of automating the management of such environments. Devices and elements of devices, such as file systems and network interfaces, can be added and removed automatically as they come and leave an organization.

Now modify the agent configuration file.

# vi /etc/zabbix/zabbix_agent2.conf

Modify the following parameters. Replace IP and hostname with yours in the below command:

Server=192.168.2.212
ServerActive=192.168.2.212
Hostname=client-name
HostMetadata=LinuxServer

Click on Configuration -> Action --> Auto Registation --> Create Action
 
Action tab --> Name = LinuxServer --> New Condition : Host metadata = LinuxServer --> Add
 
 
Operation Tab: Operation : Add host, Add to host group, Link to template
 
 
 
After some time you can see the host visible in Zabbix portal.

 

How to enable encryption of data flow between Zabbix server and agent. 
 
We will enable encryption for lamp01.darole.org servers. 
 
 
First create folder to store the secret key. 
 
[root@lamp01 ~]# mkdir /home/zabbix
[root@lamp01 ~]# cd /home/zabbix/
 
Generate the secret key. 
 
[root@lamp01 zabbix]# openssl rand -hex 32 > secret.psk
[root@lamp01 zabbix]# cat secret.psk
7496dc82e63db9ab05279e64913f11a4aba749b5f039162cf85ca5e2cc948aa9
 
Give Zabbix user permission to access the key 
 
[root@lamp01 zabbix]# ls -lrt
total 4
-rw-r--r-- 1 root root 65 Nov 10 16:24 secret.psk
[root@lamp01 zabbix]# chown zabbix:zabbix secret.psk
 
Only Zabbix user and group can access the key 
 
[root@lamp01 zabbix]# ls -lh
total 4.0K
-rw-r--r-- 1 zabbix zabbix 65 Nov 10 16:24 secret.psk
[root@lamp01 zabbix]# chmod 640 secret.psk
 
Change the below configuration 
 
[root@lamp01 zabbix]# vi /etc/zabbix/zabbix_agentd.conf
# TLSConnect=unencrypted         ### Comment the line 
TLSConnect=psk
# TLSAccept=unencrypted        ### Comment the line 
 TLSAccept=psk
# TLSPSKIdentity= ### Comment the line 
TLSPSKIdentity=lamp01.darole.org
# TLSPSKFile=                    ### Comment the line 
TLSPSKFile=/home/zabbix/secret.psk
 
Restart the zabbix agent to update the configuration file 
 
[root@lamp01 zabbix]# systemctl restart zabbix-agent
 
Now login zabbix portal go Configuration >>  Host >> lamp01.darole.org 
Go to Encryption tab and update the below.  

 
After few minute you will see the agent encryption is enabled. 


 
Monitor Docker containers using Zabbix 5

1. Check the docker containers.
 
root@dock01:~# docker ps

2. Give the permission to zabbix agent to monitor docker. 
 
root@dock01:~# usermod -aG docker zabbix

3. Restart Zabbix Agent and check status.

root@dock01:~# systemctl restart zabbix-agent2
root@dock01:~# systemctl status zabbix-agent2

4. Add Docker template to client servers. 


5. To check the connectivity from zabbix server to docker client use below command. 

[root@zap01 ~]# zabbix_get -s dock01 -k docker.info

6. After some time check data collection in zabbix portal. 




 If we get the below error will monitoring docker 
Cannot fetch data: Get "http://1.28/images/json": dial unix /var/run/docker.sock: connect: permission denied.

Solution: Give zabbix user the permission to read/write the docker.sock file.  

#setfacl --modify user:zabbix:rw /var/run/docker.sock
 
 To configure email alerts in Zabbix, follow these steps:
  • Log in to the Zabbix portal. Go to the Administration tab, then click on Media types. 

  • Provide the SMTP server hostname, the SMTP HELO domain name and enable the SMTP email address. 


  • Go to Configuration and enable the action.


  • Check again in Administration tab and click on Admin.


  • Update the media type email and sent to email id. 



 

No comments:

Post a Comment