Script to install Cacti on CentOS 6 or Red Hat 6

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
# linuxchris@gmail.com
#
# Modify the password variables below to match what you want

MYSQLPASS=’PASSWORD999′
CACTIPASS=’PASSWORD111′
CACTIVERSION=`wget -qO- www.cacti.net| grep “latest version” | sed ‘s/<[^>]*>//g’ | awk ‘{print $NF}’`
RRDVERSION=1.4.5
PKG_CONFIG_PATH=/usr/lib/pkgconfig/
CACTITMP=/tmp/cactisql.tmp
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 \
ntp

#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
done

#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
done

# 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
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool.tar.gz
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/
wget http://www.cacti.net/downloads/cacti-$CACTIVERSION.tar.gz
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 setting.\n”

You can also download the script from here.

Posted in Automation, Linux, Sysadmin | 2 Comments

SSH Connection Sharing

I was reading a post on a perl blog the other day and leaned about connection sharing in ssh. It allows you to open a ssh connection to a server and while that 1st connection is open, all subsequent connections will use the 1st connections credentials. It really saves time not having to enter your password if you are not using ssh keys. To enable it all you have to do is add the following two lines to your ~/.ssh/config file. If you do not have a config, just create it and add the two lines to the new file.

ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r

Another cool tip is that you can keep your connection ready for a specified period of time, even if you log out. So, if you log into the same server several times a day, you will only have to provide a password the 1st time until an inactive period of time passes. Add the the following to your ~/.ssh/config to keep connections ready for 2 hours.

ControlPersist 2h

The site I got this info from is here.

Posted in Linux, Sysadmin | Leave a comment

How to have a cifs (smb) share mount on startup with authentication

If you want to have a smb share mount on start up on a Linux system there are several options. I think the easiest option is to embed the auth info in a file only readable by root. All you have to do is put the auth file in the appropriate /etc/fstab mount line and it will work on boot. So, say we want to mount the default C$ share on a Windows box every time our Linux server boots. Here is what I would put in /etc/fstab:
//WINSRV/c$ /mnt/winsrv_c cifs credentials=/etc/credfile,domain=MYDOMAIN 0 0

My /etc/credfile file would contain two lines as follows:
username=WINUSER
password=WINPASS

Of course, WINUSER would be your domain (or local Windows) username and WINPASS would be you password. You want to set the permissions on this file to read/write for only root. As root (or sudo) you would run chmod 600 /etc/credfile.

Now you should be able to run ‘mount /mnt/winsrv_c’ at the command line to mount your windows c$ share. The mount will also show up again when you perform a reboot.

Posted in Linux, Samba, Sysadmin | 1 Comment

Manually testing a SMTP connection from the command line.

I have often had to manually test a SMTP (mail server) connection from the command line but I always forget the exact order of the commands in the conversation. This test is done via a standard telnet client on Linux, Unix, Mac OSX and Windows. If I remember correctly, in Windows you will have to enable echo to see your commands as they are typed (Set local_echo). Here is my walk through:

telnet mailserver.domain.com 25
helo mydomainname.com
mail from: myemail@mydomain.com
rcpt to: testemailaddress@mydomain.com
data
“Some Random Text.”
.

Remember the single period is the end of the conversation and signifies the end of the message to the SMTP server. A message should not be delivered to testemailaddress@mydomain.com from myemail@mydomain.com. The body of the e-mail will contain “Some Random Text.”

Posted in Uncategorized | 4 Comments

My new blog

Welcome to my new blog. I had a blog a while back but didn’t keep up with it… I am hoping to use this as a location for my notes on Linux, VMWare, Storage, etc. Hopefully I can use this to record things that will be useful to other people on the net.

Posted in Uncategorized | Leave a comment