shell script自动搭建简单的cacti监控
2013-03-04 17:20
447 查看
#!/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} <<EOF
create database cacti;
grant all on cacti.* to "cacti"@"localhost" identified by "${user_passwd}";
flush privileges;
EOF
cd ${soft_http}/cacti/
${cmd_mysql} -uroot -p${mysql_root_passwd} cacti < cacti.sql &> /dev/null
##########################################################
#change config.php and global.php files
#input your cacti password to change last word as "cacti"
#config.php
#grep "\$database_username = \"cactiuser\";" ${file_config} |sed -i "/\$database_username = \"cactiuser\";/\$database_username = \"${user_name}\";/" ${file_config}
#grep "\$database_password = \"cactiuser\";" ${file_config} |sed -i "/\$database_password = \"cactiuser\";/\$database_password = \"${user_passwd}\";/" ${file_config}
#global.php
#grep "\$database_username = \"cactiuser\";" ${file_global} |sed -i "/\$database_username = \"cactiuser\";/\$database_username = \"${user_name}\";/" ${file_config}
#grep "\$database_password = \"cactiuser\";" ${file_global} |sed -i "/\$database_password = \"cactiuser\";/\$database_password = \"${user_passwd}\";/" ${file_global}
#####################################################
#config.php
ed -s ${file_config} <<EOF
g/\$database_username = "cactiuser";/s/\$database_username = "cactiuser";/\$database_username = "${user_name}";/g
w
q
EOF
ed -s ${file_config} <<EOF
g/\$database_password = "cactiuser";/s/\$database_password = "cactiuser";/\$database_password = "${user_passwd}";/g
w
q
EOF
#global.php
ed -s ${file_global} <<EOF
g/\$database_username = "cactiuser";/s/\$database_username = "cactiuser";/\$database_username = "${user_name}";/g
w
q
EOF
ed -s ${file_global} <<EOF
g/\$database_password = "cactiuser";/s/\$database_password = "cactiuser";/\$database_password = "${user_passwd}";/g
w
q
EOF
chown -R root:root /usr/local/apache2/htdocs/cacti
echo '*/5 * * * * php /usr/local/apache2/htdocs/cacti/poller.php &> /dev/null' >> /etc/crontab
echo "Please login [http://localhost/cacti/] to finsh setting"
echo "Enjoy cacti..."
cat <<EOF
##########################Note####################
login:
username: admin
password: admin
##################################################
EOF
本文出自 “无咎” 博客,请务必保留此出处http://perofu.blog.51cto.com/6061242/1144582
#
#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} <<EOF
create database cacti;
grant all on cacti.* to "cacti"@"localhost" identified by "${user_passwd}";
flush privileges;
EOF
cd ${soft_http}/cacti/
${cmd_mysql} -uroot -p${mysql_root_passwd} cacti < cacti.sql &> /dev/null
##########################################################
#change config.php and global.php files
#input your cacti password to change last word as "cacti"
#config.php
#grep "\$database_username = \"cactiuser\";" ${file_config} |sed -i "/\$database_username = \"cactiuser\";/\$database_username = \"${user_name}\";/" ${file_config}
#grep "\$database_password = \"cactiuser\";" ${file_config} |sed -i "/\$database_password = \"cactiuser\";/\$database_password = \"${user_passwd}\";/" ${file_config}
#global.php
#grep "\$database_username = \"cactiuser\";" ${file_global} |sed -i "/\$database_username = \"cactiuser\";/\$database_username = \"${user_name}\";/" ${file_config}
#grep "\$database_password = \"cactiuser\";" ${file_global} |sed -i "/\$database_password = \"cactiuser\";/\$database_password = \"${user_passwd}\";/" ${file_global}
#####################################################
#config.php
ed -s ${file_config} <<EOF
g/\$database_username = "cactiuser";/s/\$database_username = "cactiuser";/\$database_username = "${user_name}";/g
w
q
EOF
ed -s ${file_config} <<EOF
g/\$database_password = "cactiuser";/s/\$database_password = "cactiuser";/\$database_password = "${user_passwd}";/g
w
q
EOF
#global.php
ed -s ${file_global} <<EOF
g/\$database_username = "cactiuser";/s/\$database_username = "cactiuser";/\$database_username = "${user_name}";/g
w
q
EOF
ed -s ${file_global} <<EOF
g/\$database_password = "cactiuser";/s/\$database_password = "cactiuser";/\$database_password = "${user_passwd}";/g
w
q
EOF
chown -R root:root /usr/local/apache2/htdocs/cacti
echo '*/5 * * * * php /usr/local/apache2/htdocs/cacti/poller.php &> /dev/null' >> /etc/crontab
echo "Please login [http://localhost/cacti/] to finsh setting"
echo "Enjoy cacti..."
cat <<EOF
##########################Note####################
login:
username: admin
password: admin
##################################################
EOF
本文出自 “无咎” 博客,请务必保留此出处http://perofu.blog.51cto.com/6061242/1144582
相关文章推荐
- shell script自动搭建简单的mysql主从(replication)
- 运维笔记40 Linux系统监控之Cacti(Cacti搭建,自动抓取cacti统计图片脚本)
- shell script自动搭建简单的nfs服务器
- shell script自动搭建简单的pxe服务器
- shell script自动搭建简单的mail服务器(postfix+dovecot)
- shell script自动搭建简单的yum
- shell script自动搭建简单的双机ssh认证
- 一个简单自动监控nginx 504错误的php脚本
- linux 进程监控和自动重启的简单实现
- Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)
- lnmp环境下cacti简单配置以及监控
- Linux下的motion detection(最简单的办公室监控系统) 邮件自动发送
- linux下mrtg,cacti,nagios,ganglia的搭建和win/linux主机等的监控
- Cacti流量监控系统搭建维护手册
- zookeeper搭建服务自动注册与监控
- linux 进程监控和自动重启的简单实现 .
- 搭建cacti监控平台
- Dubbo服务,后台管理,监控中心搭建的简单实践
- shell script自动搭建简单的dhcp服务器
- shell script自动搭建简单的quota(磁盘配额)