Install Cacti on RockyLinux 8 system
Step 1 – Prerequisites
First we need to install some of the software packages needed for Cacti to run properly. Using a minimal installation, we need to install the following repositories and packages
- epel and remi repository
- PHP and modules
- gcc, net-snmp and dev packages for spine installation
In order to use python for scripting purposes ( or ansible), we are also going to install it as well.
Let’s proceed with the package installation on our RockyLinux 8 system. First we will enable the required EPEL ad REMI repositories:
dnf install -y epel-release dnf install -y dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm sudo dnf -y module reset php sudo dnf -y module enable php:remi-8.0 sudo dnf config-manager --set-enabled powertools
Now we can proceed with installing the packages:
dnf -y install mariadb-server php php-mysqlnd php-cli net-snmp-utils rrdtool gcc mariadb-devel dnf -y install net-snmp-devel autoconf automake libtool dos2unix wget php-posix php-ldap php-mbstring php-gd dnf -y install php-gmp php-zip php-json php-xml php-gettext php-curl php-intl help2man dnf -y install net-snmp net-snmp-devel net-snmp-utils
Now let’s install git and python, and also make sure we have the setuptool-rust installed in case we want to run ansible. Lastly we also install some tools to manage SELinux:
dnf -y install git python3-pip python3-devel python3-dnf dnf -y install policycoreutils-gui sudo pip3 install setuptools-rust sudo pip3 install --upgrade pip
In order to have all packages up-to-date, let’s do a quick upgrade on our system as well:
dnf -y upgrade
The above completes the specifics for the install Cacti on RockyLinux 8. Most of the tasks below are valid for a CentOS7/RHEL7 instalaltion as well.
In the next step, we will make sure that our webserver and the database are automatically starting up after a reboot. In order to do this, use the following commands to enable these:
systemctl enable httpd.service systemctl enable mariadb.service systemctl restart mariadb.service
Now that we have the database server started, we need to populate it with the timezone data:
# Create the timezone data and import it into the mysqldatabase mysql_tzinfo_to_sql /usr/share/zoneinfo > /tmp/mysql_timezone.sql mysql mysql < /tmp/mysql_timezone.sql
Next, we need to change some settings for the mariadb server. These will make sure that spine and Cacti are utilizing the database connection in an optimal way. The following settings are for a 1GB memory system.
Don’t worry, Cacti will provide you with some recommended settings for your system during the installation process.
So, let’s edit the /etc/my.cnf.d/mariadb-server.cnf file and add the following lines to the [mysqld] section:
max_heap_table_size=90M max_allowed_packet=16M tmp_table_size=64M join_buffer_size=64M innodb_file_per_table=ON innodb_buffer_pool_instances=3 innodb_buffer_pool_size=256M innodb_doublewrite=OFF innodb_lock_wait_timeout=50 innodb_flush_log_at_trx_commit=2 character_set_server=utf8mb4 character_set_client=utf8mb4 collation_server=utf8mb4_unicode_ci default-time-zone='Europe/Berlin' 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 innodb_file_format=Barracuda innodb_large_prefix=1
Make sure to adapt the default-time-zone to your requirements
Next, we need to restart the web-server as well as the Maria DB service in order to continue the installation:
systemctl restart httpd.service systemctl restart mariadb.service
Step 2 – Cacti Files
Let’s now move to the actualy installation of Cacti. First we need to download and extract it. As of this writing the current Cacti Version is 1.2.22.
cd /var/www/html wget http://www.cacti.net/downloads/cacti-latest.tar.gz tar -xzvf cacti-latest.tar.gz
Let’s now rename the cacti directory:
mv cacti-1.2.23 cacti
Step 3 – File permissions
We also need to make sure that the ownership of the required cacti directory is set correctly:
chown -R apache.apache /var/www/html/cacti/rra chown -R apache.apache /var/www/html/cacti/log chown -R apache.apache /var/www/html/cacti/resource/snmp_queries/ chown -R apache.apache /var/www/html/cacti/resource/script_server/ chown -R apache.apache /var/www/html/cacti/resource/script_queries/ chown -R apache.apache /var/www/html/cacti/scripts/ chown -R apache.apache /var/www/html/cacti/cache chown -R apache.apache /var/www/html/cacti/include/vendor/csrf chmod -R 775 /var/www/html/cacti/cache chmod -R 775 /var/www/html/cacti/resource chmod -R 775 /var/www/html/cacti/scripts chmod -R 775 /var/www/html/cacti/include/vendor/csrf
Step 4 – Cacti Database
Now that we have extracted the cacti files, we can move on preparing the database for the final installation step. Your first step should be securing the mysql database. The following command will help you with this task on a CentOS system. Make sure to select a strong password for root, e.g. MyN3wpassw0rd
Let’s create a new database and assign a special user to it:
mysqladmin -u root -p create cacti mysql -p cacti < /var/www/html/cacti/cacti.sql mysql -u root -p
With the last command, you should be seeing a mysql prompt where you can enter mysql commands. Here we are going to create the special cacti user. That user only needs to be able to connect from the local system and should have a strong password as well. Enter the following commands and make sure to replace the password:
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost IDENTIFIED BY 'MyV3ryStr0ngPassword'; GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'MyV3ryStr0ngPassword'; flush privileges; exit
We now have the cacti files and the cacti database setup. The last step before moving to the web-based installer is setting the database credentials within the Cacti config file:
cd /var/www/html/cacti/include/ vi config.php
Change the $database_ lines to fit your new settings:
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "MyV3ryStr0ngPassword"; $database_port = "3306"; $database_ssl = false;
Depending on your installation, you should also uncomment the following line. In our example we have to make sure the following line is there:
$url_path = "/cacti/";
Step 5 – Adding firewall rules
The following settings will enable the firewall and add access rules to http and https from outside:
systemctl enable firewalld systemctl start firewalld firewall-cmd --permanent --zone=public --add-service=https firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
Step 6 – Important PHP Settings
The default PHP installation usually has not configured the correct timezone or php error reporting. While not required to run Cacti, it’s highly recommended to enable error reporting to syslog for troubleshooting issues with plugins or other scripts.
The following lines need to be enabled/configued in your /etc/php.ini file:
; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Europe/Berlin
; Log errors to syslog (Event Log on NT, not valid in Windows 95). error_log = syslog
and also increase the memory limit and max execution time:
memory_limit = 400M max_execution_time = 60
Let’s restart the HTTP and PHP-FPM services
systemctl restart httpd.service systemctl restart php-fpm
Step 7 – Set SELinux Context for http directory
SELinux does interfere with the installation, so let’s disable it for now. :
sudo chcon -R -t httpd_sys_rw_content_t /var/www/html sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html(/.*)?"
Step 8 – Running the Web-based installer
Let’s move on to the web-based installer.
Login with admin/admin and you’re ready to go !
Please go to “Console -> System Utilities” and click on “Rebuild Poller Cache” after the first login!
Step 9 – Installing Spine
Now let us look into installing Spine as a replacement of the cmd.php poller.
The following task will download, compile and configure the spine poller:
## Install Spine cd /tmp wget https://files.cacti.net/spine/cacti-spine-latest.tar.gz tar -xzvf cacti-spine-latest.tar.gz cd cacti-spine-1.2.23 sudo ./bootstrap sudo ./configure sudo make sudo make install sudo chown root:root /usr/local/spine/bin/spine sudo chmod +s /usr/local/spine/bin/spine sudo cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf sudo sed -i "s/DB_Pass cactiuser/DB_Pass MyV3ryStr0ngPassword/ig" /usr/local/spine/etc/spine.conf
Step 10 – Remove File permissions
Now we can remove unnecessary file permissions again:
chmod -R 555 /var/www/html/cacti/resource chmod -R 555 /var/www/html/cacti/scripts chmod -R 550 /var/www/html/cacti/include/vendor/csrf
Step 11 – Cron Job
Cacti uses cron (scheduled task) to execute its polling process. It’s always a good idea to run this under a different user than root.
Let’s now add a new cron entry to your system for a 1-minute polling interval using the following command:
echo "*/1 * * * * apache php /var/www/html/cacti/poller.php &>/dev/null" >> /etc/cron.d/cacti
Need Commercial Support on how to install Cacti on RockyLinux 8 ?
Urban-Software.de offer commercial Cacti support not only for Cacti itself, but also for several of the plugins ( e.g. Thold ).
There’s going to be an on-demand solution in the future. You can contact us for more details using the contact form.
If you require free support, please visit the cacti forum !