How to install Cacti Monitoring Server on CentOS 8

How to install Cacti Monitoring Server on CentOS 8

Cacti is a free, open source, powerful web-based network monitoring and mapping tool. It monitors system performance, CPU load and network bandwidth utilization in a chart format. It allows you to poll the service at predetermined time intervals and graph the resulting data. It is a complete front end of RRDTool, written in PHP, and uses a MySQL database to store all necessary information.

In this tutorial, we will explain how to install the Cacti monitoring tool on CentOS 8.

prerequisites

  • A server running CentOS 8 with at least 2 GB RAM.
  • The root password is configured for the server.

getting Started

First, it is recommended to update the system software package to the latest version. You can update them with the following command:

dnf update -y

After updating all packages, install other dependencies required by Cacti using the following command:

dnf install net-snmp net-snmp-utils net-snmp-libs rrdtool -y

After installing all the dependencies, please start the SNMP service and use the following command to enable it to start at boot time:

systemctl start snmpdsystemctl enable snmpd

Once completed, you can proceed to the next step.

Install LAMP server

Next, you will need to install Apache web server, MariaDB database server, PHP and other necessary PHP extensions in your system. You can install all components with the following command:

dnf install httpd mariadb-server php php-xml php-session php-sockets php-ldap php-gd php-json php-mysqlnd php-gmp php-mbstring php-posix php-snmp php-intl -y

After installing all the packages, start the HTTP and MariaDB services and start them at boot time using the following command:

systemctl start httpdsystemctl start mariadbsystemctl enable httpdsystemctl enable mariadb

Next, you will need to edit the php.ini file and make some changes:

nano /etc/php.ini
date.timezone = Asia/Kolkata
memory_limit = 512M
max_execution_style = 60

Once completed, you can proceed to the next step.

Configure MariaDB database

Next, you will need to create a database and users for Cacti. First, log in to MariaDB shell using the following command:

mysql

After logging in, use the following commands to create a database and user for Cacti:

MariaDB [(none)]> create database cactidb;MariaDB [(none)]> GRANT ALL ON cactidb.* TO [email protected] IDENTIFIED BY 'password';

Next, use the following command to clear the privileges and exit from the MariaDB shell:

MariaDB [(none)]> flush privileges;MariaDB [(none)]> exit;

Next, you will need to edit the MariaDB configuration file and make some settings. You can do this by editing the file /etc/my.cnf.d/mariadb-server.cnf.

nano /etc/my.cnf.d/mariadb-server.cnf

Add the following line inside [mysqld] section:

collation-server=utf8mb4_unicode_ci
character-set-server=utf8mb4
max_heap_table_size=32M
tmp_table_size=32M
join_buffer_size=64M
# 25% Of Total System Memory
innodb_buffer_pool_size=1GB
# pool_size/128 for less than 1GB of memory
innodb_buffer_pool_instances=10
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_io_capacity=5000
innodb_file_format=Barracuda
innodb_large_prefix=1
innodb_io_capacity_max=10000

Save and close the file when you are done, then restart the MariaDB service to apply the changes:

systemctl restart mariadb

Next, use the following command to import mysql_test_data_timezone.sql into the mysql database:

mysql -u root -p mysql < /usr/share/mariadb/mysql_test_data_timezone.sql

Next, log in to MySQL and grant the cactus user access to the mysql.time_zone_name table:

mysql

After logging in, run the following command to grant access:

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO [email protected];

Next, use the following command to refresh the privileges and exit from MariaDB shell:

MariaDB [(none)]> flush privileges;MariaDB [(none)]> exit;

Once completed, you can proceed to the next step.

Install and configure Cacti

By default, Cacti is not available in the CentOS 8 default repository. Therefore, you need to add the EPEL repository to the system.

You can use the following command to install:

dnf install epel-release -y

After installing the repository, install Cacti using the following command:

dnf install cacti -y

After installing Cacti, please check the Cacti installation using the following command:

rpm -qi cacti

You should get the following output:

Name        : cacti
Version     : 1.2.14
Release     : 1.el8
Architecture: noarch
Install Date: Wednesday 07 October 2020 01:04:02 AM EDT
Group       : Unspecified
Size        : 56217780
License     : GPLv2+
Signature   : RSA/SHA256, Thursday 06 August 2020 05:06:22 AM EDT, Key ID 21ea45ab2f86d6a1
Source RPM  : cacti-1.2.14-1.el8.src.rpm
Build Date  : Thursday 06 August 2020 04:54:10 AM EDT
Build Host  : buildvm-a64-27.iad2.fedoraproject.org
Relocations : (not relocatable)
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://www.cacti.net/
Bug URL     : https://bugz.fedoraproject.org/cacti
Summary     : An rrd based graphing tool
Description :
Cacti is a complete frontend to RRDTool. It stores all of the
necessary information to create graphs and populate them with
data in a MySQL database. The frontend is completely PHP
driven.

Next, use the following command to import Cacti data into the Cacti database:

mysql -u root -p cactidb < /usr/share/doc/cacti/cacti.sql

Next, edit the Cacti configuration file and define the database settings:

nano /usr/share/cacti/include/config.php

Change the following lines that match the database:

