Cacti With Xampp On Ubuntu

Want to support HowtoForge? Become a subscriber!
 
Submitted by deadwait (Contact Author) (Forums) on Wed, 2007-10-03 07:00. :: Ubuntu | Monitoring

Cacti With Xampp On Ubuntu

This is a simple setup of Cacti, so that you don’t really need a "Linux" expert to maintain it. Please note that Cacti can also be installed on Windows and guides for both these installations are available on the net. This guide is just a repeat of how Cacti was set up here in Mumbai.

What is Cacti? You can check out that here http://cacti.net.

What is Cacti being used for?

Cacti was primarily set up to monitor backhauls and have ready graphs whenever we need, but currently we are also using it to monitor CPU usage, memory usage, see traffic patterns, get alerts etc.

So now we go on to the basic setup.

Requirements:

One Linux machine - (can be any depending on your choice; try and keep at least 256mb ram, I have tested Cacti on a 1.4ghz processor and 256 mb ram, with centos as the operating system and with around 350 monitored devices, and it has run without a hitch for more than a month, currently Cacti resides on a 1.8ghz machine with 512 mb ram, which is also running a proxy server - squid, plus an intranet web ftp server).

The Cacti package - we will need to download this from http://cacti.net.

RRDtool - this is the defacto package used by 95% of all NMS tools out on the net for graphing, details can be found at http://oss.oetiker.ch/rrdtool/.

Xampp - now the reason I am going in for Xampp is because it lets maintain a lot of things very easily (the Apache webserver - MySQL database, PHP programming language and all needed dependencies); of course we can do it without Xampp but you can search for those docs on the net.

Ubuntu installation:

1: The First step now would be to install Linux on our machine, for this example we will download Ubuntu isos from the following site: http://cdimage.ubuntu.com/releases/gutsy/tribe-5/gutsy-desktop-i386.iso. This is the current latest version of Ubuntu.

Note: there is a server version of Ubuntu which is also available but we will not be going in for that due to lack of gui.

2: Once downloaded burn it onto a CD and then boot the machine you have decided to make as your server with the same CD.

3: Once the machine boots up, you will notice that it is running in Live-CD mode, i.e. the hard disk is not being used, you will find an Install icon on the top left of your screen, double-click on it and go ahead with the installation, the only problem you might have is during partitioning - as we are going in for a separate machine it's best that we go in for auto partitioning (a detailed Ubuntu install guide is not really possible right now but it can be found here: https://help.ubuntu.com/6.10/ubuntu/installation-guide/i386/index.html.

Also remember to type in your username to be used as deadwait (im taking deadwait just for this example).

4: Once Ubuntu is installed - all further steps will now occur from within Ubuntu itself, the next thing to do is see to it that it is updated. For that we have to have access to the Internet hence your network card will have to be configured, I hope you remember the root password you had supplied during the installation.

4.1: Click on:

System --> Administration --> Network

and in the wired connection tab supply your needed IP address/subnet mask and gateway.

4.2: If your Internet access is through a proxy, then click on:

System --> Preferences --> Network Proxy

and supply your proxy server’s IP address and port.

4.3: Open up a terminal window (Applications –> Accessories –> Terminal) and type in the foll. commands:

sudo aptitude update

and then:

sudo aptitude install build-essential

4.4: Once the build essential is over you are set to install Xampp, RRDtool and Cacti.

5: We will begin with Xampp - to know in detail what Xampp is check out their website http://www.apachefriends.org/en/xampp.html. Now we need to download Xampp for Linux directly clicking on this link http://jaist.dl.sourceforge.net/sourceforge/xampp/xampp-linux-1.6.3b.tar.gz. This is the current latest version of Xampp. Remember to download it to /opt (the reason im going in for /opt is because the same is mentioned on the website, but remember you can have it downloaded and installed anywhere).

5.1: Now assuming you have downloaded the file to /opt you need to do the foll next (I'm going to be guiding you in command line mode - but it can be done in GUI, the reason I haven't mentioned the GUI method is because I get confused in GUI mode, as these DOCS will be open for editing later anyone who wishes to update the GUI mode can do so).

As usual click on:

Applications --> Accessories --> Terminal

Type in:

cd /opt

This will bring you in the /opt directory, type in:

sudo tar -xvzf xampp-linux-1.6.3b.tar.gz

What this does is unzip/unpack the file into its own directory, if you type in the command dir you will now see that a new directory (lampp) has been created. If you want to delete the xampp-linux-1.6.3b.tar.gz file or not is up to you, if you want to delete it the command is:

sudo rm -rf xampp-linux-1.6.3b.tar.gz

What I do is usually move these files in to my home folder, assuming my login name is deadwait then my home folder becomes /home/deadwait, the command to move the file is as follows:

sudo mv xampp-linux-1.6.3b.tar.gz /home/deadwait

Now for the cool part –> in the same terminal type in:

cd lampp

Then type in:

sudo ./lampp start

and your webserver along with MySQL and FTP will have started, to check the same, open up Firefox and type in http://localhost, you should get the Xampp screen.

5.2: Now let's clear some basic stuff we need to do - you see Cacti needs a database which we have already installed using Xampp, now what we need to do is create Cacti's own database. Now since you have opened up http://localhost in Firefox, Xampp will ask you its language preference, click on English, then on the left pane you will see a link for phpmyadmin, click on it, what you see now is a web based administration tool for MySQL, on the first page itself you will see an option named Create Database. In the field below type in cacti since this is the name we will use for our database (of course, you could name it whatever you want). Then go on to the next step.

