Saturday, December 28, 2024
Google search engine
HomeGuest BlogsInstall Cacti Monitoring Server on Debian 11 / Debian 10

Install Cacti Monitoring Server on Debian 11 / Debian 10

In this guide, you’ll learn to Install Cacti on Debian 11 / Debian 10 with Nginx reverse proxy. Cacti is a complete network graphing solution designed to harness the power of RRDTool’s data storage and graphing functionality. Cacti offer fast polling, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with thousands of devices.

Follow the following steps to get Cacti running in Debian 11 / Debian 10

Step 1: Install Required Packages

There are dependency packages required for the installation. Ensure they are installed.

sudo apt update
sudo apt install software-properties-common
sudo apt install nginx

Debian 11:

sudo apt install curl vim acl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full python3-memcache python3-mysqldb snmp snmpd whois php-snmp rrdtool librrds-perl

Debian 10:

sudo apt install curl vim acl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full python-memcache python-mysqldb snmp snmpd whois php-snmp rrdtool librrds-perl

Step 2: Install PHP on Debian

Run the following commands on your Debian terminal to install PHP.

sudo apt -y install php php-common

Add PHP Extensions

sudo apt -y install php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath php-gmp php-ldap

Step 3: Database Configuration for Cacti

We installed MariaDB in step 1. Let us proceed to create a database for Cacti.

Login to your DataBase

sudo systemctl enable mysql
sudo systemctl restart mysql
sudo mysql -u root -p

Create Database and cacti user

The default Cacti database data we will import later uses a database named cacti. So it will be prudent to create a database with that name to make your work easier.

CREATE DATABASE cacti;
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'SafePassWord'; ## Make it strong
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';
FLUSH PRIVILEGES;
EXIT

Grant database user access to the MySQL TimeZone database and select permission

Cacti database login account (cactiuser in this example) must have access to the MySQL TimeZone database. Provide the Cacti database account “select” access to the “time_zone_name” table in the “mysql” database, and populate MySQL’s TimeZone information before proceeding.

sudo mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql

After that, log in to MariaDB.

sudo mysql -u root -p

Grant the permission to your user e.g cactiuser in this example

GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
ALTER DATABASE cacti CHARACTER SET = 'utf8mb4'  COLLATE = 'utf8mb4_unicode_ci';
flush privileges;
exit

Open MariaDB file and add the lines below under [mysqld] section for an optimized database

sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf

Add the following under [mysqld]

[mysqld]
collation-server = utf8mb4_unicode_ci
character-set-server  = utf8mb4
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 = 1GB
innodb_buffer_pool_instances = 10
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

Run the following command to restart mysql database service:

sudo systemctl restart mysql

Step 4: Configure PHP-FPM for Cacti use

Let us ensure date.timezone is set in php.ini to a preferred time zone.

sudo vim /etc/php/*/fpm/php.ini

Under [Date] uncoment the date.timezone line and add your timezone.

date.timezone = Africa/Nairobi ## Input your Time zone
max_execution_time = 300       ## Increase max_execution_time
memory_limit = 512M            ## Increase memory limit

Also modify below file to set timezone and increase php script maximum execution time.

$ sudo vim /etc/php/*/cli/php.ini
date.timezone = Africa/Nairobi  ## Input your Time zone
max_execution_time = 300        ## Increase max_execution_time
memory_limit = 512M             ## Increase memory limit

Update the address in which FPM will accept FastCGI requests.

$ sudo vim /etc/php/*/fpm/pool.d/www.conf
listen = /run/php/php-fpm.sock

Restart PHP-FPM

Restart php fpm service:

sudo systemctl restart php*-fpm.service

Step 5: Configure Nginx Webserver

Since we chose Nginx as our preferred web server, it is time to add configurations so that we can serve our Cacti pages.

Delete the default page that loads up after fresh installation of Nginx

sudo rm /etc/nginx/sites-enabled/default

Create a file as shown and add the following in it

sudo vim /etc/nginx/conf.d/cacticonfig.conf

Paste and modify below data.

server {
 listen      80;
 server_name cacti.example.com;
 root        /var/www/html;
 index       index.php;
 access_log  /var/log/nginx/cacti_access.log;
 error_log   /var/log/nginx/cacti_error.log;
 charset utf-8;
 gzip on;
 gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
 location / {
   try_files $uri $uri/ /index.php?$query_string;
  }
  location /api/v0 {
   try_files $uri $uri/ /api_v0.php?$query_string;
  }
  location ~ .php {
   include fastcgi.conf;
   fastcgi_split_path_info ^(.+.php)(/.+)$;
   fastcgi_pass unix:/run/php/php-fpm.sock;
  }
  location ~ /.ht {
   deny all;
  }
 }

Restart Nginx

sudo systemctl restart nginx

Step 6: Install Cacti server on Debian 11 / Debian 10

We will now need to download the latest version of Cacti package.

# Download using curl
curl -sLO https://www.cacti.net/downloads/cacti-latest.tar.gz

# Download using wget
wget https://www.cacti.net/downloads/cacti-latest.tar.gz

After it is done downloading, extract the Cacti archive

tar -zxvf cacti-latest.tar.gz

Move the files to our web root directory and change the name of the directory

sudo mv cacti-1* /var/www/html/
sudo mv /var/www/html/cacti-*/ /var/www/html/cacti

Change ownership for the cacti files

sudo chown -R www-data:www-data /var/www/html/

Import the default Cacti database data to the Cacti database.

sudo mysql -u root -p cacti < /var/www/html/cacti/cacti.sql

Open the Cacti configuration file to input database information.

$ sudo vim /var/www/html/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "SafePassWord"; 
$database_port = "3306";
$database_ssl = false;

Validate nginx configurations syntax:

$ sudo nginx  -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

After you are done with the configuration, restart the webserver.

sudo systemctl restart nginx

Step 7: Edit the crontab file.

In order for Cacti to poll every few minutes, you may need to add the following in your crontab

$ sudo vim /etc/cron.d/cacti
*/5 * * * * www-data php /var/www/html/cacti/poller.php > /dev/null 2>&1

That will cause Cacti to poll every five minutes.

Step 8: Open Cacti Web installer

Now head to the web installer and follow the on-screen instructions.

http:// IP or FQDN /cacti

That should load the installer similar to the one below. Enter default username and password which is admin and admin

Change the default password. Input a long password with mixed characters with one upper and lower case as well as special characters.

Accept License Agreement and click “Begin

cacti accept license 3

I prefer dark mode by all means, so I had to change the default theme. You do not have to do the same if you prefer the default one. Click “Begin” to start the installation.

cacti accept license change to dark 3

It is going to check if the PHP and MySQL configurations we made meet the requirements it needs. Click “Next” if everything gives a green thumbs up.

cacti pre installation check 4

Choose the installation type you want. Primary server it is for this example. Click “Next” thereafter.

cacti installation type 5

Directory permission checks. Click “Next

cacti directory permissions 6

It will suggest the directories where its critical binary files will be placed. Simply click on “Next

cacti binary checks 7

Read the statement carefully and check the radio button after you have understood it. This is important because it touches on the security of your server. Click “Next” thereafter.

cacti whitelist protection statement 8

Choose default profile for poller and network details

cacti default profile 9

Setup the templates you need and click “Next” to proceed forward

cacti template setup 10

The wizard will do configuration checks. After it is done, click “Next

cacti server collation 11

Confirm installation by checking the radio button then click “Install” to begin the installation process.

cacti confirm installation 12

Give it time to complete installing

cacti final installation 13

After it is done, refresh your page and you should be presented with the login page. Input admin and the new password you created.

cacti login 14

And here we are!

Conclusion

It is now time to add your devices and configure Cacti to start monitoring them. There is much more do after you have your server running. Some of them is provided in How to Import templates on Cacti. We hope the guide was informative and helpful. Thank you for visiting.

More guides for you :

How To Install Cacti on RHEL 8 / CentOS 8

How to Install and Configure Cacti on Ubuntu

Install and Configure Nagios 4 on RHEL 8 / CentOS 8

How To Install Zabbix Server on CentOS 8 / RHEL 8

Install and configure LibreNMS on Debian with Nginx

RELATED ARTICLES

Most Popular

Recent Comments