批量部署Cacti监控系统

背景:公司总共有十几个机房,每个机房都要部署一台监控系统

思路:一台一台去安装肯定太慢,也麻烦,更累。写一个或者多个部署脚本,指安装和配置监控系统

分三个脚本来实现

监控系统环境安装脚本
监控系统安装脚本
监控系统配置脚本
监控系统数据库脚本

一、监控系统部署

1.监控系统环境安装脚本

#!/bin/bash
cd /root/CentOS
echo "cd /root/CentOS"
 
sleep 3
echo "Install SNMP Server..."
rpm -ivh net-snmp-5.3.1-24.el5.i386.rpm net-snmp-utils-5.3.1-24.el5.i386.rpm net-snmp-devel-5.3.1-24.el5.i386.rpm net-snmp-perl-5.3.1-24.el5.i386.rpm beecrypt-devel-4.1.2-10.1.1.i386.rpm elfutils-devel-0.125-3.el5.i386.rpm lm_sensors-devel-2.10.0-3.1.i386.rpm lm_sensors-2.10.0-3.1.i386.rpm elfutils-devel-static-0.125-3.el5.i386.rpm
 
sleep 3
echo "Install php-snmp..."
rpm -ivh php-snmp-5.1.6-20.el5.i386.rpm
 
cd /root/monitor/rrd
echo "cd /root/monitor/rrd"
sleep 3
echo "Install RRDTool..."
rpm -ivh perl-rrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-1.2.23-1.el5.rf.i386.rpm rrdtool-devel-1.2.23-1.el5.rf.i386.rpm
 
sleep 3
echo "Install Syslog-NG..."
rpm -ivh syslog-ng-2.1.4-1.el5.i386.rpm
 
sleep 3
echo "Copy Configure Files..."
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
cp /root/monitor/snmpd.conf /etc/snmp/
 
sleep 3
echo "Set the file +x..."
chmod +x /etc/rc.d/init.d/syslog-ng
 
sleep 3
chkconfig --level 3 snmpd on
service snmpd restart
 
sleep 3
cd /root/monitor/rrd
sleep 3
tar xzvf cacti-spine-0.8.7a.tar.gz
sleep 3
cd cacti-spine-0.8.7a
sleep 3
./configure
sleep 3
make
sleep 3
make install
 
#sleep 3
#echo "Install Nessus Security..."
#rpm -ivh /root/monitor/Nessus-3.2.1-es5.i386.rpm

2.监控系统安装脚本

#!/bin/bash
#
# Create by kevin
# Data 2009-04-28
# Mail kevinadmin@sohu.com
#
 
if [ ! -e /www ]; then
mkdir /www
fi
 
