Script to Install Cacti on a CentOS or RHEL 6.5 host

By | 7 April 2014

I while back I wrote a post about this script and it had since broken as some updates to RHEL/CentOS and rrdtool caused the script to crash. I updated it this weekend and verified it using a CentOS 6.5 x64 minimal install in a VM. Worked fine so here it is. You can download it here as well.

# 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.
# I make no promises that this will work every time, if ever…
# Proceed at your own risk! I am not responsible for any mistakes or issues caused.
# This script has no error checking! Add some if you’d like.
# Feel free to share this, just please post a link back to my site giving credit
# where credit is due. Enjoy!
# By: Chris Adams
# On: 6 Apr 2014
# Modify the password variables below to match what you want.
# You will also want to verify the rrd version prior to running.

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 -y 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

sed -i -e “s#^SELINUX\=enforcing#SELINUX\=disabled#” /etc/selinux/config

for i in ${OFFSERVERS[@]}
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[@]}
echo “Starting ${i}\n”
chkconfig ${i} on
service ${i} start

# Add teh fonts we installed to the font cache for Apache to use
echo “Upating Fornts for Apache Use, we dont want our Cacti to be ugly!”
fc-cache -vfs

echo “Now on to rrdtool”
# 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

echo “MySQL stuff being done…”
#Set Mysql password for root
mysqladmin –user=root password $MYSQLPASS
mysqladmin –user=root -p$MYSQLPASS reload

echo “Finally… The Cacti stuff!”
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 rm -f $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 settings (or run setenforce).\n”


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.