From ArchWiki
Revision as of 21:52, 4 February 2019 by Indigo (talk | contribs) (→‎Nginx: expand abbreviation, disable http link, style fix)
Jump to navigation Jump to search

Cacti is a web-based system monitoring and graphing solution.

Server setup

This article assumes that you already have a working LAMP (Linux, Apache, MySQL, PHP) server. Alternatively, when using Nginx instead of Apache, it is assumed you have a php proxy such as php-fpm running as well.

Cacti setup

Install the cacti, php-snmp and net-snmp packages. Ensure LAMP services (httpd, mysqld) are started and enabled. If it is necessary for Cacti to monitor the machine that it is running on, configure snmpd.

Cacti uses PHP, an SQL database (MySQL or MariaDB) and SNMP, so enable the required PHP modules:


PHP scripts are, by default, permitted only to open files in specific directories. Configure (or comment out) open_basedir in /etc/php/php.ini. When misconfigured, errors such as PHP Warning: include(): open_basedir restriction in effect. will appear in the webserver log file. Don’t forget to add /etc/webapps (or /etc/webapps/cacti if you prefer) and /var/log/cacti to open_basedir.

In order to display dates and times in the correct timezone, configure date.timezone in /etc/php/php.ini. Values are in "Continent/City" notation, for example "America/New_York", "Asia/Tokyo".


Configure Apache to point to Cacti by adding the following in a /etc/httpd/conf/extra/cacti.conf (or in a vhost's config file):

Alias /cacti /usr/share/webapps/cacti
<Directory /usr/share/webapps/cacti>
  # PHP options
  AddType application/x-httpd-php .php
  <IfModule dir_module>
    DirectoryIndex index.php

  Require all granted
  Options +FollowSymLinks
  AllowOverride All

  # The following may be useful.
  #<IfModule mod_php5.c>
  #  php_flag magic_quotes_gpc Off
  #  php_flag short_open_tag On
  #  php_flag register_globals Off
  #  php_flag register_argc_argv On
  #  php_flag track_vars On
  #  # This setting is necessary for some locales.
  #  php_value mbstring.func_overload 0
  #  php_value include_path .


When using Nginx, the following configuration snippet works for a subdomain:

server {
   listen 80;
   return 301 https://$server_name$request_uri;

server {
   listen 443 ssl;
   root /usr/share/webapps/cacti;
   index index.php;
   charset utf-8;

   location ~ \.php?$ {
       include /etc/nginx/fastcgi_params;
       fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   access_log /var/log/nginx/cacti.access.log main;
   error_log /var/log/nginx/cacti.error.log warn;

   include ssl.conf;

Edit the following parameter:

$url_path = '/';

If the Cacti configuration is in a separate file, remember to add Include conf/extra/cacti.conf to /etc/httpd/conf/httpd.conf.

The file /usr/share/webapps/cacti/.htaccess also controls access. Configure or remove it.

Cacti needs to have permission to write its gathered data and log messages to disk: # chown -R http:http /usr/share/webapps/cacti/{rra,log}

MySQL setup

Cacti needs its own database in which to store its data, and a database user account to access the database.

Run the following commands as root:

# mysqladmin -u root -p create cactidb
# mysql -u root -p cactidb </usr/share/webapps/cacti/cacti.sql
# mysql -u root -p
mysql> GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'some_password';
mysql> exit

Alternatively, use PhpMyAdmin to achieve the same results:

  • Create an empty database called cactidb.
  • Import the file /usr/share/webapps/cacti/cacti.sql into the cactidb database.
  • Create a user cactiuser, and grant this user privileges to access the cactidb database.

Add the database access details to /usr/share/webapps/cacti/include/config.php:

$database_type = "mysql";
$database_default = "cactidb";
$database_username = "cactiuser";
$database_password = "some_password";


Optionally, install cacti-spineAUR, a faster poller for cacti, from the AUR. configure it with database access details:

DB_User cactiuser
DB_Pass some_password


Cacti uses a poller to collect data, so create a Systemd service to run poller.php, and a timer to run the service every 5 minutes:

Description=Cacti Poller

ExecStart=/usr/bin/php /usr/share/webapps/cacti/poller.php
Description=Cacti Poller Timer


Note: Do not start or enable cacti_poller.service. Instead, start and enable cacti_poller.timer only, which calls the service every 5 minutes.
Tip: journalctl can be used to watch for the poller's log messages, which will resemble the following:
Sep 27 15:50:00 hoom php[4072]: OK u:0.00 s:0.01 r:0.35
Sep 27 15:50:00 hoom php[4072]: OK u:0.00 s:0.01 r:0.38
Sep 27 15:50:00 hoom php[4072]: OK u:0.00 s:0.01 r:0.40
Sep 27 15:50:01 hoom php[4072]: 09/27/2015 03:50:01 PM - SYSTEM STATS: Time:0.6176 Method:cmd.php Processes:1 Threads:N/A Hosts:5 HostsPerProcess:5 DataSources:169 RRDsProcessed:15

Web configuration

Open a browser and go to http://your_server/cacti/. You should be welcomed with the cacti installer.

  • Click Next
  • Select New Install and click Next
  • Ensure that all paths are ok. You need to specify versions of RRDTool and NET-SNMP. Get RRDTool Utility Version using 'rrdtool -v', and'net-snmp-config --version' for NET-SNMP. Click Finish.
    • If any paths are invalid, you'll need to figure out why. Check the apache error logs for hints.
  • Login with username "admin" and password "admin".
  • Change the password as requested, click Save.
  • (Optional) If you chose to install spine, follow these instructions to set it up.
    • Click on Settings, on the left panel of the Console tab.
    • Select the Poller tab.
    • Change Poller Type to spine.
    • Adjust any other settings on the page as desired, then click Save.
    • Select the Paths tab.
    • Set Spine Poller File Path to /usr/bin/spine and click Save.

External links