Install Cacti on CentOS 7 with LAMP Stack and SNMP
Cacti is a no-cost, open source solution for network monitoring and data visualization, developed using PHP. By leveraging RRDtool (Round-Robin Database Tool), Cacti offers various capabilities, including the use of both local and remote data collectors, template-based graph generation, automated network scanning, and streamlined device administration.
Requirements
- A new CentOS 7 x64 server instance, for example with the IP address
203.0.113.1
. - A user account with sudo privileges.
- The system must be updated to the latest stable state, utilizing the EPEL YUM repository.
Step 1: Prepare a Current LAMP Stack
Before deploying Cacti, you must install a working LAMP environment or an equivalent web stack.
Follow the instructions below to set up a modern LAMP configuration with CentOS 7, Apache 2.4, MariaDB 10.2, and PHP 7.1
Install Apache 2.4
sudo yum install httpd -y
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Install MariaDB 10.2
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo yum install MariaDB-server MariaDB-client -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
Secure the MariaDB Installation
sudo /usr/bin/mysql_secure_installation
When prompted, provide the following responses:
- Enter current password for root (enter for none): Press Enter
- Set root password? [Y/n]: Y
- New password: your-MariaDB-root-password
- Re-enter new password: your-MariaDB-root-password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Create a Database for Cacti
mysql -u root -p
CREATE DATABASE cacti;
CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
Note: For enhanced security, change the default values “cacti”, “cactiuser”, and “yourpassword” to your own secure credentials.
Install PHP 7.1 and Required Extensions
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y mod_php71w php71w-process php71w-common php71w-pdo php71w-xml php71w-ldap php71w-mbstring php71w-gd php71w-snmp php71w-mysqlnd php71w-cli php71w-mcrypt php71w-opcache php71w-imap php71w-intl
sudo cp /etc/php.ini /etc/php.ini.bak
sudo sed -i 's#;date.timezone =#date.timezone = America/Los_Angeles#' /etc/php.ini
Open HTTP Service in the Firewall
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
Step 2: Install Additional Dependencies
Beyond setting up the LAMP stack, Cacti also requires a few additional tools. Install them as shown below.
sudo yum install -y net-snmp net-snmp-utils rrdtool
sudo systemctl start snmpd.service
sudo systemctl enable snmpd.service
Step 3: Prepare Cacti Files and Database
Begin by downloading and extracting the archive for Cacti version 1.1.
cd
wget http://www.cacti.net/downloads/cacti-1.1.20.tar.gz
tar -zxvf cacti-1.1.20.tar.gz
Move the unpacked Cacti directory to the desired location, create the required log file, and set appropriate ownership and permissions.
sudo mv ~/cacti-1.1.20 /opt
sudo ln -s /opt/cacti-1.1.20 /var/www/html/cacti
sudo touch /opt/cacti-1.1.20/log/cacti.log
sudo chown -R apache:apache /opt/cacti-1.1.20
Import timezone details and preload the Cacti SQL data into your MariaDB database.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql -u root -p cacti < /var/www/html/cacti/cacti.sql
mysql -u root -p
Within the MySQL shell, apply the following privileges and exit:
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;
EXIT;
Configure Cacti Settings
Edit the Cacti configuration file using the vi
text editor:
sudo vi /var/www/html/cacti/include/config.php
Verify that the following values are configured correctly:
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'yourpassword';
$database_port = '3306';
$database_ssl = false;
$url_path = '/cacti/';
After making adjustments, save and exit the editor:
:wq!
Configure Cron for Cacti Poller
To schedule Cacti’s poller execution, create a cron job for the Apache user:
sudo crontab -u apache -e
Add the following line to the file:
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
Save and quit with:
:wq!
Step 4: Configure Apache Virtual Host for Cacti
To allow Apache to serve Cacti, define a dedicated virtual host configuration.
Note: Replace the placeholders for ServerAdmin
, ServerName
, and ServerAlias
with your actual server details.
cat <
ServerAdmin admin@example.com
DocumentRoot /var/www/html/
ServerName cacti.example.com
ServerAlias www.cacti.example.com
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
ErrorLog /var/log/httpd/cacti.example.com-error_log
CustomLog /var/log/httpd/cacti.example.com-access_log common
EOF
Restart Apache to apply all configuration changes:
sudo systemctl restart httpd.service
Step 5: Tune MariaDB Configuration
To enhance Cacti’s performance, adjust your MariaDB settings with recommended parameters.
Start by backing up the original configuration file and then open it in vi
:
sudo cp /etc/my.cnf /etc/my.cnf.bak
sudo vi /etc/my.cnf
Locate the [client-server]
section or appropriate place, and append the following configuration:
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server=utf8mb4_unicode_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
max_heap_table_size=64M
tmp_table_size=80M
join_buffer_size=80M
innodb_buffer_pool_size=256M
innodb_doublewrite=OFF
innodb_flush_log_at_timeout=3
innodb_read_io_threads=32
innodb_write_io_threads=16
Save and exit:
:wq!
Apply the changes by restarting the MariaDB service:
sudo systemctl restart mariadb.service
Step 6: Finalize the Cacti Installation via Web Interface
Open your preferred web browser and visit http://203.0.113.1/cacti
. This will launch the Cacti Installation Wizard interface.
On the License Agreement screen, select the option to accept the GPL License Agreement. Proceed by clicking the Next button.
During the Pre-installation Checks, confirm that all required conditions are met. Click Next to continue.
On the Installation Type screen, select New Primary Server and then hit Next.
When you arrive at the Critical Binary Locations and Versions screen, you may disregard the error regarding the Spine Binary File Location, as Spine has not been installed. Click Next again.
On the Directory Permission Checks screen, ensure that all listed folders have write permissions. Click Next to proceed.
In the Template Setup section, choose Local Linux Machine and click Finish to wrap up the installation and access the login page.
At the User Login screen, use the default credentials: username admin
and password admin
.
Upon successful login, the system will prompt you to change your password. Be sure to choose a secure password that meets all specified requirements.
That completes the installation and configuration of Cacti. As a next step, remember to configure RRDtool correctly so Cacti can collect the data it needs for graphing.
Conclusion
You have now completed the full installation and setup process for Cacti on a CentOS 7 server. From preparing the LAMP environment and configuring MariaDB to running the web-based installation wizard, your system is now ready for network monitoring. With Cacti fully operational, you can proceed to integrate RRDtool and additional monitoring configurations to visualize your infrastructure effectively.