if [ -e /www ]; then
echo "Copy the Cacti files..."
sleep 2
cp -r /root/monitor/cacti/* /www/
sleep 2
cp -r /root/monitor/cacti-plugin-arch/* /www/
sleep 2
cp -r /root/monitor/cactiez/* /www/
 
sleep 2
# Configure the syslog-NG
echo "Congfiure the syslog-NG..."
cp /root/monitor/sbin/syslogtomysql /sbin/
chmod +x /sbin/syslogtomysql
 
sleep 2
echo "Configure the syslog-ng..."
mv /etc/rc.d/init.d/syslog-ng /etc/rc.d/init.d/syslog-ng.bak
mv /etc/rc.d/init.d/network /etc/rc.d/init.d/network.bak
 
sleep 2
cp /root/monitor/etc/rc.d/init.d/* /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/flow-capture /etc/rc.d/init.d/cacti_rrdsvc
chmod +x /etc/rc.d/init.d/network /etc/rc.d/init.d/syslog-ng
 
sleep 2
cp /root/monitor/etc/logrotate.d/cacti /etc/logrotate.d/
cp /root/monitor/etc/mail/relay-domains /etc/mail/
 
sleep 2
mv /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.bak
cp /root/monitor/etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/
 
sleep 2
echo "Copy the Cacti Plugins files..."
cp -r /root/monitor/plugins/* /www/plugins/
fi
 
sleep 2
 
echo "Auto Create Database and other configure...."
/root/monitor/automysql.sh
 
sleep 2
 
if [ -e /www/plugins/syslog ]; then
 
echo "Import the SQL file to the Database..."
mysql -u root --password=cactipasswd monitor < /www/cacti.sql
mysql -u root --password=cactipasswd monitor < /www/pa.sql
mysql -u root --password=cactipasswd monitor < /www/cacti-changes.sql
mysql -u root --password=cactipasswd syslog < /www/plugins/syslog/syslog.sql
mysql -u root --password=cactipasswd syslog < /www/syslog-changes.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/monitor/monitor.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/update/update.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/thold/thold.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/boost/boost_sql_myisam.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/boost/boost_sql_memory.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/realtime/realtime.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/discovery/discover.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/wmi/wmi.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/aggregate/aggregate.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/routerconfigs/routerconfigs.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/flowview/flowview.sql
mysql -u root --password=cactipasswd monitor < /www/plugins/mactrack/mactrack.sql
fi
 
sleep 2
 
echo "Auto Modified the Cacti about the connect the Database..."
/root/monitor/automodify.sh
 
sleep 2
echo "Start the syslog-NG service..."
chkconfig --level 345 syslog-ng on
chkconfig --level 2345 syslog off
service syslog-ng restart

3.监控系统配置脚本

#!/bin/bash
if [ -e /www ]; then
 
echo "modify the config.php file"
sed -i '27s/cacti/monitor/' /www/include/config.php
 
sed -i '29s/cactiuser/cactiuser/' /www/include/config.php
 
sed -i '30s/CactiMadeEZ/cactipasswd/' /www/include/config.php
 
echo "modify the global.php file"
sed -i '35s/cacti/monitor/' /www/include/global.php
 
sed -i '37s/cactiuser/cactiuser/' /www/include/global.php
 
sed -i '38s/cactiuser/cactipasswd/' /www/include/global.php
 
echo "modify the syslog config.php file"
sed -i '4s/syslog/syslog/' /www/plugins/syslog/config.php
 
sed -i '6s/cactiuser/cactiuser/' /www/plugins/syslog/config.php
 
sed -i '7s/CactiMadeEZ/cactipasswd/' /www/plugins/syslog/config.php
 
echo "modify the syslogtomysql file"
sed -i '8s/cactiuser/cactiuser/' /sbin/syslogtomysql
sed -i '8s/CactiMadeEZ/cactipasswd/' /sbin/syslogtomysql
 
echo "modify spine configure file"
sed -i '32s/cacti/monitor/' /usr/local/spine/etc/spine.conf
sed -i '33s/cactiuser/cactiuser/' /usr/local/spine/etc/spine.conf
sed -i '34s/cactiuser/cactipasswd/' /usr/local/spine/etc/spine.conf
fi

4.监控系统数据库脚本

#!/usr/bin/expect -f
set user "root"
set passwd "hxwhb.com"
set timeout 60
set cmd "mysql>"
spawn mysqladmin -u root password hxwhb.com
spawn mysql -u $user -p
expect "Enter password:"
send "$passwd\r"
sleep 3
expect "$cmd"
send "create database monitor;\r"
expect "$cmd"
sleep 3
send "grant all privileges on monitor.* to cactiuser@localhost identified by 'cactipasswd';\r"
expect "$cmd"
sleep 3
send "flush privileges;\r"
expect "$cmd"
sleep 3
send "create database syslog;\r"
expect "$cmd"
sleep 3
send "grant all privileges on syslog.* to cactiuser@localhost identified by 'cactipasswd';\r"
expect "$cmd"
send "flush privileges;\r"
expect "$cmd"
send "\q\r"

还没有评论,快来抢沙发!

发表评论

  • 😉
  • 😐
  • 😡
  • 😈
  • 🙂
  • 😯
  • 🙁
  • 🙄
  • 😛
  • 😳
  • 😮
  • emoji-mrgree
  • 😆
  • 💡
  • 😀
  • 👿
  • 😥
  • 😎
  • ➡
  • 😕
  • ❓
  • ❗
  • 70 queries in 0.374 seconds