Installing Cacti Monitoring Tool on CentOS 7

Installing Cacti Monitoring Tool on CentOS 7

Let us see about cacti, Cacti is a complete front end  RRDTool(round-robin database tool), it stores all of the vital information to create graphs and populate them with data in a MySQL database. Along with this, it is capable  to maintain Graphs, Data Sources, and Round Robin Archives in a database, cacti handles the data gathering.

A common usage is to monitor network traffic by polling a network switch or router interface via Simple Network Management Protocol (SNMP)

Now, we can proceed with the steps involved in installing and configuring Cacti.

Prerequisites for installing

  • CentOS 7 server
  • Root privileges

Step 1 – Installing Apache

It is recommended to update the server before installing any package so that the existing packages and repositories were updated.

# yum -y update

Once the system updated, we can proceed to install the Apache web server.

# yum -y install httpd

Now, we can start Apache web server and enable it to start at boot time.

# systemctl start httpd
# systemctl enable httpd

 

Step 2 – Installing PHP

Cacti support all the version of PHP greater than 5.3. But in this tutorial, we will install PHP 7.1 . Installing the latest version of PHP will ensure the maximum security and performance of the application.

The default YUM repository of CentOS does not have PHP 7.1 included, hence we need to add the Webtatic repository in our system.

# yum -y install epel-release

To install Webtatic repository, use

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum -y update

Now, we can install PHP 7.1 along with all the required dependencies.

# yum -y install php71w php71w-snmp php71w-mysqli php71w-cli php71w-ldap php71w-xml php71w-session php71w-sockets php71w-pcre php71w-gd php71w-dom php71w-posix php71w-mbstring

Now, the required dependencies has been installed, to check the PHP version use

# php -v

You should get output similar to this.

[root@webhostingchennai ~]# php -v
PHP 7.1.6 (cli) (built: Jun 10 2017 07:28:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

Now we need to do few configurations in PHP. Open the PHP configuration file, php.ini using your favourite text editor.

# nano /etc/php.ini

Find the following lines and Uncomment the line and set the timezone according to your region, as follows

[...]

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Kolkata

[...]

Save the PHP configuration file.

Step 3 – Installing MySQL

Download and add the repository

# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
# sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

Now, we need to update the repository

# yum update

Completing the update, install mysql server and start it

# yum install mysql-server
# systemctl start mysqld

Run the mysql_secure_installation script to address several security concerns in a default MySQL installation.

[root@webhostingchennai ~]# mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
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 MySQL
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Sorry, you can't use an empty password here.

New password:
Aborting!

Cleaning up...
Cleaning up...
Warning: Could not unlink .my.cnf.2462: No such file or directory
Warning: Could not unlink .mysql.2462: No such file or directory
[root@webhostingchennai ~]# mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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 MySQL
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 MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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, MySQL 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...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- 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!

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

Thanks for using MySQL!

Cleaning up...
[root@webhostingchennai ~]#

To create a database we will need to login to MySQL command line first. Run the below command.

Login to MySQL shell of the root user, it will prompt for the password of the root user. Provide the password to login.

# mysql -u root -p

Now, we can create a new database for your Cacti installation.

# CREATE DATABASE cacti_data;

Once the database is created we need create a new user and grant all the permissions to the user for the database.

To create a new database user,

# CREATE USER 'cacti_user'@'localhost' IDENTIFIED BY 'StrongPassword';

Replace ‘StrongPassword’ with a very strong password.

Now provide the all the privileges to your database user over the database you have created.

# GRANT ALL PRIVILEGES ON cacti_data.* TO 'cacti_user'@'localhost';

To apply the changes on the database privileges, run the below command and exit from mysql.

# FLUSH PRIVILEGES;
# EXIT

You will also need to populate the time zone table

# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

Provide the MySQL root password to proceed.

Once the tables are populated, you will need to provide select access to Cacti user account over the tables. Login to MySQL prompt again using.

# mysql -u root -p

Now run below commands, this will give SELECT access to cacti_user

# GRANT SELECT ON mysql.time_zone_name TO 'cacti_user'@'localhost';
# FLUSH PRIVILEGES;
# EXIT

 

Step 4 – Installing and Configuring Cacti

Cacti require few more dependencies, run the following command to install them.

# yum -y install net-snmp rrdtool net-snmp-utils

Now, all the dependencies are ready, we can download the install package from Cacti website.

# cd /var/www/html
# wget http://www.cacti.net/downloads/cacti-1.1.10.tar.gz

Extract the archive

# tar xzvf cacti*.tar.gz

Rename your Cacti folder

# mv cacti-1*/ cacti/

Now import the Cacti database by running

# cd /var/www/html/cacti

To import the cacti.sql database into cacti_data using the user root. It ask the password of root user before importing the database.

# mysql cacti_data < cacti.sql -u root -p

Now, we need to edit Cacti configuration file.

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

Find the following lines and edit them according to your MySQL database credentials.

/* make sure these values reflect your actual database/host/user/password */

$database_type = 'mysql';
$database_default = 'cacti_data';
$database_hostname = 'localhost';
$database_username = 'cacti_user';
$database_password = 'StrongPassword';
$database_port = '3306';
$database_ssl = false;

Save the file and Exit.

Step 5 – Configure Permissions and Firewall

Now, we need to modify  the ownership of the application to web server user

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

We also need to allow HTTP traffic on port 80 through the firewall if you are running. Before that make sure FirewallD is enabled and running else run

systemctl enable firewalld  systemctl start firewalld
# firewall-cmd --zone=public --permanent --add-service=http
# firewall-cmd --reload

Now, we need to disable SELinux because Proxy configuration does not work with SELinux policies. To temporary disable SELinux without restarting the server,

# setenforce 0

Now, let step into creating a user for cacti.

# useradd cactiuser

Set the appropriate permissions on cacti’s directories for graph/log generation.

# chown -R cactiuser rra/ log/

Enabling cron, Add the below cron command to your /etc/crontab  file.

# */5 * * * * cactiuser php /var/www/html/cacti/poller.php > /dev/null 2>&1

Replace cactiuser with the valid user you have created.

Now, we can complete the installation using a web browser.

http://IP_ADDRESS/cacti , You will now see the following page.

Installing cacti monitoring tool on centos 7

Accept the license agreement to proceed further.

In next interface you will see the pre-installation, all the required dependencies are met.

Installing cacti monitoring tool on centos 7

Proceed to next interface.

In installation type, choose New Primary Server and proceed next.

Installing cacti monitoring tool on centos 7

In next interface, you will need to provide the locations to the binaries. Path to RRDTool and PHP binaries are correct. For all other binaries, provide the path /usr/bin/binary_name. For example, for snapwalk binary, the path is /usr/bin/snmpwalk.

Installing cacti monitoring tool on centos 7

In next interface, you need to check whether all the folders are writable.

Installing cacti monitoring tool on centos 7

In template setup, choose Local Linux Machine and click Finish.

Installing cacti monitoring tool on centos 7

Now, you will be taken to the login page. Login using username ‘admin’ and password ‘admin’,

Now, it will ask you to modify the password, Modify it and you will be taken to dashboard.

Installing cacti monitoring tool on centos 7

Installation of Cacti is now finished, you can use the application to monitor the server using interactive graphs as given below.

Installing cacti monitoring tool on centos 7

Hope this post helps your need, please share your valuable comments to improve us.

For installing Zabbix Server 3.4 on CentOS 7 : Click Here

You may also like...