Cacti is a free and open source web based front-end network graphing solution application designed for the industry-standard data logging tool RRDtool. It provides its users a fast poller, advanced graph templating, multiple data acquisition methods, and user management features with its beautiful web based interface. It is generally used to graph time-series data of metrics such as CPU load and network bandwidth utilization. It can handle multiple users, with their own graph sets to display bandwidth statistics of the users. Some of the awesome features of Cacti are as follows.
- It consists of unlimited graph items with auto-padding support.
- Graph data manipulation and flexible data sources.
- Data gathering on a non-standard timespan with custom scripts
- It consists built-in SNMP support.
- It contains graph, data source, host templates
- Tree, list, and preview views of graph data
- It provisions user-based management and security.
Here are some simple easy steps on how we can install and setup Cacti in our machine running Fedora 22 or CentOS 7 as operating system.
1. Installing LAMP Stack
First of all, we'll need to install LAMP stack in our linux machine. LAMP stack is the combination of Apache web server, MariaDB/MySQL database server and PHP modules which is essential for Cacti in order to provide the web interface for it. To install the complete set of LAMP stack, we'll need to run the following command under root/sudo access according our operating system installed in our machine.
On Fedora 22
# dnf install httpd mariadb mariadb-server php php-mysql php-gd php-pear php-common php-cli php-devel php php-mbstring nano
On CentOS 7
# yum install httpd mariadb mariadb-server php php-mysql php-gd php-pear php-common php-cli php-devel php php-mbstring nano
2. Installing EPEL Repo
To install Cacti, we'll need to install and enable EPEL repository as cacti is not available on the default repository of Fedora 22 or CentOS 7. To install EPEL repo, we need to run the following command.
On Fedora 22
# dnf install http://ftp.cuhk.edu.hk/pub/linux/fedora-epel/7/x86_64/e/epel-release-7-5.noarch.rpm
On CentOS 7
# yum install epel-release
2. Installing SNMP and Cacti
Now, we'll gonna install snmp and cacti in our linux machine. As snmp and cacti is available on the official repository of both centos and fedora repository, we'll gonna install it using its default package manager.
On Fedora 22
# dnf install php-snmp net-snmp net-snmp-utils cacti
On CentOS 7
# yum install php-snmp net-snmp net-snmp-utils cacti
3. Starting and Enabling Apache, MariaDB and SNMP
To start apache web server, snmp and mariadb in our centos and fedora machine, we'll need to run the following systemd command in our linux terminal or console.
# systemctl start httpd mariadb snmpd
Next, we'll also need to enable them to start along with the system boot so that it will automatically get into work in every reboot.
# systemctl enable httpd mariadb snmpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/snmpd.service to /usr/lib/systemd/system/snmpd.service.
4. Configuring MariaDB
As we have just installed our mariadb database server in our linux machine, we'll now need to assign a new password for our mariadb root user. Then, we'll create a new database for our Cacti to store its data. To configure mariadb, we'll need to run the following command in a terminal or a console.
This will ask us to enter the password for root but as we haven’t set any password before and its our first time we’ve installed mariadb, we’ll simply press enter and go further. Then, we’ll be asked to set root password, here we’ll hit Y and enter our password for root of MariaDB. Then, we’ll simply hit enter to set the default values for the further configurations.
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
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
installation should now be secure.
Thanks for using MariaDB!
Next, we’ll login to the MariaDB command prompt as root.
# mysql -u root -p
Here, we’ll need to enter the password of the MariaDB root account that we had set above.
After we’re logged in into the mariadb command prompt, we’ll gonna create the database for Cacti.
> CREATE DATABASE cacti;
> GRANT ALL ON cacti.* TO [email protected] IDENTIFIED BY 'password';
> FLUSH PRIVILEGES;
Note: It is highly recommended to change the above variables cacti, cactiuser and password according to your requirement or desire for security issue.
5. Configuring Cacti
Now, we'll gonna configure our installation of cacti which includes database configuration. Before we configure cacti, we'll need to first import the dumped cacti database table to the database in MariaDB server that we just created above. To do so, we'll need to run the following command.
# mysql -u cactiuser -p cacti < /usr/share/doc/cacti-*/cacti.sql
Here, we'll be asked to enter the password for our database user cactiuser. We'll need to enter the password that we had set in the above step. Here, we have database user as cactiuser and password as password .
After we have successfully imported the database table to our mariadb database cacti, we'll now configure our cacti configuration file. To do so, we'll need to edit /usr/share/cacti/include/config.php file using our favorite text editor.
# nano /usr/share/cacti/include/config.php
Then, we'll need to make change to the file as show below using the variables we had set above during the configuration of database in our mariadb server.
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "password";
$database_port = "3306";
$database_ssl = false;
After we've configured our cacti configuration file, we'll then save and exit it.
6. Adding Cacti to Cronjob
We'll now add a cronjob for cacti so that our cacti will work as scheduled in our cronjob configuration. To do so, we'll need to create a file named cacti under /etc/cron.d/ using our favorite text editor.
# nano /etc/cron.d/cacti
Then, we'll gonna uncomment the following lines by removing "#" from the line.
*/5 * * * * cacti php /usr/share/cacti/poller.php > /dev/null 2>&1
After that, we'll save and exit the file.
7. Fixing Ownership and Firewall
Next, we'll need to change the ownership of two directories rra and log which lies under /var/www/html/cacti/ to cacti so that it will have full read and write access over its files and directories.
# chown -R cacti /usr/share/cacti/rra/ /usr/share/cacti/log/
As fedora 22 and centos 7 both has preinstalled firewalld as the default firewall solution, we'll need to make firewalld allow http port so that cacti will be accessible via web browser. To do so, we'll need to run the following command.
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload
8. Configuring Apache Config
We'll now need to allow access to Cacti from over the internet. To do so, we'll need to edit /etc/httpd/conf.d/cacti.conf using a text editor.
# nano /etc/httpd/conf.d/cacti.conf
Then, we'll need to append the file as shown below.
Alias /cacti /usr/share/cacti
# httpd 2.4
Require all granted
# httpd 2.2
Deny from all
Allow from all
After saving and exiting the file, we'll gonna restart our apache web server by running the following command.
# systemctl restart httpd
9. Web Installation
Finally, after we have successfully setup cacti and lamp stack, we'll now navigate to the web interface of cacti. We'll need to point our web browser to http://ip-address/cacti or http://domain.com/cacti according to our configuration. Then, we'll see our first screen as Installation Guide with the portion of GNU General Public License.
To continue, we'll need to click on Next button which makes us that we accept the license agreement of the Cacti software. Then another page will be loaded which will ask us to select the type of installation we are going to setup. As we're gonna setup a new installation of Cacti, we'll simply select as New Install and verify the determined information then click on Next to continue.
After that, we'll be shown if all the required binary dependencies are available on the system or not. As we have already installed them in the above steps, we'll see that the dependencies were found in the system as shown below. After that, we'll simply click on Finish to continue further.
Then, we'll need to enter the default username and password of Cacti in order to login to the dashboard. The default username and password of Cacti is admin and admin respectively.
After entering the default username and password, we'll click on Login. Then, we'll need to change our password after logging in. A page to change the login password will appear in which we'll need to enter a new password which will be used for logging into the Cacti's dashboard.
After entering our new login password, we'll click on Save in order to apply it. Then, we'll be welcomed to our Cacti Dashboard as shown below.
To create a new graph, we'll need to click on New Graphs which lies on the sidebar for our new devices. To see our graphs, we'll need to click on Graphs. We can change, import and export templates, manage users and system utilities from the very Cacti Dashboard.
Cacti is an awesome RRDTool based graphing solution having an easy to use web based interface. It is widely used from a small LAN installations to a complex networks with hundreds of devices. It is commonly used to monitor network traffic by polling a network switch or router interface through Simple Network Management Protocol. It is extensible because it can be extended to monitor any source using scripts. Cacti is very easy to setup and configure as we did in above tutorial. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents.