您的位置:首页 > 移动开发 > IOS开发

Cagios.sh 自动安装nagios cacti zabbix munin的脚本

2013-04-01 18:21 543 查看
#!/bin/bash
#Cagios.sh
#================================================================+
# Tips: Login				                                     +
#      Admin:root     Password:cagios					         +
#================================================================+
# Tips: Ngios				                                     +
#      local http://localhot:/nagios 				         +
#      Admin:nagios     Password:nagios					         +
#================================================================+
# Cacti:                                                         +
#      local http://localhot/cacti 				             +
# User:admin   Password:admin		                             +
# MySQL:                                                         +
#      User: cactiuser  Password: cactiuser                      +
#================================================================+
# Zabbix:                                                        +
#      local http://localhot/zabbix 				             +
# User:admin   Password:zabbix		                             +
# MySQL:                                                         +
#      User: zabbix  Password: zabbix                            +
#================================================================+
# munin:                                                         +
#      local http://localhot/munin 				             +
# User:munin   Password:munin		                             +
#================================================================+
# Tips: SNMP                                                     +
#       TCP port 161          public                             +
#snmpwalk -v 2c -c public localhost                              +
#================================================================+
#
#
#
#
#
########################################
# Close Selinux                        #
########################################
setenforce 0
cp -rf /etc/selinux/config /etc/selinux/config.backup
echo "SELINUX=disabled" >/etc/selinux/config
echo '#!/bin/bash
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
inet=$(ifconfig eth0|grep "inet addr:"|cut -d: -f2|awk -F"  " '\'{print \$1}\'')
echo "This is Cagios OS; Author:CaoGuo
inet:$inet" >/etc/issue' >/root/iptables.rule
echo "sh /root/iptables.rule" >>/etc/rc.local

########################################
# Nagios-nrpe                          #
########################################

yum -y update
yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp net-snmp-utils openssl openssl-devel wget patch mysql-devel mailx

#email send tools
#nano /etc/mail.rc
#set from=s0lence@126.com smtp=smtp.126.com
#set smtp-auth-user=xx@oo smtp-auth-password=xxoo
#set smtp-auth=login

cd /tmp
wget http://jaist.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz 
useradd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
tar zxvf nagios-3.5.1.tar.gz
tar zxvf nagios-plugins-1.4.16.tar.gz
tar zxvf nrpe-2.13.tar.gz
cd nagios
./configure --prefix=/opt/nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cp -R contrib/eventhandlers/ /opt/nagios/libexec/
chown -R nagios:nagios /opt/nagios/libexec/eventhandlers
/opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg

cd /tmp/nagios-plugins-1.4.16
./configure --prefix=/opt/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make && make install

cd /tmp/nrpe-2.13
./configure --prefix=/opt/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config

/opt/nagios/bin/nrpe -c /opt/nagios/etc/nrpe.cfg -d

echo "/opt/nagios/bin/nrpe -c /opt/nagios/etc/nrpe.cfg -d" >>/etc/rc.local

sed -i 's/use_authentication=1/use_authentication=0/' /opt/nagios/etc/cgi.cfg
sed -i 's@#cfg_file=/opt/nagios/etc/objects/windows.cfg@cfg_file=/opt/nagios/etc/objects/windows.cfg@g' /opt/nagios/etc/nagios.cfg
htpasswd -bc /opt/nagios/etc/htpasswd.users nagios nagios

echo 'define command{
command_name    check_nrpe
command_line    /opt/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}' >>/opt/nagios/etc/objects/commands.cfg

sed -i 's/members         localhost/members         localhost,centos/g' /opt/nagios/etc/objects/localhost.cfg

echo "define host{
use                     linux-server            ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the local-service host template definition.
host_name               centos
alias                   Centos
address                 192.168.21.128
}

define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             PING
check_command                   check_ping!100.0,20%!500.0,60%
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             SSH
check_command                   check_ssh
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             HTTP
check_command                   check_http
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             FTP
check_command                   check_ftp
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             DHCP
check_command                   check_dhcp
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-users
check_command                   check_nrpe!check_users
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-load
check_command                   check_nrpe!check_load
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-zombie-procs
check_command                   check_nrpe!check_zombie_procs
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-total-procs
check_command                   check_nrpe!check_total_procs
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-sda1
check_command                   check_nrpe!check_sda1
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-sda2
check_command                   check_nrpe!check_sda2
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-swap
check_command                   check_nrpe!check_swap
notifications_enabled           0
}
define service{
use                             local-service         ; Name of service template to use
host_name                       centos
service_description             NRPE-mysql
check_command                   check_nrpe!check_mysql
notifications_enabled           0
}" >>/opt/nagios/etc/objects/localhost.cfg

#################################
# Cacti                         #
#################################

yum install -y httpd php php-mysql php-snmp mysql mysql-server net-snmp net-snmp-utils rrdtool crontabs wget
cd /tmp
wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz tar zxvf cacti-0.8.8a.tar.gz
echo "grant all privileges on *.* to 'root'@'localhost' identified by 'toor' with grant option;
grant all privileges on *.* to 'root'@'%' identified by 'toor' with grant option;
create database cacti;
grant all privileges on cacti.* to cactiuser@localhost identified by 'cactiuser';
create database zabbix character set utf8;
grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';
flush privileges;" >/tmp/initialize.sql
service mysqld start
mysql </tmp/initialize.sql

rm -rf /var/www/cacti
mv cacti-0.8.8a /var/www/cacti
mysql -h localhost -u root -ptoor cacti </var/www/cacti/cacti.sql
useradd cacti
echo "cacti"|passwd cacti --stdin
#echo "*/5 * * * * php /var/www/cacti/poller.php >/dev/null 2>&1"
ln -sf /var/www/cacti/ /var/www/html/
chown -R cacti.cacti /var/www/cacti/rra/ /var/www/cacti/log/ /var/www/cacti/poller.php

sed -i "s@;date.timezone =@date.timezone = Asia/Chongqing@g" /etc/php.ini

###/etc/snmp/snmpd.conf##
#echo "com2sec notConfigUser  default       public
#group
a667
notConfigGroup v1           notConfigUser
#group   notConfigGroup v2c           notConfigUser
#view    systemview    included   .1.3.6.1.2.1.1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
#access  notConfigGroup ""      any       noauth    exact  all none none
#view all    included  .1                               80
#syslocation Unknown (edit /etc/snmp/snmpd.conf)
#syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
#dontLogTCPWrappersConnects yes" >/etc/snmp/snmpd.conf

#wget http://www.cacti.net/downloads/patches/0.8.8a/snmpv3_priv_proto_none.patch #patch -p1 -N <snmpv3_priv_proto_none.patch

#################################
# zabbix                        #
#################################

rpm --import http://repo.zabbixzone.com/centos/RPM-GPG-KEY-zabbixzone rpm -Uvh http://repo.zabbixzone.com/centos/zabbixzone-release-0.0-1.noarch.rpm yum install -y mysql-server zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway
sed -i "s@;date.timezone =@date.timezone = Asia/Chongqing@g" /etc/php.ini
service mysqld restart
mysql -u zabbix -pzabbix zabbix </usr/share/doc/zabbix-server-mysql-2.0.8/create/schema.sql
mysql -u zabbix -pzabbix zabbix </usr/share/doc/zabbix-server-mysql-2.0.8/create/images.sql
mysql -u zabbix -pzabbix zabbix </usr/share/doc/zabbix-server-mysql-2.0.8/create/data.sql

#################################
# munin                         #
#################################

cd /tmp
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -ivh /tmp/epel-release-6-8.noarch.rpm
yum -Y install http
yum -y install munin munin-node
htpasswd -bc /etc/munin/munin-htpasswd munin munin
#user:munin
#passwd:munin

#################################
# ntop                          #
#################################
# yum install gcc cpp glibc glibc-devel gcc-c++
# yum install libtool gdbm gdbm-devel libpcap gd gd-devel libpng libpng-devel lksctp-tools lksctp-tools-devel openssl-devel
#wget http://ncu.dl.sourceforge.net/project/ntop/ntop/Stable/ntop-5.0.1.tar.gz 
service httpd start
chkconfig httpd on

service mysqld restart
chkconfig mysqld on

service snmpd start
chkconfig snmpd on

service nagios start
chkconfig nagios on

service zabbix-server start
chkconfig zabbix-server on
service zabbix-agent start
chkconfig zabbix-agent on

service munin-node start
chkconfig munin-node on

service crond restart
chkconfig crond on

/opt/nagios/libexec/check_nrpe -H localhost -c check_load
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: