Here at computingforgeeks, we like exploring various network and system monitoring tools. So far we have covered the basic setup and usage of Zabbix, telegraf/Influxdb, Grafana, and Prometheus. Zabbix functionality is similar to Cacti, though Cacti is more fit for network graphing. In this guide, we’ll look at how to install cacti server on Ubuntu 18.04.
What is Cacti?
Cacti is a completely open-source network monitoring and graphing tool that was designed as a front-end application for the industry-standard data logging tool RRDtool. Cacti harness the power of RRDTool’s data storage and graphing functionality. Some good features of Cacti include:
- Fast polling of metrics
- Support for multiple data acquisition methods
- Support for advanced graph templating
- User management functionality with ACL
Cacti provide an intuitive and easy to use web interface which can be used for small LAN installations up to complex networks with thousands of servers and networking devices.
How to Install Cacti Server on Ubuntu 18.04
Cacti has a number of dependencies that need to be installed and configured before you can deploy Cacti server itself. This guide will cover installation of these dependencies one by one:
Step 1: Update system and upgrade all packages
We always start with server packages upgrade to avoid any dependency issues:
$ sudo apt-get update $ sudo apt-get upgrade
Step 2: Install php and required modules
We now need to install php and some php modules required by cacti. Run the following commands to get everything and installed.
$ sudo apt-get -y install php php-mysql php-curl php-net-socket \ php-gd php-intl php-pear php-imap php-memcache libapache2-mod-php \ php-pspell php-recode php-tidy php-xmlrpc php-snmp \ php-mbstring php-gettext php-gmp php-json php-xml php-common
The most important module is php-snmp and php-mysql. Make sure they are installed. You can check your php version using the command:
# php -v PHP 7.2.5-0ubuntu0.18.04.1 (cli) (built: May 9 2018 17:21:02) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.5-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
Ensure you set correct timezone:
# grep date.timezone /etc/php/7.2/apache2/php.ini ; http://php.net/date.timezone date.timezone = "Africa/Nairobi"
Step 3: Install Apache Web server
The default recommended web server for Cacti is Apache, install it using the commands:
$ sudo apt-get -y install apache2
After installing Apache, configure basic security by allowing Prod ServerTokens only.
$ sudo vim /etc/apache2/conf-enabled/security.conf
Change line 25
This directive configures what you return as the Server HTTP response. Valid options are Full | OS | Minimal | Minor | Major | Prod.
# grep ServerName /etc/apache2/apache2.conf ServerName cacti.computingforgeeks.com
Set Server Admin to receive an email in case of issues.
# grep ServerAdmin /etc/apache2/apache2.conf ServerAdmin firstname.lastname@example.org
If you have ufw enabled, open http and https ports on the firewall.
# ufw allow http Rule added Rule added (v6 # ufw allow https Rule added Rule added (v6)
You need to restart apache web service after making these changes:
$ sudo systemctl restart apache2
Step 3: Install MariaDB server
For the installation of MariaDB on Ubuntu, use my previous guide:
Tune MariaDB database for Cacti
Add the following settings under[mysqld] on the file /etc/mysql/mariadb.conf.d/50-server.cnf
max_heap_table_size=128M tmp_table_size=128M join_buffer_size=64M innodb_buffer_pool_size=512M innodb_doublewrite=OFF innodb_additional_mem_pool_size=128M innodb_flush_log_at_timeout=3 innodb_read_io_threads=32 innodb_write_io_threads=16
Restart mariadb service
$ sudo systemctl restart mariadb
To check any of these settings, use mysql select statement, e.g.
MariaDB [(none)]> select @@tmp_table_size; +------------------+ | @@tmp_table_size | +------------------+ | 134217728 | +------------------+ 1 row in set (0.00 sec)
MariaDB [(none)]> show variables like 'join_buffer_size';
Once Database server installation is done, you need to create a database for Cacti:
$ mysql -u root -p Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 56 Server version: 10.3.7-MariaDB-1:10.3.7+maria~bionic-log mariadb.org binary distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database cacti; Query OK, 1 row affected (0.000 sec) MariaDB [(none)]> grant all privileges on cacti.* to cacti_user@'localhost' identified by 'strongpassword'; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> exit Bye
Test database connection:
$ mysql -u cacti_user -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 178 Server version: 10.1.29-MariaDB-6 Ubuntu 18.04 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | cacti | | information_schema | +--------------------+ 2 rows in set (0.00 sec) MariaDB [(none)]>
Step 4: Install SNMP and Cacti
The last package installation step is for Cacti and snmp packages. Cacti depend on Snmp and rrdtool tool for its functions. Install these packages using the command:
sudo apt-get install snmp snmpd snmp-mibs-downloader rrdtool cacti cacti-spine
When asked to select web server, choose apache.
+-------------------------+ Configuring cacti +--------------------------+ | Please select the web server for which Cacti should be automatically | | configured. | | | | Select "None" if you would like to configure the web server manually. | | | | Web server: | | | | apache2 | | lighttpd | | None | | | | | | <Ok> | | | +------------------------------------------------------------------------+
For Database configuration, select no for manual configuration since we have created a database for cacti on
+---------------------------+ Configuring cacti +---------------------------+ | | | The cacti package must have a database installed and configured before | | it can be used. This can be optionally handled with dbconfig-common. | | | | If you are an advanced database administrator and know that you want to | | perform this configuration manually, or if your database has already | | been installed and configured, you should refuse this option. Details | | on what needs to be done should most likely be provided in | | /usr/share/doc/cacti. | | | | Otherwise, you should probably choose this option. | | | | Configure database for cacti with dbconfig-common? | | | | <Yes> <No> | | | +---------------------------------------------------------------------------+
Wait for the installation to finish then proceed to configure SNMP.
Step 5: Configure SNMP
Start by enabling loading of MIBs by commenting out the following line on /etc/snmp/snmp.conf
# mibs :
Configure SNMP community name by editing /etc/snmp/snmpd.conf
# On line 49 - Uncomment and change to the name of community string to any name you like. # This enable full access from localhost rocommunity Computingforgeeks localhost
Diable public access by commenting below lines:
rocommunity public default -V systemonly rocommunity6 public default -V systemonly
# rocommunity public default -V systemonly # rocommunity6 public default -V systemonly
Restart snmpd service
$ sudo systemctl restart snmpd
Validate snmp configurations using snmpwalk command line tool:
Remember to replace Computingforgeeks with the name of your community string.
Step 6: Configure Cacti Server
From here, we have to configure database settings for Cacti and initiate setup on the web interface. Change db settings on the file /usr/share/cacti/site/include/config.php.
# On line 49 - Change cacti database connection info $database_type = "mysqli"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti_user"; $database_password = "strongpassword"; $database_port = "3306"; $database_ssl = false;
Replace cacti_user with database user you created on Step 3 and strongpassword with cacti database user password.
Import cacti Mysql database schema:
$ mysql -u cacti_user -p cacti < /usr/share/doc/cacti/cacti.sql Enter password:
Replace cacti_user with database user and cacti with the database name.
Setup mysql timezone for cacti database user
# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql Enter password: Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Grant cacti MySQL database user access to TimeZone database:
# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 202 Server version: 10.1.29-MariaDB-6 Ubuntu 18.04 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cacti_user@localhost; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye
Configure Cacti apache site Access control (Optional) :
If you would like to restrict access to Cacti Web interface, edit the file /etc/apache2/conf-available/cacti.conf and comment out the line:
Require all granted
Then configure as below:
# Change line 7 #Require all granted Require host localhost Require ip 192.168.1.0/24
Replace 192.168.1.0/24 with your trusted subnet. You can also add a single IP like below:
Require ip 192.168.1.20 Require ip 172.16.20.30
You need to restart apache service after making above modifications,
$ sudo systemctl restart apache2
Step 7: Start Initial Cacti Setup
Open your favorite web browser and navigate to “http://(Cacti server’s hostname or IP address)/cacti/” from a client system authorized on Cacti server.
Click Next button to go to the next stage.
You will be asked to select server installation type:
- New Primary Server – Choose this for the Primary site.
- New Remote Poller – Remote Pollers are used to access networks that are not readily accessible to the Primary site.
Since this is our first server, Choose “New Primary Server” then click Next
Confirm that all binaries all located and click Next.
You are now on the final stage, finish the installation by clicking the Finish button to get the login page.
The default logins are:
username: admin Password: admin
Step 8: Monitor Local Cacti Server
Add the local Cacti server for monitoring. Login to Cacti as admin user and go to:
Fill server details and scroll down and click “Save” button.