How to Install Cacti Network Monitoring Tool on Ubuntu 20.04
This tutorial exists for these OS versions
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
On this page
Cacti is a free, open-source and web-based network monitoring tool written in PHP. It is a front-end application for the RRDtool. It uses the SNMP protocol to monitor the bandwidth utilization and network traffic of a router or switch. It displays the CPU load and network bandwidth utilization in a graph format and populates them with data in a MySQL database.
In this tutorial, we will show you how to install the Cacti monitoring tool on Ubuntu 20.04 server.
Prerequisites
- A server running Ubuntu 20.04.
- A root password is configured the server.
Getting Started
Before starting, it is a good idea to update all system packages to the latest version. You can update them with the following command:
apt-get update -y
Once all the packages are updated, install other required dependencies by running the following command:
apt-get install snmp php-snmp rrdtool librrds-perl unzip curl git gnupg2 -y
Once all the dependencies are installed, you can proceed to the next step.
Install LAMP Server
Next, you will need to install the Apache web server, MariaDB, PHP and other required PHP extensions to your server. You can install all of them by running the following command:
apt-get install apache2 mariadb-server php php-mysql libapache2-mod-php php-xml php-ldap php-mbstring php-gd php-gmp -y
After installing all the packages, edit the php.ini file and make some changes:
nano /etc/php/7.4/apache2/php.ini
Change the following lines:
memory_limit = 512M max_execution_time = 60 date.timezone = Asia/Kolkata
Save and close the file then edit another php.ini file and make some changes:
nano /etc/php/7.4/cli/php.ini
Change the following lines:
memory_limit = 512M max_execution_time = 60 date.timezone = Asia/Kolkata
Save and close the file when you are finished. Then, restart the Apache service to apply the changes:
systemctl restart apache2
Once you are finished, you can proceed to the next step.
Configure MariaDB Server
Cacti uses MariaDB as a database backend. So you will need to create a database and user for Cacti.
First, edit the MariaDB default configuration file and tweak some settings:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add / Modify 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 = 512M 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
Save and close the file then restart the MariaDB service to apply the changes:
systemctl restart mariadb
Next, log in to 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 cactidb;
MariaDB [(none)]> GRANT ALL ON cactidb.* TO cactiuser@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 import timezone data to the MySQL database. You can import it with the following command:
mysql mysql < /usr/share/mysql/mysql_test_data_timezone.sql
Next, log in to MariaDB shell and grant required privileges on MySQL timezone with the following command:
mysql
MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
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, you will need to download the latest version of Cacti from its official website. You can download it with the following command:
wget https://www.cacti.net/downloads/cacti-latest.tar.gz
Once the download is completed, extract the downloaded file with the following command:
tar -zxvf cacti-latest.tar.gz
Next, move the extracted directory to the Apache root directory with the following command:
mv cacti-1* /var/www/html/cacti
Next, import the database to the cactidb with the following command:
mysql cactidb < /var/www/html/cacti/cacti.sql
Next, edit the Cacti config.php file and define your database settings:
nano /var/www/html/cacti/include/config.php
Change the following lines:
$database_type = 'mysql'; $database_default = 'cactidb'; $database_hostname = 'localhost'; $database_username = 'cactiuser'; $database_password = 'password'; $database_port = '3306';
Save and close the file then create a log file for Cacti.
touch /var/www/html/cacti/log/cacti.log
Next, set the ownership and permission of the cacti directory with the following command:
chown -R www-data:www-data /var/www/html/cacti/
chmod -R 775 /var/www/html/cacti/
Next, create a new Cacti cron job file with the following command:
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.
At this point, Cacti is installed and configured. You can now proceed to the next step.
Configure Apache for Cacti
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 then enable the virtual host file with the following command:
a2ensite cacti
Next, restart the Apache service to apply the configuration changes:
systemctl restart apache2
You can also verify the status of the Apache service 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 2020-12-02 03:11:25 UTC; 9s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 15445 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 15459 (apache2) Tasks: 6 (limit: 4691) Memory: 13.2M CGroup: /system.slice/apache2.service ??15459 /usr/sbin/apache2 -k start ??15460 /usr/sbin/apache2 -k start ??15461 /usr/sbin/apache2 -k start ??15462 /usr/sbin/apache2 -k start ??15463 /usr/sbin/apache2 -k start ??15464 /usr/sbin/apache2 -k start Dec 02 03:11:25 ubuntu2004 systemd[1]: Starting The Apache HTTP Server...
Once you are finished, you can proceed to the next step.
Access Cacti Web Interface
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 default admin username and password as admin and click on the Login button. You should see the password reset screen:
Change your default password and click on the Save button. You should see the License agreement page:
Accept the agreement and click on the Begin button. You should see the pre-installation check screen:
Click on the Next button. You should see the Installation Type screen:
Select your desired installation type and click on the Next button. You should see the Directory Permission check screen:
Click on the Next button. You should see the Binary Locations and Versions check screen:
Click on the Next button. You should see the following screen:
Check the "I have read this statement" and click on the Next button. You should see the following screen:
Select your desired options and click on the Next button. You should see the template setup screen:
Click on the Next button. You should see the following screen:
Click on the Next button. You should see the Confirm installation screen:
Check the "Confirm Installation" and click on the Install button. Once the installation has been completed, you should see the following screen:
Click on the Get Started button. You should see the Cacti dashboard in the following screen:
Conclusion
Congratulations! you have successfully installed and configured the Cacti monitoring tool on Ubuntu 20.04 server. You can now add network devices from the Cacti dashboard and start monitoring them from the web browser. Feel free to ask me if you have any questions.