Latest

Saturday, 20 June 2020

How to install Cacti Server on CentOS 8

Install Cacti Server on CentOS 8

In this article, you will learn how to install Cacti network monitoring server on CentOS 8. This article provides the complete installation steps including SELinux configuration.

 

This Article Provides:

 

What is Cacti? :

Cacti is an open-source, web-based network monitoring and graphing tool designed as a front-end application for the open-source, industry-standard data logging tool RRDtool.

Cacti uses a Poller to collect system metrics at a predetermined intervals and graph the resulting data. Cacti can use one of two back ends: "cmd.php", a PHP script suitable for smaller installations, or "Spine" (formerly Cactid), a C-based poller which can scale to thousands of hosts.

The front end can handle multiple users, each with their own graph sets, so it is sometimes used by web hosting providers to display bandwidth statistics for their customers. Cacti can be extended to monitor any source via shell scripts and executables.

Cacti is maintained by The Cacti Group, Inc. and distributed under GNU GPL license.

Install Cacti Server on CentOS 8

Cacti Features:

Some of the popular features of Cacti network monitoring software are:

  • unlimited graph items
  • auto-padding support for graphs
  • graph data manipulation
  • flexible data sources
  • data gathering on a non-standard timespan
  • custom data-gathering scripts
  • built-in SNMP support
  • graph, devices and data sources templates
  • tree, list, and preview views of graph data
  • user and user group based management and security
  • remote data collection
  • graph aggregation
  • device, graph and tree automation
  • network discovery

 

Environment Specification:

We are using a minimal CentOS 8 KVM machine with following specification.

  • CPU - 3.4 Ghz (2 cores)
  • Memory - 2 GB
  • Storage - 20 GB
  • Operating System - CentOS 8.2
  • Hostname – cacti-01.centlinux.com
  • IP Address - 192.168.116.206 /24

 

Upgrade CentOS 8 Software Packages:

Connect with cacti-01.centlinux.com as root user by using a ssh tool.

First of all, we are upgrading the existing software packages of our CentOS 8 server.

# dnf update -y

Our CentOS 8.1 machine has been upgraded to CentOS 8.2. We can confirm it by using following commands.

# uname -a
Linux cacti-01.centlinux.com 4.18.0-193.6.3.el8_2.x86_64 #1 SMP Wed Jun 10 11:09:32 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

You can follow our previous post to upgrade CentOS 7 to CentOS 8 Server.

 

Install Apache HTTP Server on CentOS 8:

Cacti network monitoring server is a PHP based web application, therefore, we need a PHP supported web browser to run it.

We are using the popular Apache HTTP Server for this purpose.

# dnf install -y httpd httpd-devel

Enable and start Apache service.

# systemctl enable --now httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service â /usr/lib/systemd/system/httpd.service.

Allow the Apache Service in Linux firewall, to make it accessible from the network computers.

# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success

 

Install MariaDB Server on CentOS 8:

Cacti requires a MySQL database for its metadata repository. Therefore, we are installing MariaDB server. Please follow our previous article, if you want to install latest version of MariaDB on CentOS 8.

# dnf install -y mariadb-server

Enable and start MariaDB database service.

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service â /usr/lib/systemd/system/mariadb.service.

Configure MariaDB Server and set the password of root user.

# mysql_secure_installation

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!

 

Install PHP on CentOS 8:

Cacti is developed in PHP programming language, thus it requires a PHP supported web server to run. We have already installed Apache HTTP Server and now we are installing PHP on CentOS 8.

# dnf install -y php-fpm php-common php-mysqlnd php-xml php-ldap php-json php-cli php-gd php-gmp php-mbstring php-process

Enable and start PHP-FPM Service.

# systemctl enable --now php-fpm.service
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service â /usr/lib/systemd/system/php-fpm.service.

 

Install SNMP on CentOS 8:

SNMP (Simple Network Management Protocol) is an Internet standard protocol for collecting and organizing information about managed devices on IP networks.

Install net-snmp and net-snmp-utils packages to install SNMP and php-snmp to enable PHP support for SNMP.

# dnf install -y net-snmp php-snmp net-snmp-utils

 