$database_type="mysql";
$database_default="cactidb";
$database_hostname="localhost";
$database_username="cacti";
$database_password = 'password';
$database_port="3306";
$database_retries  = 5;
$database_ssl      = false;

Save and close the file when you are done, and then create a cron file for Cacti.

nano /etc/cron.d/cacti

Add the following line:

*/5 * * * *   apache /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

Save and close the file when you are done.

Once completed, you can proceed to the next step.

Configure Apache for Cacti

Next, you will need to create an Apache virtual host configuration file for Cacti. You can create it with the following command:

nano /etc/httpd/conf.d/cacti.conf

Find the following lines: ads

Alias /cacti    /usr/share/cacti

<Directory /usr/share/cacti/>
        <IfModule mod_authz_core.c>
               	# httpd 2.4
                Require host localhost
        </IfModule>
        <IfModule !mod_authz_core.c>
               	# httpd 2.2
                Order deny,allow
                Deny from all
                Allow from localhost
        </IfModule>
</Directory>

And, replace them with the following lines:

Alias /cacti    /usr/share/cacti

<Directory /usr/share/cacti/>
        <IfModule mod_authz_core.c>
               	# httpd 2.4
                Require all granted
        </IfModule>
        <IfModule !mod_authz_core.c>
               	# httpd 2.2
                Order deny,allow
                Deny from all
                Allow from all
        </IfModule>
</Directory>

Save and close the file when you are done, then restart the Apache and PHP-FPM services to apply the changes:

systemctl restart httpdsystemctl restart php-fpm

You can also check the status of Apache with the following command:

systemctl status httpd

You should get the following output:

? httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           ??php-fpm.conf
   Active: active (running) since Wed 2020-10-07 01:10:35 EDT; 58s ago
     Docs: man:httpd.service(8)
 Main PID: 5159 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 12523)
   Memory: 28.7M
   CGroup: /system.slice/httpd.service
           ??5159 /usr/sbin/httpd -DFOREGROUND
           ??5161 /usr/sbin/httpd -DFOREGROUND
           ??5162 /usr/sbin/httpd -DFOREGROUND
           ??5163 /usr/sbin/httpd -DFOREGROUND
           ??5164 /usr/sbin/httpd -DFOREGROUND

Oct 07 01:10:35 centos8 systemd[1]: Stopped The Apache HTTP Server.
Oct 07 01:10:35 centos8 systemd[1]: Starting The Apache HTTP Server...
Oct 07 01:10:35 centos8 httpd[5159]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::200:45>
Oct 07 01:10:35 centos8 systemd[1]: Started The Apache HTTP Server.
Oct 07 01:10:35 centos8 httpd[5159]: Server configured, listening on: port 80

At this point, the Apache web server has been configured to serve Cacti. Now you can proceed to the next step.

Configure firewall and SELinux

Next, you will need to allow http and https services through firewalld. You can allow them with the following command:

firewall-cmd --permanent --zone=public --add-service=httpfirewall-cmd --permanent --zone=public --add-service=httpsfirewall-cmd --reload

Next, you also need to cancel SELinux in the system.

You can disable SELinux by editing the /etc/selinux/config file:

nano /etc/selinux/config

Find the following line:

SELINUX=enforcing

And, replace it with the following line:

SELINUX=permissive

Save and close the file, then reboot the system to apply the changes.

Access the Cacti web interface

Now, open your web browser and use the URL http://your-server-ip/cacti to access the Cacti web interface. You will be redirected to the Cacti login page:

Provide the default user name and password as admin/admin, and click log in Button. You should see the “Cacti Password Change” screen:

change the password

Provide your default password, new password, and click save Button. You should see the Cacti License Agreement page:

Accept license

Accept the license agreement and click Start Button. You should see the pre-installation check page:

Check before installation

Make sure all packages are installed, then click next Button. You should see the following page:

Choose installation type

Choose your installation type and click next Button. You should see the directory permission check page: Advertisement

Directory permissions

Click on next Button. You should see the following page.

Check binary position

Click on next Button. You should see the “Input Verification” page:

Enter verification whitelist

Select the check box and click next Button. You should see the “Profile” page:

Default profile

Provide your network range and click next Button. You should see the template settings page:

Template settings

Select the desired template and click next Button. You should see the following page:

Server organization

Next, open your terminal, log in to MySQL Shell and change the character set by running the following command:

MariaDB [(none)]> ALTER DATABASE cactidb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;MariaDB [(none)]> flush privileges;MariaDB [(none)]> exit;

Next, return to the Cacti installation wizard and click next Button. You should see the following page:

Confirm installation

Confirm the installation and click installation Button. After the installation is complete, you will see the following page:

Installation completed successfully

Click on get Started Button. You should see the Cacti dashboard in the following page:

Cactus dashboard

Click on chart => Local Linux machine. You should see information about your local computer in the following page:

Use Cacti for server monitoring

in conclusion

Congratulations! You have successfully installed and configured the Cactus network monitoring tool on Ubuntu 20.04. Now you can install Cacti agents on the client computer, then add them to the Cacti server and start monitoring. If you have any questions, please feel free to ask me.

Sidebar