6: So then, one part of our work is done. Next thing to do is to install rrdtool. You're going to love this, in a terminal box type in the magic commands:

sudo aptitude install rrdtool

and that's it. rrdtool is installed (now for a bit of history, we can install the entire Cacti along with webserver, PHP and MySQL by doing sudo aptitude install cacti, but we haven't done that because if you are not comfortable with Linux it could lead to a lot of confusion as to where the files are installed, also the package could break if an upgrade takes place).

At the same time let's install one more tool needed (which is snmp) with the same command:

sudo aptitude install snmp

and then:

sudo aptitude install snmpd

What is important to remember is rrdtool gets installed in /usr/bin/rrdtool, we will need this path later.

7: Now the cream - Cacti installation.

First we need to download the Cacti package which we can do so from this link: http://www.cacti.net/downloads/cacti-0.8.6j.tar.gz.

Save the link on your e.g.: Desktop, then open up a terminal and navigate to your desktop, the commands are (assuming your user login is deadwait):

cd /home/deadwait/Desktop

Remember Linux is case-sensitive, so desktop won't work, it will be Desktop. Once we are in Desktop, type in the foll commands:

sudo tar -xvzf cacti-0.8.6j.tar.gz

which will extract the foll in a directory named cacti-0.8.6j. For purposes of our ease let's rename it to just cacti with the foll command:

sudo mv cacti-0.8.6j cacti

Now that the directory is renamed let's move it to our lampp directory so that we can access it via our webserver. To do so run the foll command:

sudo mv cacti /opt/lampp/htdocs

Now our Cacti directory is copied into lampp’s webroot directory. Remember we had created a database in MySQL named cacti, now we need to populate this database, which you should not worry about if you dont understand, just follow the foll steps:

7.2: Open up Firefox and again go to phpmyadmin, http://localhost/phpmyadmin.

On the left pane select the database which we have created, in our case it's cacti.

Then on the right pane select import –>, then click on browse –>. Navigate to the directory /opt/lampp/htdocs/cacti in which you have to select the file cacti.sql and then click on go.

7.3: Again in a terminal type in:

cd /opt/lampp/htdocs/cacti/include

then type in

sudo nano config.php

nano is an editor which will open up the file config.php, in the beginning you will see these options:

 $database_type = "mysql";
 $database_default = "cacti";
 $database_hostname = "localhost";
 $database_username = "cactiuser";
 $database_password = "cactiuser";
 $database_port = "3306";

You need to change the username and password so that it looks like this:

 $database_type = "mysql";
 $database_default = "cacti";
 $database_hostname = "localhost";
 $database_username = "root";
 $database_password = "";
 $database_port = "3306";

Then press ctrl-x and come out.

7.4: Now open up Firefox and type into the address bar the following: http://localhost/cacti.

You will be greeted with a screen which will be the beginning of the installation, just click on next.

On the next screen you will asked if it's a new install, which of course it is,confirm whether the database user and the database name mentioned are correct, go back to step 7.3 and check, click on next.

7.5: When we click it shows us the base paths of all needed files. We will notice that the path for php is marked in red because the path is wrong. The path shown in the installer is:

/usr/bin/php

We have to change that to:

/opt/lampp/bin/php

and then click finish.

Cacti is now installed.

It will open up to the Cacti homepage and ask you for a username and password. Type in:

admin

and password as

admin

It will then force you to change the password, type in the new password that you decide on and log in using the new password.

We need to do a bit more stuff, you see Cacti works by polling the devices which we set it up for, so let's set the poller for every 5 minutes. Open up terminal and type in the foll command:

sudo nano /etc/crontab

This will open up the crontab file, now at the end type in the foll.:

/5 * * * * deadwait /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php > /dev/null 2>&1

Then press ctrl x and come out. Now all along we have assumed the username to log in to your machine is deadwait, hence the deadwait is added above, now we need to do one last thing. Type in the following command in a terminal:

sudo chown -R 777 /opt/lampp/htdocs/cacti


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by sylvainr (not registered) on Tue, 2011-08-02 20:33.

With version 5.5.8 of MySQL, the import might throw in an error because cacti.sql uses TYPE=MyISAM and should be using ENGINE=MyISAM. I've opened up the file in an editor and did a find and replace and then MySQL imported the file.

 Thanks for this tutorial. Helped me a lot.

Submitted by msfz751 (registered user) on Sat, 2008-01-05 20:24.

This how-to allowed me to have xampp and cacti working, at last, in Ubuntu Dapper, very clear instructions. Thanks.

I found a typo in crontab. Instead of this line:

/5 * * * * deadwait /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php > /dev/null 2>&1

you may want to use this (I added the asterisk):

*/5 * * * * deadwait /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php > /dev/null 2>&1

Even better if you use www-data instead of deadwait. www-data is already a user in Ubuntu.

 */5 * * * * www-data /opt/lampp/bin/php /opt/lampp/htdocs/cacti/poller.php > /dev/null 2>&1

 Now, in order to enable cacti to write, we should change some rights on a couple of folders:

sudo chown -R www-data:www-data /opt/lampp/htdocs/cacti/log

and:

sudo chown -R www-data:www-data /opt/lampp/htdocs/cacti/rra