Install RRDTool on CentOS 8:

Cacti requires RRDTool (RRD stands for Round Robin Database) for maintaining system metrics data. Therefore, we are installing rrdtool package using dnf command.

# dnf install -y rrdtool

 

Configure PHP Settings for Cacti:

To use Cacti network monitoring server, we need to customize PHP settings accordingly.

Edit /etc/php.ini configuration file and configure it for using Cacti.

# vi /etc/php.ini

Locate and set following parameters therein.

safe_mode = Off                 ; Disable safe mode
date.timezone = "Asia/Karachi"  ; Define timezone to avoid warnings on time/date functions
file_uploads = On               ; Allow import of templates
memory_limit = 400M             ; maximum amount of memory a PHP script can consume
max_execution_time = 60         ; maximum execution time (in seconds) of a PHP script

 

Install Cacti on CentOS 8:

We are downloading latest stable version of Cacti from their official website.

# cd /tmp
# wget https://www.cacti.net/downloads/cacti-1.2.12.tar.gz
--2020-06-19 09:50:55--  https://www.cacti.net/downloads/cacti-1.2.12.tar.gz
Resolving www.cacti.net (www.cacti.net)... 104.28.9.127, 172.67.196.107, 104.28.8.127, ...
Connecting to www.cacti.net (www.cacti.net)|104.28.9.127|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25126474 (24M) [application/octet-stream]
Saving to: âcacti-1.2.12.tar.gzâ

cacti-1.2.12.tar.gz 100%[===================>]  23.96M  2.34MB/s    in 11s

2020-06-19 09:51:08 (2.12 MB/s) - âcacti-1.2.12.tar.gzâ saved [25126474/25126474]

Extract downloaded tarball into default DOCUMENT_ROOT.

# tar -C /var/www/html -xzf cacti-1.2.12.tar.gz
# cd

Rename the Cacti directory to a simple name for easy accessibility.

# mv /var/www/html/cacti-1.2.12 /var/www/html/cacti

 

Create a MariaDB Database for Cacti:

Connect with MariaDB server as root user.

# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Create a database for Cacti network monitoring server.

MariaDB [(none)]> create database cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.112 sec)

Create a user for Cacti software and grant complete rights on cacti database.

MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'Str0ngPa55word';
Query OK, 0 rows affected (0.254 sec)

Grant Time Zone selection privilege to cacti user.

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost;
Query OK, 0 rows affected (0.042 sec)

Reload privileges tables.

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.083 sec)

Exit from MySQL shell.

MariaDB [(none)]> QUIT
Bye

Cacti tarball also contains a SQL script for creating the necessary database objects. We can use this script to create tables and other objects in the cacti database.

# mysql -D cacti -u cacti -pStr0ngPa55word < /var/www/html/cacti/cacti.sql

Before moving forward, we need to load the MariaDB timezone tables. Otherwise, the Cacti web installer will give you warning on timezones.

Use following command to load timezone tables with available timezones from CentOS 8 operating system.

# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p123 mysql
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.

Timezones has been successfully loaded into MariaDB tables. Don't worry about the warnings, it is because these files do not contain a valid timezone.

Edit MariaDB configuration file.

# vi /etc/my.cnf.d/mariadb-server.cnf

Set following global variables under [mysqld] section, as required by Cacti network monitoring software.

join_buffer_size=30M
innodb_file_format=Barracuda
innodb_buffer_pool_size=256M
innodb_buffer_pool_instances=1
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_io_capacity=5000
innodb_io_capacity_max=10000
innodb_large_prefix=1
character_set_client=utf8mb4
character_set_server=utf8mb4
collation_server=utf8mb4_unicode_ci

 

Configure Cacti on CentOS 8:

Edit config.php file and update parameters according to your environment.

# vi /var/www/html/cacti/include/config.php

Locate and update following parameters.

$database_username = 'cacti';
$database_password = 'Str0ngPa55word';

Make apache user as owner of the Cacti software directory.

# chown -R apache:apache /var/www/html/cacti/

Restart Apache and PHP services to apply changes.

