How to Install and Configure Zabbix Server on CentOS 7


This guide will walk you through the steps to install and configure Zabbix 4.4.4 on a CentOS 7 server. These instruction can also be applied if you are running an RHEL 7 server.

Prerequisites

You will need one CentOS/RHEL 7 (physical or virtual) machine with minimal installed having sudo non-root user privileges.

Disabling SELinux

You should change from SELINUX=enforcing to SELINUX=disabled in /etc/selinux/config file for smooth installation of the packages:
sudo vi /etc/selinux/config
SELINUX=disabled
Save and close.

Now reboot your CentOS/RHEL machine to take changes into effect:
sudo reboot

Adding EPEL Repository

It is always recommended to add extra packages for enterprise Linux repository before installing packages on your CentOS or RHEL:
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Adding Zabbix Repository

Zabbix isn't available in yum package manager by default, so you will need to install Zabbix official repository on your CentOS or RHEL 7:
sudo yum -y install http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

Installing Apache

You can install the latest version of Apache by typing the following command:
sudo yum -y install httpd httpd-devel

Installing MariaDB

MySQL is now replaced with MariaDB on CentOS 7, so you will need to install MariaDB database using the following command:
sudo yum -y install mariadb-server mysql

Starting Services

Now start Apache and MariaDB service and make them persistent even when system reboots:
sudo systemctl start httpd
sudo systemctl start mariadb

sudo systemctl enable httpd
sudo systemctl enable mariadb

Securing MariaDB

By default MariaDB database is not secure and anyone can intrude into your database, so make it secure by executing the following script and follow the instruction:
sudo mysql_secure_installation
Response to the following prompts on your CentOS server:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Installing Zabbix

Now you can install the Zabbix server and web frontend with its database using the following command:
sudo yum -y install zabbix-server-mysql zabbix-web-mysql
You will also need to install Zabbix agent to collect data about the Zabbix server itself:
sudo yum -y install zabbix-agent

Creating Database

At this stage you will need to create a user and a database for Zabbix like below:
sudo mysql -u root -p
Type the following on mysql prompt:
create database zabbix character set utf8;
create user 'zabbix'@'localhost' identified by 'zabbixpass';
grant all privileges on zabbix.* to 'zabbix'@'localhost';
flush privileges;
quit;

Importing Zabbix Database Schema

Find out the Zabbix database schema file and then import it into your newly created database:
sudo find / -name create.sql.gz
Now import this schema file into database like below:
sudo zcat /usr/share/doc/zabbix-server-mysql-4.4.4/create.sql.gz | mysql -u zabbix -p zabbix

Database Credential Settings:

Now edit the /etc/zabbix/zabbix_server.conf file, uncomment by removing # and update the DBPassword= parameter with your zabbix database user password:
sudo vi /etc/zabbix/zabbix_server.conf
### Option: DBPassword
#       Database password.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=zabbixpass
Save and close.

Configuring PHP

The Zabbix installation process created an PHP configuration file that contains PHP settings. It is located in the directory /etc/httpd/conf.d/. You just need to uncomment date.timezone parameter and update it with your timezone. You can check supported time zones on http://php.net/manual/en/timezones.php to find the right one for you.

sudo vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Karachi
Save and close.

Now restart Apache service to take changes into effect.
sudo systemctl restart httpd

Starting Zabbix Service

Its time to start Zabbix server and make it persistent even when system reboots:
sudo systemctl start zabbix-server
sudo systemctl enable zabbix-server

sudo systemctl start zabbix-agent
sudo systemctl enable zabbix-agent
Check the Zabbix server status before proceeding to next step:
sudo systemctl status zabbix-server
If the zabbix service is failed to start, reboot your CentOS 7 machine.
sudo reboot
Once rebooted, check zabbix server status again
sudo systemctl status zabbix-server
The Zabbix server status shows up and running, so lets proceed to next step.
zabbix-server.service - Zabbix Server
   Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-12-30 03:51:36 PKT; 4s ago
  Process: 15167 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
 Main PID: 15169 (zabbix_server)
    Tasks: 38 (limit: 11513)
   Memory: 38.1M
   CGroup: /system.slice/zabbix-server.service

Adding Firewall Rules

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

Configuring Zabbix

The Zabbix web interface lets us see reports and add network devices that you wish to monitor, but it needs some initial setup before we can use it. Open up your web browser and navigate to http://your_server_name_or_ip/zabbix

The first screen like below will greet you a welcome message.

Click Next step to continue.



This page will show you the table that lists all of the prerequisites to run Zabbix. If anything missing make sure to fix it first then proceed to Next.

Provide zabbix database user password and proceed to next.


Keep it default and proceed next.


This is the summary screen, verify and proceed next.


This screen confirms that you have successfully installed Zabbix.

Click Finish


Zabbix frontend is ready! The default user name is Admin, password zabbix.


Once logged in, you will see below dashboard screen and from here you can administer and manage your Zabbix server.





