Cacti is a popular open-source Network Management Software (NMS) that utilizes RRDTool for data storage and graphing capabilities. As a web-based application released under the GNU General Public License, it is completely free to use. Cacti is compatible with various operating systems, including Windows, Linux, and Solaris, but deploying it on Linux provides an effective and cost-free NMS solution. In this tutorial, I will guide you through the installation of Cacti on a CentOS 6 server.
1. Prerequisites
Cacti requires MySQL, PHP, RRDTool, net-snmp, and a web server that supports PHP such as Apache (Linux) or IIS (Windows).
First, we need to install Apache to serve our HTTP requests, as such:
# yum install httpd httpd-develNow, install MySQL for the database:
# yum install mysql mysql-serverAnd, don't forget to install PHP:
# yum install php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli php-mysqlAnd go ahead and install SNMP for support:
# yum install php-snmp# yum install net-snmp-utils p net-snmp-libs php-pear-Net-SMTPNow if you like pretty colorful graphs, install RRDTool, as such:
# yum install rrdtoolOnce you have installed everything, we can now start up the services:
# service httpd start
# service mysqld start
# service snmpd startAfter reboot, you will have to manually start them again, so it's better to change this option to have the services auto-start upon reboot:
# chkconfig httpd on
# chkconfig mysqld on
# chkconfig snmpd onYou can install Cacti from a repository or compile it yourself. To save time, we'll use the EPEL repository:
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpmNow, we are ready to install Cacti:
# yum install cactiApache, MySQL, and SNMP are now running, and Cacti has been installed. The next step will be to configure MySQL to prepare for Cacti.
2. MySQL Configuration
Because we just installed MySQL, we still have to set a password for the MySQL server. We also have to create a new database for Cacti to connect to and create a new user account for that:
# mysqladmin -u root password MYPASSWORDThe MySQL server now has a password. Let's login and create a database and user account.
‼ Note: The default Cacti Web User ID is admin with a password of admin. You will be forced to change it upon initial login to the Cacti web UI.# mysql -u root -p
Enter password: MYPASSWORD
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> create database cacti;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on cacti.* to cacti@localhost identified by 'MYPASSWORD';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
ByeWe have a new database called 'cacti' and a username called 'cacti.' The database is there, but it's empty. We'll import a file from the Cacti installation packet and import it into the database. First, however, we need to find out where it is located:
# rpm -ql cacti | grep cacti.sql
/usr/share/doc/cacti-0.8.8a/cacti.sqlIn my case, it's located in the folder above. We'll import this SQL file into the database, as such:
# mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.8a/cacti.sql This will find the database. Now, we need to edit the database configuration file of Cacti so that it uses the correct database name and username:
# vi /etc/cacti/db.phpAs you may have noticed, I'm using vi as my text editor. Below, you will find the part that we are looking for:
/* make sure these values reflect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";
$database_ssl = false;Make sure it reflects your database name and username/password you created. When you are done, save the file and exit your text editor. We still have yet to configure Apache.
3. Apache Configuration
We can change the Apache configuration to choose what IP addresses or subnets that are allowed to connect. We can do this by editing the following file:
# vi /etc/httpd/conf.d/cacti.confThis is the part we are looking for:
<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>I will now change the "Allow from localhost" to "Allow from all" so that I can access Cacti from any IP address:
Allow from allIf you are installing Cacti for a production environment, then it's recommended to ensure security by only selecting a specific range of IP addresses vice full zones or ranges, as such:
Allow from 192.168.1.0/24Once you are done, save your configuration and exit your text editor. Also, don't forget to restart the Apache service:
# service httpd restartMySQL and Apache are now up and running. The last thing to do is enable a cron job. This will allow Cacti to collect information from network devices.
4. Configuring a Cron Job
By default, Cron will collect data from devices every 5 minutes, but the cron job is disabled by default, so we'll go ahead and enable it:
# vi /etc/cron.d/cactiYou will find the line below:
#*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1Remove the # so that it looks like this:
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1Save your changes and exit your text editor. We can now access the web installer!
5. Configuring Cacti
You can access the GUI from your web browser using http://YOUR-IP/cacti. It will look similar to this:
Click on Next and choose a new installation:
Cacti will show you an installation guide checklist. At this point, everything should be good to go now.
Rate This Article
Thanks for reading: How to Install Cacti on CentOS 6, Sorry, my English is bad:)







