
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 Vultr.
- 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-snmpInstall your preferred text editor.
$ sudo pkg install nanoInstall 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-posixEdit the
php.ini-productionconfiguration file.$ sudo nano /usr/local/etc/php.ini-productionLocate the
[Date]section.[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone ;date.timezone =Uncomment the
date.timezonedirective, and enter your timezone. For exampleEurope/London.date.timezone = Europe/LondonLocate the
memory_limitdirective, and change it from128Mto a value above 400MB.memory_limit = 500MLocate
max_execution_time, and change it from30to 60 or more.max_execution_time = 60Save and close the file.
Make a copy of the edited
php.ini-productionfile and rename it tophp.ini$ sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.iniStart PHP-FPM.
$ sudo service php-fpm startRestart 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 mysqlLogin to MySQL.
$ sudo mysql -u rootCreate 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.
EXITEdit the main MySQL configuration file.
$ sudo nano /usr/local/etc/mysql/my.cnfLocate the following configurations at the bottom of the file.
innodb_write_io_threads = 8 innodb_read_io_threads = 8Change the directive values as below:
innodb_write_io_threads = 16 innodb_read_io_threads = 32Save 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/cactiDownload the latest Cacti release file.
$ wget https://files.cacti.net/cacti/linux/cacti-latest.tar.gzExtract files.
$ tar -xvf cacti-latest.tar.gzMove extracted files to the Cacti directory.
$ sudo mv cacti-1.2.20/* /usr/local/www/cactiImport the Cacti database.
$ sudo mysql -u root cactidb < /usr/local/www/cacti/cacti.sqlEdit the Cacti configuration file.
$ sudo nano /usr/local/www/cacti/include/config.phpFind 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.confEdit the file.
$ sudo nano /usr/local/etc/apache24/Includes/cacti.confAdd 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 configtestRestart Apache.
$ sudo apachectl restart
5. Setup SSL
Edit the main Apache configuration file.
$ sudo nano /usr/local/etc/apache24/httpd.confLocate the following module directives.
#LoadModule ssl_module libexec/apache24/mod_ssl.so #LoadModule rewrite_module libexec/apache24/mod_rewrite.soUncomment them by removing
#.LoadModule ssl_module libexec/apache24/mod_ssl.so LoadModule rewrite_module libexec/apache24/mod_rewrite.soSave and close the file.
Test the Apache configuration file.
$ sudo apachectl configtestInstall the Apache Certbot agent.
$ sudo pkg install py38-certbot-apache py38-certbotRequest a Let’s Encrypt SSL certificate.
$ sudo certbot --apache -d cacti.androidcomet.comEnter 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.comTo 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.