Cacti is a free and powerful network monitoring and graphing tool for Linux. It is a frontend tool for RRDtool used to poll services at predetermined intervals and graph the resulting data. Cacti provide a web-based interface, where you can monitor system performance, CPU load, and network bandwidth utilization in a graph format. It is written in PHP and uses MySQL/MariaDB database to store their data
In this tutorial, we will show you how to install the Cacti monitoring tool on Ubuntu 22.04.
Prerequisites
- A server running Ubuntu 22.04 with a minimum 2 GB RAM.
- A root password is configured on the server.
Getting Started
First, it is recommended to update your system packages to the latest version. You can update them with the following command:
apt update -y apt upgrade -y
Once all the packages are updated, install other dependencies required for Cacti with the following command:
apt-get install snmp php-snmp rrdtool librrds-perl unzip git gnupg2 -y
Once all the dependencies are installed, you can proceed to the next step.
Install Apache, PHP, and MariaDB
First, you will need to install the Apache web server, MariaDB database server, PHP and other necessary PHP extensions to your system. You can install all of them with the following command:
apt-get install apache2 mariadb-server php php-mysql php-intl libapache2-mod-php php-xml php-ldap php-mbstring php-gd php-gmp -y
Once all the packages are installed, edit the php.ini file and change the default settings.
nano /etc/php/8.1/apache2/php.ini
Change the following lines:
memory_limit = 512M max_execution_time = 360 date.timezone = UTC
Save and close the file when you are finished then open another php.ini file:
nano /etc/php/8.1/cli/php.ini
Change the following lines:
memory_limit = 512M max_execution_time = 360 date.timezone = UTC
Save and close the file then restart the Apache service to apply the changes:
systemctl restart apache2
Once you are finished, you can proceed to the next step.
Create a Database and User for Cacti
Next, you will need to create a database and user for Cacti. First, log into the MariaDB shell with the following command:
mysql
Once login, create a database and user for Cacti with the following command:
MariaDB [(none)]> create database cacti; MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'password';
Next, flush the privileges and exit from the MariaDB shell with the following command:
MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit;
Next, you will need to edit the MariaDB configuration file and tweak some settings. You can do it by editing the file /etc/mysql/mariadb.conf.d/50-server.cnf.
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add the following lines inside [mysqld] section:
collation-server = utf8mb4_unicode_ci max_heap_table_size = 128M tmp_table_size = 64M join_buffer_size = 64M innodb_file_format = Barracuda innodb_large_prefix = 1 innodb_buffer_pool_size = 1024M 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 sort_buffer_size = 10K innodb_doublewrite = OFF
Save and close the file when you are finished then restart the MariaDB service to apply the changes:
systemctl restart mariadb
Next, import the mysql_test_data_timezone.sql to mysql database with the following command:
mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql
Next, log into MySQL and grant cacti user to access the mysql.time_zone_name table:
mysql
Once login, run the following command to grant access:
MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti@localhost; MariaDB [(none)]> ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Next, flush the privileges and exit from the MariaDB shell with the following command:
MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit;
Once you are finished, you can proceed to the next step.
Install and Configure Cacti
First, download the latest version of Cacti in your system with the following command:
wget https://www.cacti.net/downloads/cacti-latest.tar.gz
Once the Cacti is downloaded, extract the downloaded file with the following command:
tar -zxvf cacti-latest.tar.gz
Next, move the extracted directory to the Apache root directory using the following command:
mv cacti-1.2.23 /var/www/html/cacti
Next, change the ownership of the cacti to www-data with the following command:
chown -R www-data:www-data /var/www/html/cacti/
Next, import the Cacti data to the Cacti database with the following command:
mysql -u root -p cacti < /var/www/html/cacti/cacti.sql
Next, edit the Cacti configuration file and define your database settings:
nano /var/www/html/cacti/include/config.php
Change the following lines that match with your database:
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "password"; $database_port = "3306"; $database_ssl = false;
Save and close the file when you are finished then create a Cron file for Cacti.
nano /etc/cron.d/cacti
Add the following line:
*/5 * * * * www-data php /var/www/html/cacti/poller.php > /dev/null 2>&1
Save and close the file when you are finished then create a log file for Cacti with the following command:
touch /var/www/html/cacti/log/cacti.log chown -R www-data:www-data /var/www/html/cacti/
Once you are finished you can proceed to the next step.
Create an Apache Virtual Host
Next, you will need to create an Apache virtual host configuration file for Cacti. You can create it with the following command:
nano /etc/apache2/sites-available/cacti.conf
Add the following lines:
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>
Save and close the file when you are finished. Then, enable the Cacti virtual host with the following command:
a2ensite cacti
Next, restart the Apache service to apply the changes:
systemctl restart apache2
You can also check the status of the Apache with the following command:
systemctl status apache2
You should get the following output:
? apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2023-01-18 14:01:31 UTC; 8s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 19267 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 19271 (apache2) Tasks: 6 (limit: 4579) Memory: 12.9M CPU: 84ms CGroup: /system.slice/apache2.service ??19271 /usr/sbin/apache2 -k start ??19272 /usr/sbin/apache2 -k start ??19273 /usr/sbin/apache2 -k start ??19274 /usr/sbin/apache2 -k start ??19275 /usr/sbin/apache2 -k start ??19276 /usr/sbin/apache2 -k start Jan 18 14:01:31 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...
At this point, Apache web server is configured to serve Cacti. You can now proceed to the next step.
Access Cacti Web UI
Now, open your web browser and access the Cacti web interface using the URL http://your-server-ip/cacti. You will be redirected to the Cacti login page:
Provide the default username and password as admin / admin then click on the Login button. You should see the Cacti password change screen:
Provide your default password, new password and click on the Save button. You should see the Cacti license agreement page:
Accept the license agreement and click on the Begin button. You should see the pre-installation check page:
Make sure all the packages are installed then click on the Next button. You should see the following page:
Select your installation type and click on the Next button. You should see the directory permission check page:
Click on the Next button. You should see the following page.
Click on the Next button. You should see the Input Validation page:
Check the checkbox and click on the Next button. You should see the Profile page:
Select your required template and click on the Next button. You should see the following page:
Click on the Next button. You should see the following page:
Confirm the installation and click on the Install button. Once the installation has been finished, you should see the following page:
Click on the Get Started button. You should see the Cacti dashboard on the following page:
Conclusion
Congratulations! you have successfully installed and configured the Cacti network monitoring tool on Ubuntu 22.04. You can now install the Cacti agent on the client’s machine and add them to the Cacti server and start monitoring. Feel free to ask me if you have any questions.