Introduction
Cacti is an open-source network monitoring tool that uses the Simple Network Management Protocol (SNMP) to monitor network traffic and bandwidth utilization of network devices such as routers and switches. It serves as the front-end application for Round Robin Databases (RRDtool), stores and displays time-series data in graph formats. In this article, you will learn how to install Cacti Monitoring tool on Ubuntu 20.04 server.
Prerequisites
- Deploy a fully updated Rcs Ubuntu 20.04 Server.
- Create a non-root user with sudo access.
- Install LAMP on your server.
1. Configure PHP
Edit the first php.ini
file.
$ sudo nano /etc/php/*/apache2/php.ini
Change the following lines and make sure to uncomment the date.timezone
value. To search for a specific line, use Control+W, enter the search phrase, then press Enter Save and close the file.
memory_limit = 512M
max_execution_time = 300
date.timezone = "Africa/Nairobi"
Edit the second php.ini
file.
$ sudo nano /etc/php/*/cli/php.ini
Change the following lines. Save and close the file.
memory_limit = 512M
max_execution_time = 300
date.timezone = "Africa/Nairobi"
Restart the Apache service to apply the changes.
$ sudo systemctl restart apache2
2. Configure MariaDB Server
Edit the MariaDB default configuration file.
$ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Modify the following lines. Save and close the file.
innodb_file_format=Barracuda
innodb_large_prefix=1
collation-server=utf8mb4_unicode_ci
character-set-server=utf8mb4
innodb_doublewrite=ON
max_heap_table_size=128M
tmp_table_size=128M
join_buffer_size=128M
innodb_buffer_pool_size=1G
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
innodb_io_capacity=5000
innodb_io_capacity_max=10000
innodb_buffer_pool_instances=9
Make sure to comment out the following code to avoid configuration issues:
# collation-server = utf8mb4_general_ci
Restart the MariaDB service to apply the changes.
$ sudo systemctl restart mariadb
Log in to the MariaDB shell.
$ sudo mysql -u root -p
Create a database named cactidb
.
CREATE DATABASE cactidb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Grant all permissions of the created database to cactiuser
.
GRANT ALL ON cactidb.* TO cactiuser@localhost IDENTIFIED BY 'StrongPassword';
Flush the privileges.
FLUSH PRIVILEGES;
Exit from the MariaDB shell.
exit;
Import timezone data to the MySQL database.
$ sudo mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql
Log in to MariaDB shell.
$ sudo mysql -u root -p
Grant required privileges on MySQL timezone.
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
Flush the privileges.
FLUSH PRIVILEGES;
Exit from the MariaDB shell.
exit;
3. Install Cacti
Download the latest version of Cacti from its official website. You can download it with the following command:
$ wget https://files.cacti.net/cacti/linux/cacti-latest.tar.gz
Extract the downloaded file.
$ sudo tar -zxvf cacti-latest.tar.gz
Move the extracted directory to the Apache root directory.
$ sudo mv cacti-1* /var/www/html/cacti
Import the database to the cactidb
.
$ sudo mysql -u root -p cactidb < /var/www/html/cacti/cacti.sql
Edit the Cacti configuration file config.php
.
$ sudo nano /var/www/html/cacti/include/config.php
Change the following lines, save and close the file.
$database_type = 'mysql';
$database_default = 'cactidb';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'StrongPassword';
$database_port = '3306';
Create the log file.
$ sudo touch /var/www/html/cacti/log/cacti.log
Set the ownership and permission of the cacti directory.
$ sudo chown -R www-data:www-data /var/www/html/cacti/
$ sudo chmod -R 775 /var/www/html/cacti/
Create a new Cacti cron job file.
$ sudo nano /etc/cron.d/cacti
Add the following line, save and close the file.
*/5 * * * * www-data php /var/www/html/cacti/poller.php > /dev/null 2>&1
4. Configure Apache
Create an Apache virtual host configuration file for Cacti.
$ sudo nano /etc/apache2/sites-available/cacti.conf
Add the following lines, save and close the file.
Alias /cacti /var/www/html/cacti
<Directory /var/www/html/cacti>
Options +FollowSymLinks
AllowOverride None
<IfVersion >= 2.3>
Require all granted
</IfVersion>
<IfVersion < 2.3>
Order Allow,Deny
Allow from all
</IfVersion>
AddType application/x-httpd-php .php
<IfModule mod_php.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>
DirectoryIndex index.php
</Directory>
Enable the Cacti configuration file.
$ sudo a2ensite cacti
Restart the Apache service to apply the configuration.
$ sudo systemctl restart apache2
Verify the status of the Apache service.
$ sudo systemctl status apache2
5. Access Cacti Web Interface
Open your web browser and access the Cacti web interface using the URL http://ServerIP/cacti
. For example:
http://192.0.2.10/cacti
Conclusion
You have successfully installed Cacti on your server. To log in, use admin as your username and admin as your password. You will access the password reset screen to change your admin password. You can now configure Cacti.
More Information
For more information on Cacti, please see the official documentation.