Migrate Cacti to New Server CentOS 6

Migrate Cacti to New Server CentOS 6

This blog is basic, and only has the steps that need to be taken, but does not fully walk you through the process, we just wanted to get it noted somewhere. Below each step there is now a short explanation of what it does and the commands we would normally use, so you can follow it end to end.

A Cacti installation is made of three parts: the PHP web application, the MySQL database that holds devices, graphs, templates and users, and the RRD files that hold the actual collected data. A migration is simply moving all three to the new host and pointing the new install at the data.

Prerequisites

  • Root access to both the old and the new server.
  • The same Cacti version on the new server as on the old one, if possible. If the new one is newer, see the note under step 2.
  • Enough disk space on the new server for the RRD directory (check with du -sh on the old server).
  • A short maintenance window: graphs will have a gap for the time the poller is stopped.

1) Bring Up New Server

Install CentOS 6 (or whatever OS you are moving to), give it its final hostname and IP, and install Apache, PHP, MySQL, net-snmp and rrdtool. A full Cacti install walk-through is in Install Cacti RHEL/CentOS/Oracle/Alma/Rocky.

2) Re-Install Cacti on New Server (do not go through the web installer)

Install the Cacti package (on CentOS 6 it comes from EPEL), but do not run the web installer: it would create a fresh, empty database and you are about to bring over the existing one.

yum -y install cacti

If the new server ends up with a newer Cacti version than the old one, import the old database first (step 3) and then run the web installer, choosing the upgrade option, so the database schema is upgraded instead of replaced.

3) Migrate MySQL/Edit the config to point to your MySQL Server

Dump the Cacti database on the old server, copy it over and import it on the new one:

mysqldump -u root -p cacti > cacti.sql
scp cacti.sql root@newserver:/root/
mysql -u root -p -e "CREATE DATABASE cacti;"
mysql -u root -p cacti < /root/cacti.sql
mysql -u root -p -e "GRANT ALL ON cacti.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'yourpassword'; FLUSH PRIVILEGES;"

Then edit the Cacti database config (on the EPEL package it is /etc/cacti/db.php) so $database_hostname, $database_username and $database_password match. If you keep a separate MySQL server, just point $database_hostname at it instead of copying the database. For more on dumps and restores, see Backup MySQL on Linux.

4) Copy/Paste Plugins from the original folder (that way those don’t need to be re-configured)

The plugin code lives in the Cacti plugins directory, while its settings are already in the database you just imported. Copying the directory over means the plugins come back exactly as they were.

5) copy /var/lib/cacti/rrd/*.rrd files to new servers

Stop the poller on the old server first (comment out the line in /etc/cron.d/cacti) so the files are not being written while you copy them, then copy them across. Depending on how Cacti was installed, the directory may be named rra rather than rrd; use whatever path the old server uses.

rsync -av /var/lib/cacti/rrd/ root@newserver:/var/lib/cacti/rrd/

RRD files are not portable between 32-bit and 64-bit systems. If the architecture changes, export each file with rrdtool dump on the old server and load it with rrdtool restore on the new one.

6) chmod *.rrd cacti:cacti

The poller runs as the cacti user, so it has to own the files. The command that sets the owner is chown:

chown cacti:cacti /var/lib/cacti/rrd/*.rrd

7) Restart http, and mysql, and see if it works

service httpd restart
service mysqld restart

Then make sure the poller cron entry in /etc/cron.d/cacti is enabled on the new server, and only there.

Verify the migration

  • Log in to the web interface with your existing Cacti account; devices and graph trees should all be there.
  • After two or three poller runs (5 minutes each by default), the graphs should continue from where the old server stopped.
  • Check /var/log/cacti/cacti.log for poller errors.
  • If you monitor devices with SNMP, make sure their access lists allow the new server’s IP.

That’s it!

Troubleshooting

  • Graphs are blank or not updating: usually file ownership on the RRD files, a disabled poller cron job, or SNMP access lists that only allow the old IP.
  • Database connection error on the login page: check the credentials in db.php and the MySQL grants.
  • The web installer appears: the version in the database does not match the installed code; finish it as an upgrade, not a new install.

Newer releases

On RHEL, AlmaLinux and Rocky 8, 9 and 10, Cacti is installed from EPEL with dnf install cacti, the database is usually MariaDB, and services are restarted with systemctl restart httpd mariadb. The overall migration steps are the same.

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Install Cacti RHEL/CentOS/Oracle/Alma/Rocky | Configure Cacti OpenLDAP authentication

Leave a Reply

Your email address will not be published. Required fields are marked *