Tuesday, May 22, 2007

Moving Cacti from one Linux server to another

I had to move Cacti now three times in the past year from one server to another. This process is not a part of the standard Cacti documentation, so you have to go hunting. Here is what I found to be the best process. Well, at least a working process. Many of these specifics are due to our Centos 4.4 kickstart install, i.e. SELinux, etc...

New Server:
1. Insure that MySQL is up and running. Mine wasn't due to SELINUX. I also needed the MySQL client.

yum install MySQL-client-standard
yum install perl-DBD-MySQL
service MySQL start
failed
service mysql restart
failed
vi /etc/my.cnf
(comment out the basedir option
#basedir=/var/lib
service mysql restart
failed
system-config-securitylevel
change permissions to allows mysql
service mysql restart
ok.


2. Download the source rpm or use the one you already have. Rebuild it on the new server and then install it.

rpmbuild --rebuild cacti-0.8.6j-1.src.rpm
rpm -Uvh /usr/src/redhat/RPMS/i386/cacti-*
oops, need other packages
yum install php-mysql php-snmp rrdtool
rpm -Uvh /usr/src/redhat/RPMS/i386/cacti-*
oops, need rrdtool and perl-rrdtool
rpm -Uvh perl-rrdtool-1.2.15-1.el4.rf.i386.rpm rrdtool-1.2.15-1.el4.rf.i386.rpm
rpm -Uvh /usr/src/redhat/RPMS/i386/cacti-*
ok.


Old Server:
1. Stop Cacti from running by removing or moving the crontab job from /etc/cron.d. I just moved it to root's home area in case I need it again.
2. Backup the cacti database:
mysqldump -u root -p cacti > cacti_export.sql (-u username -p prompt me for the password database_name > sql file)
3. Copy the cacti_export.sql file to the new server.
4. Copy the rra, scripts, and any other modified files to the corresponding directory on the new server.
scp -r /var/www/cacti/rra/* root@violet:/var/www/html/cacti/rra/
...That's right, violet lives again.

New Server:

1. Create the cacti databases, import old database, and set appropriate permissions.

mysqladmin --user=root create cacti
mysql -u root -p cacti < /root/cacti_export.sql mysql -u root -p cacti mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'the password of cactiuser';
mysql> flush privileges;
mysql> quit;


2. Verify the permissions are set correctly on the rra/ and log/ directories in cacti's home area.
chown -R cactiuser:cactiuser rra/ log/
It never hurts to make sure, especially after you have copied files from another server.

3. I then go to the log/ directory and tail -f the cacti.log and watch for the next crontab job to run and hopefully see good results.

I think that is all I had to do, but this is the best I can remember. If you have SNMP access lists on your devices or any firewall rules in your path, always make sure to change them to reflect the new server.

EXTRAS:

I install the cacti plugin architecture, www.cactiusers.org, primarily the thold plugin. The steps are easy to follow, so I leave you to follow their documentation.

Matthew

4 comments:

Brad Martin said...

Sweet. I am sure I will be coming back to this one when I have to rebuild my Linux server. I was wondering how I could keep all my existing Cacti data. Great job Brown-daddy.

Colin said...

Excellent article, and still valid. Thank you so much for posting.
Colin

Unknown said...

Its really nice and helping post

Anonymous said...

Still valid, 3 years hence... (Centos 5)