Installing Zabbix Agent

In this step we will show you how to install and configure Zabbix agent 4.4.4 on a CentOS, RHEL, Ubuntu and Windows machine.

For CentOS/RHEL 7

dnf -y install http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
dnf -y install zabbix-agent
Now edit /etc/zabbix/zabbix_agentd.conf file and update the Server= parameter with your zabbix server IP
vi /etc/zabbix/zabbix_agentd.conf
### Option: Server
#       List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.
#       Incoming connections will be accepted only from the hosts listed here.
#       If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally
#       and '::/0' will allow any IPv4 or IPv6 address.
#       '0.0.0.0/0' can be used to allow any IPv4 address.
#       Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
#
# Mandatory: yes, if StartAgents is not explicitly set to 0
# Default:
# Server=

Server=Your_Zabbix_Server_IP
Save and close.
systemctl restart zabbix-agent

For CentOS/RHEL 8

dnf -y install http://repo.zabbix.com/zabbix/4.4/rhel/8/x86_64/zabbix-release-4.4-1.el8.noarch.rpm
dnf -y install zabbix-agent
Now edit /etc/zabbix/zabbix_agentd.conf file and update the Server= parameter with your zabbix server IP
vi /etc/zabbix/zabbix_agentd.conf
### Option: Server
#       List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.
#       Incoming connections will be accepted only from the hosts listed here.
#       If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally
#       and '::/0' will allow any IPv4 or IPv6 address.
#       '0.0.0.0/0' can be used to allow any IPv4 address.
#       Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
#
# Mandatory: yes, if StartAgents is not explicitly set to 0
# Default:
# Server=

Server=Your_Zabbix_Server_IP
Save and close.
systemctl restart zabbix-agent

For Ubuntu 16

sudo dpkg -i http://repo.zabbix.com/zabbix/4.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.4-1%2Bxenial_all.deb
sudo apt-get install zabbix-agent
Now edit /etc/zabbix/zabbix_agentd.conf file and update the Server= parameter with your zabbix server IP
sudo nano /etc/zabbix/zabbix_agentd.conf
### Option: Server
#       List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.
#       Incoming connections will be accepted only from the hosts listed here.
#       If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally
#       and '::/0' will allow any IPv4 or IPv6 address.
#       '0.0.0.0/0' can be used to allow any IPv4 address.
#       Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
#
# Mandatory: yes, if StartAgents is not explicitly set to 0
# Default:
# Server=

Server=Your_Zabbix_Server_IP
Save and close.
sudo service zabbix-agent restart

For Ubuntu 18/19

sudo dpkg -i http://repo.zabbix.com/zabbix/4.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.4-1%2Bbionic_all.deb
sudo apt-get install zabbix-agent
Now edit /etc/zabbix/zabbix_agentd.conf file and update the Server= parameter with your zabbix server IP
sudo nano /etc/zabbix/zabbix_agentd.conf
### Option: Server
#       List of comma delimited IP addresses, optionally in CIDR notation, or DNS names of Zabbix servers and Zabbix proxies.
#       Incoming connections will be accepted only from the hosts listed here.
#       If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally
#       and '::/0' will allow any IPv4 or IPv6 address.
#       '0.0.0.0/0' can be used to allow any IPv4 address.
#       Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.example.com
#
# Mandatory: yes, if StartAgents is not explicitly set to 0
# Default:
# Server=

Server=Your_Zabbix_Server_IP
Save and close.
sudo systemctl restart zabbix-agent

For Windows

Zabbix Windows agent can be installed from Windows MSI installer packages (32-bit or 64-bit) available for download:

To install, double-click the downloaded MSI file.


Click Next


Accept the licence to proceed to the next step.


Specify the following parameters and click next.


Click next


Click install


Click finish


Zabbix components along with the configuration file is now installed in a Zabbix Agent folder in Program Files. zabbix_agentd.exe will be set up as Windows service with automatic startup.

Adding Devices to Zabbix Server

When you are done installing Zabbix agent on your Linux or Windows machines, go back to your Zabbix server web interface and start creating devices to monitor them.

Navigate to Configuration tab


Click Hosts then click Create host


This is our Windows 10 zabbix agent machine. Specify the following parameters according to yours and click Add


Click Templates and add the templates according to your need.


When done adding hosts, navigate back to Dashboard and there you can see number of hosts you have added in zabbix server to monitor.

Navigate to Graphs, select your host and graph from the drop down list and see if your host monitoring data is being collected like below.


This is how you can add and monitor your Windows and Linux machines in zabbix server. For the devices like switches, routers, firewall etc, of course you can not install zabbix agent, but you can add and monitor them in zabbix server via SNMP and IPMI interface.

Wrapping up

In this tutorial, you set up a simple and secure solution which will help you monitor your servers. It can now warn you of problems, and you have the opportunity to plot some graphs based on the obtained data so you can analyze it and plan accordingly.

No comments:

Powered by Blogger.