There is a new version of this tutorial available for CentOS 8.

How to Monitor your CentOS 7 Server using Cacti

Cacti is a free and open source network graphing solution. It uses RRDTool for data gathering and graphing. It provides many features such as remote and local data collectors, network discovery, device management automation, graph templating etc.

In this tutorial, we will install Cacti on CentOS 7 server.

Prerequisite

  • Minimal 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 are updated.

yum -y update

Once you have your system updated, you can proceed to install the Apache web server.

yum -y install httpd

Now start Apache web server and enable it to start at boot time using the following command.

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 as PHP v5.3 has reached the end of life. 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 you will need to add the Webtatic repository in your system. Webtatic repository requires EPEL repository to work. Run the following command to install EPEL repository.

yum -y install epel-release
yum -y update

Type the commands to install Webtatic repository.

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

Type the following command to 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

To check if PHP is installed successfully, you can run:

php -v

You should get output similar to this.

[root@liptan-pc ~]# 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 you will need to configure few configurations in PHP. Open the PHP configuration file, php.ini using your favourite text editor. In this tutorial, we will be using nano editor. If you do not have nano installed, you can run yum -y install nano.

nano /etc/php.ini

Find the following line and Uncomment the line and set the timezone according to your region. For example:

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

Step 3 - Installing MariaDB

MariaDB is a fork of MySQL database. To install MariaDB on your server, run:

yum -y install mariadb mariadb-server

Run the following commands to start MariaDB and enable it to start at boot time.

systemctl start mariadb
systemctl enable mariadb


Now run the following commands to secure your MariaDB installation.

mysql_secure_installation

The above command will run a script to secure fresh MariaDB installation. The script will ask for the existing root user password, we have just installed MariaDB, the root password is not set, just press enter to proceed further.

The script will ask you if you want to set a root password for your MariaDB installation, choose y and set a strong password for the installation. Most of the questions are self-explanatory and you should answer yes or y to all the questions. The output will look like shown below.

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

mysql -u root -p

The above command will login to MySQL shell of the root user, it will prompt for the password of the root user. Provide the password to login. Now run the following query to create a new database for your Cacti installation.

CREATE DATABASE cacti_data;

The above query will create a new database named cacti_data. You can use any other name for your database if you want. Make sure that you use semicolon at the end of each query as the query always ends with a semicolon.

Once the database is created you can create a new user and grant all the permissions to the user for the database. To create a new database user, run the following query.

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

The above query will create a user with username cacti_user. You can use any username you prefer instead of cacti_user. Replace StrongPassword with a very strong password. Now provide the all the privileges to your database user over the database you have created. Run the following command.

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

Now run the following command to immediately apply the changes on the database privileges.

FLUSH PRIVILEGES;

Exit from MySQL prompt using the following command.

EXIT;

You will also need to populate the time zone table. Run the following command to populate the timezone tables.

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 the following query.

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

The above query will SELECT give access to cacti_user on

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

As we have all the dependencies ready, we can now download the install package from Cacti website.

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

You can always find the link to the latest version of the application on Cacti download page. Extract the archive using the following command.

tar xzvf cacti*.tar.gz

Rename your Cacti folder using:

mv cacti-1*/ cacti/

Now import the Cacti database by running the following command.

cd /var/www/html/cacti
mysql cacti_data < cacti.sql -u root -p

The above command will import the cacti.sql database into cacti_data using the user root. It will also ask you the password of root user before importing the database.

Now edit Cacti configuration by running the following command.

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

Now 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;

Step 5 - Configure Permissions and Firewall

Now you will need to provide the ownership of the application to web server user using the following command.

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

You may also need to allow HTTP traffic on port 80 through the firewall if you are running one. Run the following commands for same.

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

Now you will need to disable your SELinux because Proxy configuration does not work with SELinux policies. To temporary disable SELinux without restarting the server, run the following command.

setenforce 0

To completely disable the SELinux you will need to edit /etc/selinux/config file.

nano /etc/selinux/config

Find the following line:

SELINUX=enforcing

Change it to:

SELINUX=disabled

Now complete the installation using a web browser, go to the following link using your favourite web browser.

http://Your_Server_IP/cacti

You will see the following page.

Cacti License

Accept the license agreement to proceed further.

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

Cacti pre-installation check

Proceed to next interface.

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

Cacti Primary Server

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.

Cacti settings page

In next interface, you will see that the server has write access to all the required folders.

Directory Permission check

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

Template setup

You will be taken to the login page. Login using username admin and password admin, you will be taken to dashboard.

Cacti Dashboard

Installation of Cacti is now finished, you can use the application to moniter your server using interactive graphs.

Share this page:

5 Comment(s)