How to install Cacti on Debian or Ubuntu

cacti.jpeg

Cacti is a web based PHP/MySql graphing solution using the RRDtool engine. Classically, it can graph network bandwidthes with SNMP. But in fact, a lot of different graphs can be done with snmp, shell or perl scripts.

Cacti’s strength lies in the fact that it can be installed and used incredibly easily. You don’t need to be a guru or spend tons of hours on the tool to configure it. Even a beginner can use it very quickly. On the very active Cacti forum, you can share “Cacti templates” with other users which can can save you a lot of time. You can very easily add plugins to the Cacti too enabling the possiblility to integrate other free tools like ntop or php weathermap. In our opinion, this is by far the best RRDtool frontend.
For details about how to use Cacti, see the very good Cacti Manual.

RRDtool is a program developed by the Swiss Tobi Oeticker who was already the creator of the famous MRTG. RRDtool is developed using the “C” programming language and it stores the collected data on “.rrd” files.

The number of records in a “.rrd” file never increases, meaning that old records are frequently removed. This implies that one obtains precise figures for recently logged data, whereas figures based on very old data are mean value approximations. By default, you can have daily, weekly, monthy and yearly graphs.

Some of the advantages of RRDtool over MRTG are the following:

- it is much quicker..
- it can use negative values.
- it can use more than one data source in a graph.
- the generated graphes are very customizable.
- it can be used by a wide variety of front-ends such as Cacti.
- the RRDtool records stored in .rrd files keep the same size and do not increase.

The following programs are needed to run cacti:

- apache2 for the web server
- mysql-server for the database
- php5 for the server-based script
- php5-common
- php5-cgi
- php5-cli
- php5-mysql

- snmp – snmp tools used to collect data to the remote hosts
- rrdtool – a perl script to format collected data to rrdtool files

facultative:

php5-gd – the graphical library used by a Cacti plugin named php weathermap

INSTALL PROGRAMS

Use apt-get to install the programs

#apt-get install apache2
#apt-get install mysql-server
#apt-get install php5
#apt-get install php5-common
#apt-get install php5-cgi
#apt-get install php5-cli
#apt-get install php5-mysql
#apt-get install snmp
#apt-get install rrdtool

1- INSTALL CACTI WITH APT-GET (recommanded)

#apt-get install cacti

You will have to configure the mysql settings through a little wizard.
At the end of the tutorial, a mysql database and user named cacti will be automatically created.

MySql root user password

New MySql cacti user password

Confirm MySql cacti user password

Web server used by cacti

Now Cacti is ready to be used via: http://localhost/cacti The default login and password are admin.
Cacti will check if all the required tools are correctly installed.

Cacti License

Select “upgrade” or “new install”

Check if the required tools are correcty seen by cacti

Note that the poller.php script which send the requests to the remote hosts is lauched by the apache2 user, it means www-data.

To reconfigure cacti, use the following command:

#dpkg-reconfigure cacti

If you want to activate the poller manually:

#/usr/share/cacti/site/php5 poller.php

Sometime you need to activate it the first time, then it runs automatically every 5 minutes by default.



2- MANUAL INSTALL OF CACTI

Download Catci at http://www.cacti.net
uncompress the tar.gz file

#tar -xvf cacti-0.8.6h.tar.gz

move the uncompressed folder inside your /var/www folder, for example:

#mv /home/po/Desktop/cacti /var/www/

Then Configure the Cacti database

#mysqladmin -u root -p create cacti

We now have to insert the Cacti tables inside the cacti database:

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

As always, it’s better to access the database without the root user.
So, login into the database and create a new MySQL user:

#mysql -u root -p cacti

We give all the rights to the cactiuser on the cacti database:

mysql> grant all on cacti.* to cactiuser@localhost identified by ‘cactiuser’;

Now, reload mysql rights:

mysql>flush privileges;
mysql>exit

We need to change the database connection settings located in the
/var/www/cacti/include/config.php file

$database_type = “mysql”;
$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “cactiuser”;
$database_password = “cactiuser”;
$database_port = “3306″;

We then need to create a user to run cacti, this user will not be allowed tu run any shell command (/bin/false):

#useradd cacti -d /var/www/cacti/ -s /bin/false

The cacti user we need to write in two folders, so:

#chown -R cacti /var/www/cacti/

We will need to do a cron job to run the php script every 5 minutes

#crontab -e -u cacti
*/5 * * * * php5 /var/www/cacti/poller.php > /dev/null 2>&1

Restart the apache webserver:

#/etc/init.d/apache2 restart

Finally we can log in to cacti with a web browser:

http://your_ip_address/cacti

Use “admin” as the default login and password.

Related Posts

Comments are closed.