774530750 发表于 2019-1-11 06:44:49

shell script自动搭建简单的cacti监控

  #!/bin/bash
#
#Shell name:config_cacti.sh
#
#Program:
#    config cacti server by this shell script
#
#Author:perofu
#
#Mail:perofu.com@gmail.com
#
#History:
#    2012/10/23
#
#If you have any opinions please contact me

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH

soft_dir=/root/cacti/                #/full/path/
soft_rrdtool=/usr/local/src/rrdtool-1.4.5/    #NOTE:soft full name
soft_snmp=/usr/local/src/net-snmp-5.3.0.1/
soft_cacti=/usr/local/src/cacti-0.8.8a/
soft_http=/usr/local/apache2/htdocs/      #check where is your httpd home dir
cmd_mysql=$(which mysql)
file_config=/usr/local/apache2/htdocs/cacti/include/config.php
file_global=/usr/local/apache2/htdocs/cacti/include/global.php

#mysql root passwd
mysql_root_passwd=123456

#user name and password for cacti
user_name=cacti
user_passwd=123456


if [ $UID -ne "0" ]
then
echo "Run as root"
exit 77
fi

if [ ! -d ${soft_dir} ]
then
    echo "It's not the ${soft_dir} exist"
    exit 77
fi

if [ -z ${user_name} ]
then
    echo "Please input a user name for cacti in config_cacti.sh"
    exit 77
fi

if [ -z ${user_passwd} ]
then
    echo "Please input a password for cacti in config_cacti.sh"
    exit 77
fi

if [ -z ${mysql_root_passwd} ]
then
    echo "Please input a password for mysql root in config_cacti.sh"
    exit 77
fi



cd ${soft_dir}

#install base soft

yum install pango pango-devel freetype freetype-devel libpng libpng-devel gettext gettext-devel libjpeg libjpeg-devel gd gd-devel libxml2 libxml2-devel libiconv libiconv-devel qpixman qpixman-devel glib glib-devel cairo cairo-devel libart* make gcc gcc-c++ -y &> /dev/null


#taring soft to /usr/local/src/

for soft in $(ls *.tar.gz)
do
    tar -axf ${soft} -C /usr/local/src/
done

#installing rrdtool


if [ ! -d ${soft_rrdtool} ]
then
    echo "It's not the ${soft_rrdtool} exist"
    exit 77
fi

cd ${soft_rrdtool}

./configure --prefix=/usr/local/rrdtool/ && make && make install

ln -s /usr/local/rrdtool/bin/* /usr/local/bin/

#installing net-snmp

if [ ! -d ${soft_snmp} ]
then
    echo "It's not the ${soft_snmp} exist"
    exit 77
fi

cd ${soft_snmp}

./configure --prefix=/usr/local/net-snmp/ && make && make install

ln -s /usr/local/net-snmp/bin/* /usr/local/bin/

cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf

/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf

echo "/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf" >> /etc/rc.local

#installing cacti

if [ ! -d ${soft_cacti} ]
then
    echo "It's not the ${soft_cacti} exist"
    exit 77
fi

cp -a ${soft_cacti} ${soft_http}/cacti

#NOTE:input you mysql user "root" and "password" in there

${cmd_mysql} -uroot -p${mysql_root_passwd}
页: [1]
查看完整版本: shell script自动搭建简单的cacti监控