MRTG Installation For CentOS


User Variable
ipadd=ifconfig |grep inet | cut -b 21-32 |head -n1

User Functions
function fn_SELinux()
getenforce |grep Enforcing >/dev/null 2>&1 && se_l=1 || se_l=0
if [ $se_l -eq 1 ]
echo “SELinux is Enforcing”
echo “Disabling SELinux”
setenforce 0
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
echo “SELinux is Disabled”
echo “SELinux is Disabled”

IPTable Functions
function fn_IPTable()
/etc/init.d/iptables status |grep not && ipt=1 || ipt=0
if [ $ipt -eq 1 ]
echo “IPtables is already disabled”
echo “”
echo “IPtables service is running on the system”
echo “”
echo “If you want I can stop the IPtable service for you or if you don’t want to stop the IPtable service i will allow the httpd service in IPtables”
echo “”
echo “Do you want me to stop the IPTable service [y/n]”
read response
echo “$response” > respo; head -1 respo > res
cat res | grep y >/dev/null 2>&1 && sure=1 || sure=0
if [ $sure -eq 1 ]
Disabling IPTables
/etc/init.d/iptables stop
chkconfig iptables off
IPTables Service is Disabled Now
rm -f res respo
Checking if http service is allowed in IPTable
iptables -L |grep http >/dev/null 2>&1 && ena=1 || ena=0
if [ $ena -eq 1 ]
http service is already allowed in IPTable
Adding httpd service to IPTables
iptables -I INPUT 5 -i eth0 -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT
/etc/init.d/iptables save
httpd service has been allowed in IPTables
rm -f res respo

Information Collection
echo “Please enter the network IP you want to add example”
read network
echo “please enter the state/province name where system is located”
read state
echo “Please enter the country name where system is located”
read country
echo “Please enter the system administrators name”
read contact
echo “Please enter the system administrators email”
read contactmail

Preparing the Server for MRTG Installation
Checking Prerequisites

Checking for wget Package
wget |grep Usage >/dev/null 2>&1 && wgt=1 || wgt=0
if [ $wgt -eq 1 ]
echo “wget is already installed”
echo “Installing wget”
yum install -y wget

Necessary Package Installation
yum install -y httpd gcc gd gd-devel perl libpng libxml2-devel cairo-devel glib2-devel pango-devel perl-devel perl-CGI net-snmp net-snmp-utils

SNMP Configuration
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
echo “com2sec local localhost public
com2sec mynetwork $netwo public
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup \”\” any noauth exact all none none
access MyRWGroup \”\” any noauth exact all all none
syslocation $state, $country
syscontact $contact <$contactmail>
” > /etc/snmp/snmpd.conf
/etc/init.d/snmpd restart
chkconfig snmpd on

MRTG Installation
cd /tmp
tar zfx mrtg.tar.gz >/dev/null 2>&1
tar -ztf mrtg.tar.gz |head -n1 |awk -F “/THANKS” ‘{print $1}’ > mrtgvers
mrtver=”$(cat /tmp/mrtgvers)”
cd $mrtver
./configure –prefix=/usr/local/mrtg2
make install
cd /tmp
tar zfx rrdtool.tar.gz >/dev/null 2>&1
tar -ztf rrdtool.tar.gz |head -n1 |awk -F “/THANKS” ‘{print $1}’ > rrdvers
rrdver=”$(cat /tmp/rrdvers)”
cd $rrdver
./configure –prefix=/usr/local/rrdtool
make install
mkdir /var/www/mrtg
mkdir /home/mrtg
/usr/local/mrtg2/bin/cfgmaker –global “WorkDir: /var/www/mrtg” –global “Options[_]: growright, bits” –global “RunAsDaemon: Yes” –global “LogFormat: rrdtool” –global “PathAdd: /usr/local/rrdtool/bin” –global “LibAdd: /usr/local/rrdtool/lib/perl/5.10.1” -ifref=ip –output /home/mrtg/mrtg.cfg public@localhost
env LANG=C /usr/local/mrtg2/bin/mrtg /home/mrtg/mrtg.cfg
echo “*/5 * * * * root env LANG=C /usr/local/mrtg2/bin/mrtg /home/mrtg/mrtg.cfg –logging /var/log/mrtg.log ” > /etc/cron.d/mrtg
chkconfig crond on
/usr/local/mrtg2/bin/indexmaker –output=/var/www/mrtg/index.html /home/mrtg/mrtg.cfg

Configuring Mrtg.Conf
echo ”
Alias /mrtg /var/www/mrtg
<Location /mrtg>
Order deny,allow
#Deny from all
Allow from
Allow from ::1
#Allow from
Allow from all
” > /etc/httpd/conf.d/mrtg.conf
chkconfig httpd on
service httpd restart
cd /tmp
wget >/dev/null 2>&1
mv /tmp/14all-cgi1.key /var/www/cgi-bin/14all.cgi
chmod 777 /var/www/cgi-bin/14all.cgi

Installation is Completed
Check with MRTG http://Ip-address/mrtg

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s