Difference between revisions of "Cacti"

From ArchWiki
Jump to: navigation, search
m (Updated location to /usr/share/webapps)
m (add ja link)
 
(21 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[[Category:Daemons and system services]]
+
[[Category:Network monitoring]]
 
[[fr:cacti]]
 
[[fr:cacti]]
This article describes how to set up Cacti on an Arch Linux system. Cacti is a web-based system monitoring and graphing solution.
+
[[ja:Cacti]]
 +
[http://www.cacti.net/ Cacti] is a web-based system monitoring and graphing solution.
  
 
==Server Setup==
 
==Server Setup==
This article assumes that you already have a working LAMP (Linux, Apache, MySQL, PHP) server. If you do not have a web-server set up already, you can follow [[LAMP|these instructions]] to do so.
+
This article assumes that you already have a working [[LAMP]] (Linux, Apache, MySQL, PHP) server.
  
 
==Cacti Setup==
 
==Cacti Setup==
The following should all be performed as root.
+
[[Install]] the {{Pkg|cacti}}, {{Pkg|php-snmp}} and {{Pkg|net-snmp}} packages. Ensure LAMP services ({{ic|httpd}}, {{ic|mysqld}}) are [[start]]ed and [[enable]]d. If it is necessary for Cacti to monitor the machine that it is running on, configure [[snmpd]].
  
* Install the necessary programs
+
Cacti uses PHP, an SQL database (MySQL or MariaDB) and SNMP, so enable the required PHP modules:
# pacman -S cacti php-snmp
+
{{hc|/etc/php/php.ini|2=
 +
extension=mysqli.so
 +
extension=sockets.so
 +
extension=snmp.so}}
  
* Edit /etc/php/php.ini
+
PHP scripts are, by default, permitted only to open files in specific directories. Configure (or comment out) {{ic|open_basedir}} in {{ic|/etc/php/php.ini}}. When misconfigured, errors such as {{ic|PHP Warning: include(): open_basedir restriction in effect.}} will appear in the webserver log file.
:* Uncomment the following lines:
+
;extension=mysql.so
+
;extension=sockets.so
+
;extension=snmp.so
+
:* Comment the following line:
+
open_basedir=...
+
:* Uncomment and set the following:
+
;date.timezone =
+
  
* Start mysqld and snmpd if they're not already running:
+
In order to display dates and times in the correct timezone, configure {{ic|date.timezone}} in {{ic|/etc/php/php.ini}}. Values are in "Continent/City" notation, for example "America/New_York", "Asia/Tokyo".
# /etc/rc.d/mysqld start
+
# /etc/rc.d/snmpd start
+
:* Add mysqld and snmdp to the DAEMONS array in /etc/rc.conf to ensure that they're running at bootup
+
  
* Edit /etc/httpd/conf/httpd.conf
+
Configure Apache to point to Cacti by adding the following in a {{ic|/etc/httpd/conf/extra/cacti.conf}} (or in a vhost's config file):
:* Inside the <Directory "/srv/http"> block, ensure that you have the following line:
+
{{bc|<nowiki>
AllowOverride All
+
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
 +
  </IfModule>
  
* MySQL setup
+
  Require all granted
:* Create the cacti database, load the tables, and set the user. You will be asked for the MySQL root password for each of these commands.
+
  Options +FollowSymLinks
# mysqladmin -u root -p create cacti
+
  AllowOverride All
# mysql -u root -p cacti < /usr/share/webapps/cacti/cacti.sql
+
# mysql -u root -p
+
  mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'some_password';
+
  mysql> FLUSH PRIVILEGES;
+
  mysql> exit
+
  
''Note:'' As of march 2011 (mysql 5.5.9-1, cacti 0.8.7g-1) mysql fails to import the SQL due to an outdated syntax. You can update the file using this command:
+
  # 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 .
 +
  #</IfModule>
 +
</Directory>
 +
</nowiki>}}
  
cd /usr/share/webapps/cacti && mv cacti.sql cacti.sql.org && sed s/TYPE=/ENGINE=/g cacti.sql.org > cacti.sql
+
If the Cacti config is in a separate file, remember to add {{ic|Include conf/extra/cacti.conf}} to {{ic|/etc/httpd/conf/httpd.conf}}.
  
* Edit /usr/share/webapps/cacti/include/config.php. The password was specified in the previous step.
+
The file {{ic|/usr/share/webapps/cacti/.htaccess}} also controls access. Configure or remove it.
$database_username = "cacti";
+
$database_password = "some_password";
+
  
* Clean up cacti directory
+
Cacti needs to have permission to write its gathered data and log messages to disk: {{ic|<nowiki># chown -R http:http /usr/share/webapps/cacti/{rra,log}</nowiki>}}
# chown -R http:http /usr/share/webapps/cacti/{rra,log}
+
# rm /usr/share/webapps/cacti/.htaccess
+
# chmod +x /usr/share/webapps/cacti/{cmd,poller}.php /usr/share/webapps/cacti/lib/ping.php
+
  
* Optionally, install [https://aur.archlinux.org/packages.php?ID=21541 cacti-spine], a faster poller for cacti, from the [[AUR]]. Use the same password as in previous steps.
+
==MySQL setup==
 +
Cacti needs its own database in which to store its data, and a database user account to access the database.
  
:* Edit /etc/spine.conf
+
Run the following commands as root:
DB_User cacti
+
{{bc|<nowiki># mysqladmin -u root -p create cactidb
DB_Pass some_password
+
# 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> FLUSH PRIVILEGES;
 +
mysql> exit</nowiki>}}
  
* Set up cron job to run poller every 5 minutes
+
Alternatively, use [[PhpMyAdmin]] to achieve the same results:
# crontab -e
+
* Create an empty database called {{ic|cactidb}}.
:* Add the following to the end of the list
+
* Import the file {{ic|/usr/share/webapps/cacti/cacti.sql}} into the {{ic|cactidb}} database.
*/5 * * * * /usr/bin/sudo -u http /usr/bin/php /usr/share/webapps/cacti/poller.php &> /dev/null
+
* Create a user {{ic|cactiuser}}, and grant this user privileges to access the {{ic|cactidb}} database.
  
* Restart cron and apache
+
Add the database access details to {{ic|/usr/share/webapps/cacti/include/config.php}}:
# /etc/rc.d/crond restart
+
{{bc|<nowiki>$database_default = "cactidb";
# /etc/rc.d/httpd restart
+
$database_username = "cactiuser";
 +
$database_password = "some_password";</nowiki>}}
 +
 
 +
==Spine==
 +
Optionally, install {{AUR|cacti-spine}}, a faster poller for cacti, from the [[AUR]]. configure it with database access details:
 +
{{hc|/etc/spine.conf|<nowiki>DB_User cactiuser
 +
DB_Pass some_password</nowiki>}}
 +
 
 +
==Systemd==
 +
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:
 +
 
 +
{{hc|/etc/systemd/system/cacti_poller.service|
 +
<nowiki>[Unit]
 +
Description=Cacti Poller
 +
 
 +
[Service]
 +
User=http
 +
Type=simple
 +
ExecStart=/usr/bin/php /usr/share/webapps/cacti/poller.php</nowiki>
 +
}}
 +
 
 +
{{hc|/etc/systemd/system/cacti_poller.timer|
 +
<nowiki>[Unit]
 +
Description=Cacti Poller Timer
 +
 
 +
[Timer]
 +
OnCalendar=*:0/5:0
 +
Unit=cacti_poller.service
 +
AccuracySec=1
 +
 
 +
[Install]
 +
WantedBy=multi-user.target</nowiki>
 +
}}
 +
 
 +
{{Note|Do not start or enable {{ic|cacti_poller.service}}. Instead, [[start]] and enable {{ic|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:
 +
{{bc|<nowiki>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</nowiki>}}}}
  
 
==Web Configuration==
 
==Web Configuration==
Open up a browser and go to http://your_ip/cacti. You should be welcomed with the cacti installer.
+
Open a browser and go to http:<nowiki/>//your_server/cacti/. You should be welcomed with the cacti installer.
 
* Click Next
 
* Click Next
 
* Select New Install and click Next
 
* Select New Install and click Next
Line 83: Line 129:
 
** Select the Paths tab.
 
** Select the Paths tab.
 
** Set Spine Poller File Path to /usr/bin/spine and click Save.
 
** Set Spine Poller File Path to /usr/bin/spine and click Save.
 
==See Also==
 
* [[LAMP]] - Set up a LAMP server
 
  
 
==External Links==
 
==External Links==
 
* http://cacti.net
 
* http://cacti.net

Latest revision as of 08:05, 19 February 2016

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.

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:

/etc/php/php.ini
extension=mysqli.so
extension=sockets.so
extension=snmp.so

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.

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
  </IfModule>

  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 .
  #</IfModule>
</Directory>

If the Cacti config 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> FLUSH PRIVILEGES;
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_default = "cactidb";
$database_username = "cactiuser";
$database_password = "some_password";

Spine

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

/etc/spine.conf
DB_User cactiuser
DB_Pass some_password

Systemd

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:

/etc/systemd/system/cacti_poller.service
[Unit]
Description=Cacti Poller

[Service]
User=http
Type=simple
ExecStart=/usr/bin/php /usr/share/webapps/cacti/poller.php
/etc/systemd/system/cacti_poller.timer
[Unit]
Description=Cacti Poller Timer

[Timer]
OnCalendar=*:0/5:0
Unit=cacti_poller.service
AccuracySec=1

[Install]
WantedBy=multi-user.target
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