How to install and configure Zabbix on CentOS 7


Hi my name is Muneeb Shoukat  In this tutorial, we shall provide you a guide on installing and configuring Zabbix on CentOS system. 

Zabbix is an open source monitoring software. You can use Zabbix to monitor your servers, cloud services, virtual machines as many more. In this article, I will show you how to install Zabbix 4.0 on CentOS 7. So, let’s get started.

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 – Disable SELinux

Open SELinux configuration and edit the file:

vim /etc/sysconfig/selinux

You can also use "Vi" and "nono". vi/vim/nano is command-line editor.

Change “SELINUX=enforcing” to  “SELINUX=disabled”

Save and exit the file.

  After change your file  save it and exit the file use :x.

If  you use vi/vim then insert ( if you want write and changing in your file )  file use " i " and after changing Enter " Esc " to insert out after do this Enter" : " :x to exit the file.  

 Then reboot the system.

Run this cmd at your command Terminal

When you Run This command its take few Time.We use this command for Reboot our system/Machine/VM/Ec2/OS 

reboot                                                                                                                                                                 

Step 2 - Update your system

Get the latest updates for your CentOS server

yum  update  -y                                                                                                                                             

Step 3 – Install and Configure Apache

Apache is Web Server, Apache is responsible for accepting directory (HTTP) requests from Internet users and sending them their desired information in the form of files and Web pages.

Use the following commands:

yum -y install httpd

check service status.

systemctl status httpd.service

If Apache service is not running, start it manually.

systemctl restart httpd.service

Enable httpd service on system boot.

 systemctl enable httpd

Step 4 – Configure Needed Repositories

Install epel and remi repos.

yum install php

yum -y install epel-release

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Disable PHP 5 repositories and enable PHP 7.2 repo.

yum-config-manager --disable remi-php54
yum-config-manager --enable remi-php72
php --version

php 5.4 to php 7.2 replace link

Step 5 – Install PHP

yum install php php-pear php-cgi php-common php-mbstring php-snmp php-gd php-pecl-mysql php-xml php-mysql php-gettext php-bcmath

Modify the PHP time Zone by editing the php.ini file. use vi if  do not  work vim

vim /etc/php.ini

Uncomment the following line and add your time zone.

Write your appropriate  Time Zone. after change your Time Zone save your file

and exit the file Cntrl X

if. you use vi/vim then insert ( if you want write and changing in your file )  file use " i " and after changing Enter " Esc " to insert out after do this Enter Cntrl X to exit the file .

date.timezone = Asia/Karachi

Step 6 – Install MariaDB

yum --enablerepo=remi install mariadb-server

Start the MariaDB service.

systemctl start mariadb.service

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.

Everythings go with "Yes"

Login to DB server and verify.

  mysql -u root -p

Step 7 – Create a Database for Zabbix

When you Run Above Command you Enter Your MariaDB server .

Now  the Time Create your Database at  your DB server which  have you install above.....
 
You can choose any name for the database in place of  Zabbixdb . like muneebdb , some things else.

DBName: zabbixdb
DBUser: zabbixuser
DBPassword: password

 create database zabbixdb character set utf8 collate utf8_bin;                                                    

When you Run this Commands its show only " Query ok, 1  Row  affected " this types show message.


Next Run This Commands



create user 'zabbixuser'@'localhost' identified BY 'password';
grant all privileges on zabbixdb.* to zabbixuser@localhost ;                     


When you Run this Commands its show only " Query ok, 0 Row  affected " this types show message.


Flush privileges.

flush privileges;

Note: your Database is created Now if you want see it

Run this command in your MariaDB Server if you want to see your created Databasees 

show databases;                                                                 

Note: Otherwise Run this Command to exit and quit your MariaDB Server. Because we done our work at DB Server AND Return at normal Shell.

quit;                                                                                    
 

Step 8 – Install Zabbix and needed dependencies

Adding Zabbix repository. Copy the latest download URL from the official website. Paste it in the below command appropriately.

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

Install Zabbix.

yum install zabbix-server-mysql  zabbix-web-mysql zabbix-agent zabbix-get

Step 9 –  Configure Zabbix

Change Time Zone by editing the Zabbix Apache configuration file.

vim /etc/httpd/conf.d/zabbix.conf

Uncomment the following line and add your Time Zone.

php_value date.timezone Asia/Karachi

PHP Parameters should look like as follows:

Chang thses all line in file:

php_value max_execution_time 300
php_value memory_limit 128M
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 always_populate_raw_post_data -1
php_value date.timezone Asia/Karachi

Restart HTTPD service.

systemctl restart httpd.service

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 used for Change directory. in this command we change current dir and go other dir.

cd /usr/share/doc/zabbix-server-mysql-4.0.4/

Import the MySQL dump file.

When you Run This command it take few seconds and get password , when you write your password its not show at shell

password :password

zcat create.sql.gz | mysql -u zabbixdb -p password

Now modify the Zabbix configuration file with Database details.

vim /etc/zabbix/zabbix_server.conf

Change the following parameters in file:

DBHost=localhost
DBName=zabbixdb
DBUser=zabbixuser
DBPassword=password

Then save and exit the file. Restart Zabbix service.

systemctl status zabbix-server.service

Enable Zabbix on system boot.

 systemctl enable zabbix-server.service
Modify firewall rules.
yum install firewald
firewall-cmd --add-service={http,https} --permanent
firewall-cmd --add-port={10051/tcp,10050/tcp} --permanent
firewall-cmd --reload

Now restart httpd service.

systemctl restart httpd

Step 10 – Setup Zabbix

You can access Zabbix using following URL:

http://public ip of your laptop/VM/EC2 /zabbix/


Next:



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




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





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







Click Next to complete the installation.








Comments

  1. hi bro if face error in DB. i need your help in DB server

    ReplyDelete

Post a Comment