Installing Cacti
From InstallationWiki
| Official Page |
| Project Documentation |
| Download |
|
In this tutorial, we will install Cacti on our localhost. Cacti runs best on Unix/Linux systems.Also all the examples are based on Debian Linux. If you are running a different distribution, you should be able to simply replace apt-get install with the appropriate command (urpmi, yum, and so on), like for centos you have to use yum install.
Contents |
[edit] Cacti's prerequisites
Cacti has some prerequisites. You need to install these packages before installing Cacti:
- RRDTool1.0.49 or higher.
- NET-SNMP.
- MySQL4.1.x or higher.
- PHP 4.3.6 or higher.
- Apache/IIS or any other web server.
We will also need to install some other packages for support. Although you can choose to use Apache, IIS, or any other web server, in this tutorial, we will be using Apache2. If you are going to install some other web server, please follow the manual/handtutorial for that web server.
[edit] Installing Cacti prerequisites
The following are methods to install the software required by Cacti to function:
[edit] Apache
Open a shell and log-in as root or change to super user (su or sudo s).
$ su
This command will ask you for a root password. Suppose our root password is debianserver, type it, and remember that the characters will not be shown on screen.
Now, we are going to install Apache. Type this command on the same terminal:
$ apt-get install apache2
This will install Apache2 with all its dependencies. After that, open [http://localhost http://localhost] in your favourite browser.
If everything goes fine, you will see It Works! on the top.
|
Using the GUI tool to install packages You can use the Synaptic Package Manager to install these packages. |
[edit] PHP
Now that our web server is ready, we will install PHP. In the previous shell, type this command:
$ apt-get install php5 libapache2-mod-php5
It will install PHP 5 and libapache2-mod-php5 will configure Apache2 to run PHP scripts. Here, we choose PHP 5 as it's recommended for advance configurations of Cacti. Now, we need to restart the Apache 2 server so that the changes take effect:
$/etc/init.d/apache2 restart
Now, we need to test PHP to check whether it's working okay or not. So, make info.php in the /var/www/ folder and paste the following PHP code:
<?php phpinfo(); ?
Then, open [http://localhost/info.php http://localhost/info.php] in your browser. If everything goes fine, you will get a page like this:
[edit] MySQL
MySQL is a database engine that is used by many open source projects. MySQL is used by Cacti for storing setting, user, and display-related information. As MySQL 5 is the stable version, we will be using that version. In the same root shell that you had opened earlier, enter the following command:
$ apt-get install mysql-server-5.0 php5-mysql
This will install MySQL server version 5 and PHP5-MySQL, which will configure PHP so that it can talk to a MySQL server. A wizard will ask you to enter a password for the MySQL root user (as shown in the following screenshot). You need to be careful here, because it will not ask you to confirm the password, so you have only one chance to do it. Let's set the password as mysqlserver, or whatever you want. And remember it, as we will need this later.
After completing this wizard, we have to restart Apache.
$ /etc/init.d/apache2 restart
Reload [http://localhost/info.php http://localhost/info.php]and check if PHP has loaded the MySQL module:
OK, so now we have a LAMP (Linux, Apache, MySQL, PHP) configured system.
[edit] Net-SNMP
Next, we need to install Net-SNMP along with the PHP module for Net-SNMP. We can install both by using the same method seen previously:
$ apt-get install snmp php5-snmp
This will install Net-SNMP and configure PHP to use the Net-SNMP module. After the installation is done, you must restart Apache.
$ /etc/init.d/apache2 restart
Then, reload [http://localhost/info.php http://localhost/info.php] and check if PHP has loaded the SNMP module.
[edit] RRDTool
RRDTool is available in the Debian repository, so you can install it through APT.
$ apt-get intall rrdtool
[edit] Installing Cacti
After completing all the commands, we have installed all the dependences for Cacti, and can move on to the Cacti installation.
Ensure that all the previous commands have completed and you have a functioning LAMP server with SNMP and RRDTool support prior to continuing with the Cacti installation.
Cacti can be installed using two ways:
1. Binary package/Using APT.
2. Source/Manual installation.
Benefits of installing from a binary package:
- It's easy to install and upgrade.
- Needs less time than the other installation method.
Problems of a binary installation:
- You will have less control of the installation process.
- Your Cacti maybe a little backdated.
The benefits of installing from the source are:
- You will get the latest version packages, whereas the binary is sometimes little backdated.
- You have total control, you can decide what you need.
- You can do the best tuning for your system.
Problems of source installation:
- Will take more time than the binary package installation process.
- You have to update/upgrade Cacti yourself.
- You may miss an important patch for your Cacti and, this may leave some security holes open.
After reading all these points, you need to decide which installation method suits you best. If you are a new Linux user or have less experience in using Linux, I recommend following the binary method covered in the following section Installing Cacti using APT. But if you have enough experience, I recommend the manual installation, for which you can follow the section Installing Cacti From Source.
[edit] Installing Cacti using APT
In the binary method, you can install through third-party tool or the OS's package manager. Cacti can be installed on Debian server using APT (Debian's package managing tool).
We are going to install Cacti on a Linux machine. Here, we are going to use Debian GNU/Linux version 4 (etch). Debian's package managing tool is APT. Before continuing, be sure that you got no error previously. We are now in the last step of installing Cacti.
$ apt-get install cacti
This command will start installation of Cacti. A wizard will start, and ask you some important information. Here, I am going to discuss the details of this procedure:
This is simple a warning. You can ignore it. It says libphp-adodb moved to new location.
Here, you can decide if you want to take help from debconfig to configure the database for Cacti. If you are not advanced user, then I recommend following this wizard.
Here, you have to enter the MySQL root password mysqlserver, or whatever you had set before so that it can create a Cacti user and database on the MySQL server. It will not ask you again for the password confirmation, so you need to little careful here.
Here, the dialog is asking you to give an input for the Cacti user's password for the MySQL database. After pressing Enter, you have to give the same password again for confirmation. Let's set it to cactiuser or whatever you want.
If anything goes wrong or you selected the wrong option, you can start this wizard again using this command:
$ dpkg-reconfigure cacti
As we are using Apache 2 as our web server, you will have to choose Apache2 from this menu. After this, we are almost ready to configure Cacti. All the necessary files for Cacti are now installed on your system.
To complete the configuration process, open [http://localhost/cacti http://localhost/cacti] in your favorite browser.
If you got this page, everything is fine. If you don't get this page try the following:
- Ensure that all of the previous steps were completed.
- Ensure that your web server has been restarted.
- Check your apache2 log file for errors.
- If all else fails, uninstall the binary package and jump to the manual install procedure. Otherwise, continue on to the next steps.
Next is the installation type page. Here, you can select if it's new install or an upgrade. As we are going to install it for the first time, we will select New Install (which is selected by default) and click Next.
The path settings page automatically determines the installed paths for RRDTool, PHP, SNMP, andCacti.log as well as the versions for Net-SNMP and RRDTool. If any of these are missing, or you want to use a different version, adjust them on this page, and then click Next.
[edit] RRDTool Binary Path
If you installed RRDTool using APT, the default path is /usr/bin/rrdtool.
[edit] PHP Binary Path
PHP's default binary path is /usr/bin/php.
[edit] snmpwalk Binary Path
/usr/bin/snmpwalk
[edit] snmpget Binary Path
/usr/bin/snmpget
[edit] snmpbulkwalk Binary Path
/usr/bin/snmpbulkwalk
[edit] snmpgetnext Binary Path
/usr/bin/snmpgetnext
[edit] Cacti Log File Path
Cacti's default log file path on Debian is /usr/share/cacti/site/log/cacti.log. You can change it to any other place if you want to. The www-data user will need write permissions for that directory.
[edit] SNMP Utility Version
You will get the SNMP utility version on the output of phpinfo. Right now, it's Net-SNMP5.2.3, so we will select NET-SNMP 5.x.
[edit] RRDTool Utility Version
To get the version of the RRDTool that you have installed, type:
$ apt-cache policy rrdtool
This is Cacti's login screen. The username is admin and the default password is admin.
After a successful login for the first time, the system will ask you to set a new password. Enter a new password and ensure you remember it. Without this password, you cannot administer the system!
|
Using binary install If you don't have a special reason not to, it's better to use the binary install method because it will save you a huge amount of time on both install and upgrade. |
[edit] Installing Cacti from Source/Manual installation
Here, I will show you how to install Cacti from source.
Though here I am using Debian as my operating system, this procedure will work for most Linux and Unix versions.
Before installing Cacti from source, we must ensure that all its dependency packages are already installed.
1. Download the latest code from the Cacti homepage:
$ wget http://www.cacti.net/downloads/cacti-0.8.7b.tar.gz
2. After completing the download, we have to extract it:
$ tar -xzvf cacti-0.8.7b.tar.gz
3. Now, we will create a new MySQL database called cacti.
$ mysqladmin -uroot p create cacti #need password
4. It will ask for a password for the MySQL root user, enter mysqlserver or the MySQL root password that you set previously.
5. Now, we need to import cacti.sql to the cacti database:
$ mysql uroot p cacti < cacti-0.8.7b/cacti.sql
6. So, our database is ready now. Next, we will need to move the downloaded cacti folder to the web server's root folder. For Debian, Apache's root folder is /var/www/. This will move all the Cacti files and folders to /var/www:
$ mv cacti-0.8.7b /var/www/cacti
7. Now, we have to configure Cacti to use the database that we just created: $ cd /var/www/cacti
$ nano include/config.php
In the following code, replace $database_username and $database_password with your own username and password that you created before.
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "cactiuser"; $database_port = "3306";
It is recommended that you do not use the root user here, instead make a separate MySQL user for this database and give that user permission only to the Cacti database.
$ mysql uroot p mysql # will ask you root password mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY "cacti987" mysql> flush privileges;
A new user cacti will be created with the password cacti987. Now, you have to edit include/config.php with this user information. After editing that file, it will look like:
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "cacti987"; $database_port = "3306";
|
Single user per databaseIt's always a good idea to make a single user account for every user, allowing that user access only from localhost, if you will not be accessing your database from outside your network. For example: the database and the web server are on the same system. |
8. Next, we create a cron job that will run poller.php every five minutes.
$ touch /etc/cron.d/cacti
Then, edit the /etc/cron.d/cacti with your favorite editor and paste the following text there:
*/5 * * * * www-data php /var/www/cacti/poller.php> /dev/null 2>&1
This cron will poll the required data and store it in the rra folder. We have to change the ownership of rra and log folder to www-data.
$ chown R www-data rra/ log/
Now, open http://localhost/cacti in your favorite browser.
If you get this page, you are done. Now, you can log in using admin as the username. The password is also admin.
After a successful login for the first time, it will ask you for a new password.
That's all! Your Cacti is installed and configured on localhost.hes to an existing installation.
[edit] Additional References
For instructions on Creating Templates using Cact, click here
[edit] Source
The source of this content is Chapter 2: Installing Cacti of Cacti 0.8 Network Monitoring by Dinangkur Kundu, S. M. Ibrahim Lavlu (Packt Publishing, 2009).