# systemctl restart httpd.service php-fpm.service

 

Configure SELinux for Cacti on CentOS 8:

Install required SELinux commands i.e. semanage by using dnf command..

# dnf install -y policycoreutils-python-utils-2.9-9.el8.noarch

Configure SELinux to allow read/write on the following directories.

# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/log(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/snmp_queries(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_server(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/resource/script_queries(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/scripts(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/boost(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/mibcache(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/realtime(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/cache/spikekill(/.*)?"
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/cacti/rra(/.*)?"

Reapply the filecontexts on the cacti directory.

# restorecon -R /var/www/html/cacti/

Configure a cron job to run poller.php script in every 5 minutes. This script will collect and update the system metrics in /rra directory.

# echo  "*/5 * * * *    apache   /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1" >> /etc/crontab

Open URL http://cacti-01.centlinux.com/cacti in a client's browser such as Google Chrome.

01-install-cacti-centos-8-login

Login by using default username/password i.e. admin/admin

02-install-cacti-centos-8-change-password

Since, we are login to Cacti web interface for the first time, therefore, we are required to change the default password of admin user.

03-install-cacti-centos-8-license-agreement

Read and accept the License Agreement of Cacti network monitoring software.

04-install-cacti-centos-8-preinstallation-checks

If you have followed the installation steps in this article correctly, then you won't found any warning on this page.

We are skipping a warning about innodb_buffer_pool_instances, a MariaDB global variable, because we are installing MariaDB on a machine with limited memory. If you install MariaDB on a machine with more than 1 GB RAM available for InnoDB buffer, you won't see this warning.

05-install-cacti-centos-8-installation-type

Choose your preferred installation type. Since, this is our first Cacti server therefore, we have selected "New Primary Server".

06-install-cacti-centos-8-directory-permission-checks

If you have configured the SELinux correctly, then there won't be any warnings.

07-install-cacti-centos-8-critical-binary-locations-versions

Setup is checking for required binaries, their locations and required versions.

08-install-cacti-centos-8-input-validation-whitelist-protection

Setup will inform you about a security concern and how to handle it. Accept it and continue.

09-install-cacti-centos-8-default-profile

Adjust your default profile and continue.

10-install-cacti-centos-8-template-setup

Select the required device templates and continue.

11-install-cacti-centos-8-database-collation

Setup is checking the MariaDB server and database collation.

12-install-cacti-centos-8-confirm-installation

If your configurations are fine, then Cacti setup will display this page and it will ask you to start installation.

13-install-cacti-centos-8-installation-progress

14-install-cacti-centos-8-installation-completed

Cacti network monitoring server has been installed on CentOS 8.

15-install-cacti-centos-8-dashboard

After successful installation, you will reached at the Cacti Dashboard.

16-install-cacti-centos-8-graphs

You can see some graphs by clicking on the Graphs tab.

We have successfully installed and configured Cacti network monitoring software on CentOS 8. Before you begin using the Cacti network monitoring server, we recommend that you should read Cacti Beginner's Guide - Second Edition by Packt Publishing. It will be really helpful to understand the Cacti web interface and it's usage.

If you find this article useful? Don't you mind support us by Buy Me A Coffee


7 comments:

  1. Such a wonderful tutorial. Need some extra knowledge on Linux before start the play.

    ReplyDelete
  2. Indeed, i followed so many articles, but this one went through without any issues. Seamless and clear instructions with snapshots. Many thanks for the publisher.

    ReplyDelete
  3. I changed the data directory location in database, how to change socket location in php?
    PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/app/cactiserver/cactidb/mysql/mysql.socket' (2)' in Command line code:1
    Stack trace:
    #0 Command line code(1): PDO->__construct('mysql:host=loca...', 'cactiuser', 'Cacti*102030')
    #1 {main}
    thrown in Command line code on line 1

    ReplyDelete
    Replies
    1. You can customize these settings in /var/www/html/cacti/include/config.php

      Delete
    2. I made changes to below parameter and then database connection was successful.
      change database_hostname = "localhost";
      to database_hostname = "127.0.0.0";

      Delete

© 2022 CentLinux. All Rights Reserved.