Script to install Cacti on CentOS 6 or Red Hat 6

By | 29 August 2011

I have installed Cacti several times and it is a somewhat tedious process on a new system so I thought I would just build a small bash script to perform the install for me. This script will install everything needed by Cacti including rrdtool so you will go from a blank system to a full Cacti install in only a few minutes. All you have to do is run this script as root and then open a browser and log into the Cacti server at http://ServerIP/cacti and follow the prompts. RRDtool is installed in /usr/local/rrdtool/bin/ so you will have to change that on the prerequisites page when you get to it. I used this blog to walk through the steps while I was creating the script. Here is the script:

# Cacti Install Script
# This script should work on all RHEL/CentOS 6.x systems but was built and tested
# on a CentOS 6 system installed with the minimal CD.
# By: Chris Adams
# Modify the password variables below to match what you want

CACTIVERSION=`wget -qO-| grep “latest version” | sed ‘s/<[^>]*>//g’ | awk ‘{print $NF}’`
SERVERS=(mysqld httpd ntpd)
OFFSERVERS=(iptables ip6tables)

# Centos Minimal needs these added
yum install httpd php php-mysql php-snmp php-xml mysql mysql-server \
cairo-devel libxml2-devel pango-devel pango libpng-devel freetype \
freetype-devel libart_lgpl-devel net-snmp-utils gcc wget man make \
perl-CPAN perl-ExtUtils-MakeMaker perl-ExtUtils-MakeMaker-Coverage \
crontabs xorg-x11-fonts-100dpi xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi \

#Disable SELinux and the local firewall
sed -i -e “s/^SELINUX\=enforcing/SELINUX\=disabled//” /etc/selinux/config
for i in ${OFFSERVERS[@]}; do
echo “Starting ${i}\n”
chkconfig ${i} off
service ${i} stop

#Turn onn and enable the needed servers to start at boot
for i in ${SERVERS[@]}; do
echo “Starting ${i}\n”
chkconfig ${i} on
service ${i} start

# Add teh fonts we installed to the font cache for Apache to use
fc-cache -vfs

# Download the latest rrdtool and store in /opt
cd /opt
tar -xzf rrdtool.tar.gz
cd rrdtool-$RRDVERSION
#Build and install rrdtool
./configure && make && make install
cd /usr/local
ln -s /opt/rrdtool-$RRDVERSION rrdtool

#Set Mysql password for root
mysqladmin –user=root password $MYSQLPASS
mysqladmin –user=root -p$MYSQLPASS reload

#Now on to the Cacti stuff
mkdir -p /var/www/html/cacti
cd /var/www/html/
tar -xzf cacti-$CACTIVERSION.tar.gz
mv cacti-$CACTIVERSION cacti
cd cacti
#Cacti SQL
echo “GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY ‘$CACTIPASS’;” > $CACTITMP
echo “flush privileges;” >> $CACTITMP
mysqladmin –user=root create cacti -p$MYSQLPASS
mysql -u root -p$MYSQLPASS cacti < cacti.sql
mysql -u root -p$MYSQLPASS cacti < $CACTITMP
#Set the proper password for the Cacti DB user in the config
sed -i -e “s/^\$database_password\ \= \”cactiuser\”/\$database_password\ \= \”${CACTIPASS}\”/” include/config.php
chown -R apache:apache /var/www/html/cacti
# Crontab entry for cacti (runs as root)
echo ‘*/5 * * * * root /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1’ > /etc/cron.d/0Cacti

echo “If there were no errors reported, everything should now be installed!\n”
echo “You will now need to reboot the server to apply the SELinux setting.\n”

You can also download the script from here.

2 thoughts on “Script to install Cacti on CentOS 6 or Red Hat 6

  1. Jim Julson

    So, taking this script and running it on CentOS 6.2 Minimal, it fails. Although I must admit that all I did was change the fields for the passwords as instructed and nothing more.

    Am I missing something?

    1. admin Post author

      Sorry Jim, this blog was offline for a long time (had other things going on). I will try and re-run it in a more recent CentOS 6.x VM and update accordingly.


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.