Cacti is an open-source network monitoring tool that monitors network traffic using the Simple Network Management Protocol (SNMP). It can monitor traffic on multiple network devices such as routers, switches, and servers and stores the data to create performance management graphs in a database. This article explains how to install Cacti on a FreeBSD 13.0 cloud server.
Prerequisites
Before you begin, make sure you:
- Deploy a FreeBSD 13.0 server on RCS.
- Point a subdomain to the server.
- Access the server as a non-root user with sudo privileges.
- Install FAMP (FreeBSD, Apache, MySQL, PHP).
1. Install Required Packages
Install the RRDTool and SNMP.
$ sudo pkg install rrdtool net-snmp
Install your preferred text editor.
$ sudo pkg install nano
Install required PHP extensions.
$ sudo pkg install php74 php74-mysqli php74-mbstring php74-json php74-snmp php74-gd php74-gmp php74-ldap php74-zip php74-xml php74-ctype php74-openssl php74-simplexml php74-sockets php74-zlib php74-posix
Edit the
php.ini-production
configuration file.$ sudo nano /usr/local/etc/php.ini-production
Locate the
[Date]
section.[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone ;date.timezone =
Uncomment the
date.timezone
directive, and enter your timezone. For exampleEurope/London
.date.timezone = Europe/London
Locate the
memory_limit
directive, and change it from128M
to a value above 400MB.memory_limit = 500M
Locate
max_execution_time
, and change it from30
to 60 or more.max_execution_time = 60
Save and close the file.
Make a copy of the edited
php.ini-production
file and rename it tophp.ini
$ sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Start PHP-FPM.
$ sudo service php-fpm start
Restart Apache.
$ sudo apachectl restart
2. Setup the Database Server
Import system timezones to the MySQL database.
$ sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
Login to MySQL.
$ sudo mysql -u root
Create a new Cacti database.
CREATE DATABASE cactidb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
Create the Cacti database user secured with a strong password.
CREATE USER 'cacti_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Grant the user full privileges to the Cacti database.
GRANT ALL on cactidb.* TO cacti_user@localhost;
Grant the user read access to the MySQL TimeZone database.
GRANT SELECT ON mysql.time_zone_name TO cacti_user@localhost;
Refresh MySQL privileges.
FLUSH PRIVILEGES;
Exit the MySQL console.
EXIT
Edit the main MySQL configuration file.
$ sudo nano /usr/local/etc/mysql/my.cnf
Locate the following configurations at the bottom of the file.
innodb_write_io_threads = 8 innodb_read_io_threads = 8
Change the directive values as below:
innodb_write_io_threads = 16 innodb_read_io_threads = 32
Save and close the file.
Restart the MySQL database server.
$ sudo service mysql-server restart
3. Install Cacti
Create the Cacti document root directory.
$ sudo mkdir /usr/local/www/cacti
Download the latest Cacti release file.
$ wget https://files.cacti.net/cacti/linux/cacti-latest.tar.gz
Extract files.
$ tar -xvf cacti-latest.tar.gz
Move extracted files to the Cacti directory.
$ sudo mv cacti-1.2.20/* /usr/local/www/cacti
Import the Cacti database.
$ sudo mysql -u root cactidb < /usr/local/www/cacti/cacti.sql
Edit the Cacti configuration file.
$ sudo nano /usr/local/www/cacti/include/config.php
Find the following section.
$database_type = 'mysql'; $database_default = 'cacti'; $database_hostname = 'localhost'; $database_username = 'cactiuser'; $database_password = 'cactiuser'; $database_port = '3306'; $database_retries = 5; $database_ssl = false; $database_ssl_key = ''; $database_ssl_cert = ''; $database_ssl_ca = ''; $database_persist = false;
Change the values to reflect your database server, user, and password.
$database_type = 'mysql'; $database_default = 'cactidb'; $database_hostname = 'localhost'; $database_username = 'cacti_user'; $database_password = 'password'; $database_port = '3306'; $database_retries = 5; $database_ssl = false; $database_ssl_key = ''; $database_ssl_cert = ''; $database_ssl_ca = ''; $database_persist = false;
Save and close the file.
Grant Apache read and write permissions on the directory.
$ sudo chown -R www:www /usr/local/www/cacti
4. Configure Apache
Create a new Apache Virtual Host configuration file.
$ sudo touch /usr/local/etc/apache24/Includes/cacti.conf
Edit the file.
$ sudo nano /usr/local/etc/apache24/Includes/cacti.conf
Add the following configurations to the file.
<VirtualHost *:80> ServerName cacti.example.com DocumentRoot "/usr/local/www/cacti" DirectoryIndex index.php index.html Alias /cacti /usr/local/www/cacti/ <Directory /usr/local/www/cacti> AllowOverride None Order Allow,deny Allow from all Require all granted </Directory> </VirtualHost>
Save and close the file.
Test the Apache Configuration.
$ sudo apachectl configtest
Restart Apache.
$ sudo apachectl restart
5. Setup SSL
Edit the main Apache configuration file.
$ sudo nano /usr/local/etc/apache24/httpd.conf
Locate the following module directives.
#LoadModule ssl_module libexec/apache24/mod_ssl.so #LoadModule rewrite_module libexec/apache24/mod_rewrite.so
Uncomment them by removing
#
.LoadModule ssl_module libexec/apache24/mod_ssl.so LoadModule rewrite_module libexec/apache24/mod_rewrite.so
Save and close the file.
Test the Apache configuration file.
$ sudo apachectl configtest
Install the Apache Certbot agent.
$ sudo pkg install py38-certbot-apache py38-certbot
Request a Let’s Encrypt SSL certificate.
$ sudo certbot --apache -d cacti.androidcomet.com
Enter your email address and agree to Let's Encrypt terms.
Restart Apache to load changes.
$ sudo apachectl restart
6. Access Cacti
Open your web browser and load the Cacti web interface by visiting your configured subdomain or Server IP to complete the setup process.
https://cacti.example.com
To Login, use the following default username and password values.
- USERNAME:
admin
- PASSWORD:
admin
More Information
You have installed Cacti on FreeBSD 13.0. For more information, refer to the following articles.