
Cacti is an open source RRDtool-based graphing system that uses PHP/Apache for its interface and stores configuration data in a MySQL database. It scales well and may be used within large enterprise network environments. It also supports a robust plugin architecture that allows powerful Cacti plugins, such as Network Weathermap.
This HOWTO does not cover creating graphs using Cacti's interface (for this refer to the Cacti docs) because I prefer to create graphs using the NeDi Cacti API, and I think using Cacti with NeDi is superior to using Cacti alone because NeDi adds robust device discovery and interface browsing and selection. Creating Cacti graphs with NeDi's Cacti API is stunningly simple and easier than creating graphs within the Cacti interface itself.
This section covers installing general support software required for Cacti -MySQL and the PHP scripting language.
You may install the MacPorts package manager with these instructions, which include instructions for installing XWindows (X11). Follow the instructions carefully and perform all non-optional steps.
NeDi has a Cacti API that makes Cacti graph creation within NeDi far easier than within Cacti's own web interface, so I highly recommend interrupting the Cacti install at this point and installing NeDi. Then continue the Cacti install by skipping the rest of this section (NeDi prerequisites include MySQL5 and PHP5) and resume at Install and Configure Cacti.
before installing NeDi to use with Cacti. If you install NeDi to use with Cacti, skip the rest of the prerequisites section since the NeDi prerequisites also include MySQL5 and a MacPorts install of PHP5 to provide SNMP support.
To use the NeDi Cacti API, Cacti must be installed on the same host as NeDi.
MySQL is used to store the data necessary for Cacti configuration and operation.
Install MySQL with MacPorts
%%sudo port install mysql5 +server
Execute the mysql_install_db5 command to do a first-time setup for MySQL5.
%%sudo -u mysql mysql_install_db5
Start MySQL and set it to run at system boot.
%%sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
Verify the MySQL process is running with this command.
%%ps -ax | grep mysql
If MySQL is running you will see output similar to this.
26683 ?? Ss 0:00.05 /opt/local/bin/daemondo --label=mysql5 --start- 26692 ?? S 0:00.02 /bin/sh /opt/local/lib/mysql5/bin/mysqld_safe - 26712 ?? S 0:16.90 /opt/local/libexec/mysqld --basedir=/opt/local 20796 p2 R+ 0:00.00 grep mysql
Set the MySQL root password.
%%sudo /opt/local/lib/mysql5/bin/mysqladmin -u root password <mypassword>
Perform a MySQL root account login test with the new root password.
%%mysql5 -u root -p
You may install PHP from any source, but a good PHP 5 binary installer that works with Apple's built-in Apache is Marc Liyanage’s PHP 5 package. Just download it, run the installer, do an “easy install”, and afterwards edit the file /usr/local/php5/lib/php.ini for MacPorts' MySQL5 as shown.
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
To activate PHP after installation, restart Apache.
Go to System Preferences on the Apple menu.
Click the Sharing icon.
Check the Web Sharing checkbox, or remove the check and check it again.
To test PHP, create a file named test.php in /Library/WebServer/Documents that contains the line shown below.
<?php phpinfo() ?>.
Now open url http://localhost/test.php in your web browser. If PHP is working properly you will see a PHP status table.
Here we install Snort, import the Snort MySQL database schema, and configure Snort.
Use these steps to install Cacti via MacPorts. If you plan to use Cacti plugins, such as Network Weathermap, you must use the “plugins” MacPorts variant as shown below. Otherwise, you may omit this variant.
%%sudo port install cacti +plugins
After the Cacti install is complete, set a symlink for Cacti inside your Apache document root.
%%sudo ln -s /opt/local/share/cacti/ /<Apache-docroot>/cacti
The Cacti files should be flagged to the same owner as your Apache user. The default Apache user on OS X is "www", so you may just use that as your Apache user as shown in the example below.
%%sudo chown -R www:www /opt/local/share/cacti/
Login to MySQL as the root user.
%%mysql5 -u root -p
Once logged into MySQL as root, create a Cacti database and user, and set the database permissions.
mysql>grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti@localhost;mysql>grant CREATE,INSERT,SELECT,DELETE,UPDATE on cacti.* to cacti;mysql>SET PASSWORD FOR cacti@localhost = OLD_PASSWORD('<cactidb-pwd>');mysql>create database cacti;mysql>exit
Now import the Cacti database schema.
%%cd /opt/local/share/cacti%%sudo cat cacti.sql | mysql5 –u root –p cacti
Finally, login to MySQL as root and show the Cacti tables to verify the Cacti database schema was imported.
%%mysql5 –u root –pmysql>use cacti;mysql>show tables;
The Cacti database tables display as shown.
+--------------------------------+ | Tables_in_cacti | +--------------------------------+ | cdef | | cdef_items | | colors | | data_input | | data_input_data | | data_input_fields | | data_local | | data_template | | data_template_data | | data_template_data_rra | | data_template_rrd | | graph_local | | graph_template_input | | graph_template_input_defs | | graph_templates | | graph_templates_gprint | | graph_templates_graph | | graph_templates_item | | graph_tree | | graph_tree_items | | host | | host_graph | | host_snmp_cache | | host_snmp_query | | host_template | | host_template_graph | | host_template_snmp_query | | poller | | poller_command | | poller_item | | poller_output | | poller_reindex | | poller_time | | rra | | rra_cf | | settings | | settings_graphs | | settings_tree | | snmp_query | | snmp_query_graph | | snmp_query_graph_rrd | | snmp_query_graph_rrd_sv | | snmp_query_graph_sv | +--------------------------------+ 70 rows in set (0.09 sec)
Edit Cacti's config.php file.
%%cd /opt/local/share/cacti/include%%sudo pico config.php
Modify the MySQL variables.
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "<my-cacti-password>";Plugin support is optional, and may only be used if you installed Cacti with the “plugins” MacPorts variant. However, if you installed Cacti with plugin support, then you must setup plugin support properly for your Cacti installation to work.to functionthere are some additonal steps to perform.
Import the PA schema
%%cd /opt/local/share/cacti%%sudo cat pa.sql | mysql5 -u root -p cacti
Set the Cacti URL in file
/opt/local/share/cacti/include/global.php to
/cacti/ as shown (including the trailing “/”)
$config['url_path'] = '/cacti/';
Download and unzip the Cacti plugin(s) you wish to use to the directory /opt/local/share/cacti/plugins, and set the permissions of the plugin files to the Unix user chosen to run Cacti (www in this example). There is a MacPorts port for the Network Weathermap Cacti plugin, so copying and unpacking it manually is not necessary, as shown below.
%%sudo port install network-weathermap%%sudo chown -R www:www /opt/local/share/cacti/plugins/
Edit /opt/local/share/cacti/include/global.php and add an entry for each plugin you installed after the “plugins” statement.
$plugins = array(); $plugins[] = 'weathermap';
You must enable plugin(s) in the Cacti web interface for your Cacti user. See the section Login to Cacti.
To collect graph data from devices, Cacti uses a poller. It is set to run via cron, typically every 5 minutes.
Run the Cacti poller manually for the first time to verify it is operating correctly. If you are using another user to run Cacti besides the user “www”, substitute that user in the example below. If you have no errors you may proceed to setup cron for polling.
%%sudo -u www /opt/local/bin/php /opt/local/share/cacti/poller.php
Edit the Cacti user's crontab; the Cacti user is “www” here.
%%sudo -u www crontab -e
Set the Cacti poller in cron to poll devices every 5 minutes.
*/5 * * * * /opt/local/bin/php /opt/local/share/cacti/poller.php > /dev/null 2>&1
Start your web browser and go to: http://localhost/cacti to login to the Cacti web interface. The default user/password is admin/admin.

After logging in, you'll see the Cacti console window as shown below.

After logging into the Cacti interface, you should immediately set Cacti to use RRDtool 1.2.x, the version that was installed as a Cacti dependency by MacPorts. The rest of the settings should be fine at the defaults.

If you installed Cacti with plugin support and installed plugin(s), you must enable the plugin(s) in the Cacti web interface for your Cacti user. To do so, enter Console -> User Management, check the appropriate plugin checkboxes in the Realm Permissions pane as shown below, and click .

If the plugin(s) were installed correctly, after checking the boxes in the Realm Permissions pane, you will see a new top-level tab in the Cacti interface as shown below for the Network Weathermap plugin.

This completes the Cacti install with optional plugin support. For easy graph creation, I recommend creating your Cacti graphs using NeDi, a great tool in its own right. NeDi discovers all your network devices automatically and allows you to effortlessly select interfaces for Cacti graphs using the Cacti API. To create graphs natively within Cacti, you should read the Cacti documentation.
To get help with Cacti, you should first consult the documentation. If that doesn’t help you may ask questions in the Cacti forums. Before asking a question, be sure to search the forum to see if your question has already been asked.