In this tutorial we’ll learn how to install and configure Cacti network monitoring tool in the latest version of Debian and Ubuntu 16.04 LTS. Cacti will be build and installed from source files during this guide.
Cacti is an open source monitoring tool created for monitoring networks, especially network devices, such as switches, routers, servers via SNMP protocol. Cacti interacts with end-users and can be administered via a web tool interface.
Requirements
Step 1: Install and Configure Prerequisites for Cacti
1. In Debian 9, open sources list file for editing and add the contrib and non-free repositories to the file by changing the following lines:
# nano /etc/apt/sources.list
Add following lines to sources.list file.
deb http://ftp.ro.debian.org/debian/ stretch main contrib non-free deb-src http://ftp.ro.debian.org/debian/ stretch main deb http://security.debian.org/debian-security stretch/updates main contrib non-free deb-src http://security.debian.org/debian-security stretch/updates main
Add Repositories to Debian
2. Afterwards, make sure to update the system by issuing the below command.
# apt update # apt upgrade
3. In your LAMP stack make sure the following PHP extensions are present in the system.
# apt install php7.0-snmp php7.0-xml php7.0-mbstring php7.0-json php7.0-gd php7.0-gmp php7.0-zip php7.0-ldap php7.0-mcrypt
4. Next, edit PHP configuration file and change the time zone setting to match your server’s physical location, by issuing the below command.
# echo "date.timezone = Europe/Bucharest" >> /etc/php/7.0/apache2/php.ini
5. Next, log in to MariaDB or MySQL database from your LAMP stack installation and create a database for installing Cacti by issuing the following commands.
Replace cacti database name, user and password to match your own configurations and choose a strong password for cacti database.
# mysql -u root -p mysql> create database cacti; mysql> grant all on cacti.* to 'cactiuser'@'localhost' identified by 'password1'; mysql> flush privileges; mysql> exit
6. Also, issue the below commands to allow cacti user select permissions to MySQL data.timezone setting by issuing the below commands.
# mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql # mysql -u root -p -e 'grant select on mysql.time_zone_name to cactiuser@localhost'
7. Next, open MySQL server configuration file and add the following lines at the end of the file.
# nano /etc/mysql/mariadb.conf.d/50-server.cnf [For MariaDB] # nano /etc/mysql/mysql.conf.d/mysqld.cnf [For MySQL]
Add the following lines to the end of the 50-server.cnf or mysqld.cnf file.
max_heap_table_size = 98M tmp_table_size = 64M join_buffer_size = 64M innodb_buffer_pool_size = 485M innodb_doublewrite = off innodb_flush_log_at_timeout = 3 innodb_read_io_threads = 32 innodb_write_io_threads = 16
For MariaDB database also add the following line to the end of the 50-server.cnf file:
innodb_additional_mem_pool_size = 80M
8. Finally, restart MySQL and Apache services to apply all settings and verify both services status by issuing the following commands.
# systemctl restart mysql apache2 # systemctl status mysql apache2
Step 2: Download and Prepare Cacti Installation
9. Start install Cacti from sources by downloading and extracting the latest version of Cacti archive and copy all the extract files to Apache web document root, by issuing the following commands.
# wget https://www.cacti.net/downloads/cacti-latest.tar.gz # tar xfz cacti-latest.tar.gz # cp -rf cacti-1.1.27/* /var/www/html/
10. Remove index.html file from /var/www/html directory, create the Cacti log file and grant Apache with write permissions to web root path.
# rm /var/www/html/index.html # touch /var/www/html/log/cacti.log # chown -R www-data:www-data /var/www/html/
11. Next, edit cacti configuration file and modify the following lines as shown in the below example.
# nano /var/www/html/include/config.php
Cacti config.php file sample. Replace cacti database name, user and password accordingly.
$database_type = 'mysql'; $database_default = 'cacti'; $database_hostname = 'localhost'; $database_username = 'cactiuser'; $database_password = 'password1; $database_port = '3306'; $database_ssl = false; $url_path = '/';
12. Next, populate cacti database with the cacti.sql script from /var/www/html/ directory by issuing the below command.
# mysql -u cactiuser cacti -p < /var/www/html/cacti.sql
13. Now install some additional resources, as Cacti engine collects devices data via the SNMP protocol and displays graphics by using RRDtool. Install all of them by issuing following command.
# apt install snmp snmpd snmp-mibs-downloader rrdtool
14. Verify if SNMP service is up and running by restarting snmpd daemon by issuing the below command. Also check the snmpd daemon status and its open ports.
# systemctl restart snmpd.service # systemctl status snmpd.service # ss -tulpn| grep snmp
Step 3: Download and Install Cacti-Spine
15. Cacti-Spine is a C written replacement for the default cmd.php poller. Cacti-Spine provides a faster execution time. To compile Cacti-Spine pooler from sources install the below required dependencies in your system.
---------------- On Debian 9 ---------------- # apt install build-essential dos2unix dh-autoreconf help2man libssl-dev libmysql++-dev librrds-perl libsnmp-dev libmariadb-dev libmariadbclient-dev ---------------- On Ubuntu ---------------- # apt install build-essential dos2unix dh-autoreconf help2man libssl-dev libmysql++-dev librrds-perl libsnmp-dev libmysqlclient-dev libmysqld-dev
16. After you’ve installed the above dependencies, download the latest version of Cacti-Spine archive, extract the tarball and compile cacti-spine by issuing the following series of commands.
# wget https://www.cacti.net/downloads/spine/cacti-spine-latest.tar.gz # tar xfz cacti-spine-latest.tar.gz # cd cacti-spine-1.1.27/
17. Compile and install Cacti-Spine from sources by issuing the following commands.
# ./bootstrap # ./configure # make # make install
18. Next, make sure spine binary is owned by root account and set the suid bit for the spine utility by running the following commands.
# chown root:root /usr/local/spine/bin/spine # chmod +s /usr/local/spine/bin/spine
19. Now, edit Cacti Spine configuration file and add the cacti database name, user and password to the Spine conf file as illustrated in the below example.
# nano /usr/local/spine/etc/spine.conf
Add following configuration to spine.conf file.
DB_Host localhost DB_Database cacti DB_User cactiuser DB_Pass password1 DB_Port 3306 DB_PreG 0
Step 4: Cacti Installation Wizard Setup
20. To install Cacti, open a browser and navigate to your system IP address or domain name at the following URL.
http://your_IP/install
First, check Acept License Agreement and hit on the Next button to continue.
21. Next, check if system requirements and hit Next button to continue.
22. In the next window, select New Primary Server and hit on Next button to continue.
23. Next, verify critical binary locations and versions and change Spine binary path to /usr/local/spine/bin/spine. When you finish, hit Next button to continue.
24. Next, check if all web server directory permissions are in place (write permissions are set) and hit on Nextbutton to continue.
25. On the next step check all the templates and hit on Finish button in order to finish the installation process.
26. Log in to Cacti web interface with the default credentials shown below and change the admin password, as illustrated in the following screenshots.
Username: admin Password: admin
27. Next, go to Console -> Configuration -> Settings -> Poller and change the Poller Type from cmd.php to Spinebinary and scroll down to Save button to save the configuration.
28. Then, go to Console -> Configuration -> Settings -> Paths and add the following path to Cacti-Spineconfiguration file:
/usr/local/spine/etc/spine.conf
Hit on Save button to apply configuration.
29. The final setup which enables Cacti poller to start collecting data from monitored devices is to add a new crontab task in order to query each device via SNMP every 5 minutes.
The crontab job must be owned by www-data account.
# crontab -u www-data -e
Add Cron file entry:
*/5 * * * * /usr/bin/php /var/www/html/poller.php
30. Wait a few minutes for Cacti to collect data and go to the Graphs -> Default Tree and you should see the graphs collected for your monitored devices.
That’s all! You have successfully installed and configured Cacti with Cacti-Spine pooler, from sources, in the latest release of Debian 9 and Ubuntu 16.04 LTS server.