cacti+nagios/install.sh
#װLAMPapche 2.4.6  php 5.5.3

#apache

tar jxvf apr-1.5.0.tar.bz2 && cd apr-1.5.0
#ע͵configureļеĳУ/bin/rm: cannot remove `libtoolT: No such file or directory 
sed -i '/$RM "$cfgfile"/ s/^/#/' configure
./configure --prefix=/usr/local/apr && make && make install || exit 1
cd ..
#apr-util
tar jxvf apr-util-1.5.3.tar.bz2  &&  apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config  && make && make install

#pcre
cd ..
echo "Start the installation of pcre..."
tar jxvf pcre-8.34.tar.bz2 && cd pcre-8.34
./configure --prefix=/usr/local/pcre && make && make install 

sleep 2
tar zxvf httpd-2.4.9.tar.gz && cd httpd-2.4.9 && ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config  --with-pcre=/usr/local/pcre/ --enable-mods-shared=most  --enable-rewirte --enable-so --enable-ssl=static --with-ssl  && make && make install

#phpذsnmpsocketsPDO_MYSQLjsonչ(jsonĬϰ) #socketssnmpΪcacti裬socketsչװ޷򿪣ʾȱsocketsչװҪָsnmp·  
#pdo_mysqljsonչΪNPCҪ nagios plugin for cacti


yum install net-snmp net-snmp-devel net-snmp-utils
#snmpd.confԱԭֱ񼴿

#php       
./configure --prefix=/usr/local/php5.3  --with-config-file-path=/usr/local/php5.3/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir --with-iconv-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --with-zlib --with-gd=/usr/local/gd --with-freetype-dir=/usr/local/freetype --with-mcrypt --with-mhash --enable-gd-native-ttf  --with-curl --with-bz2 --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl-dir --without-pear --enable-xml --enable-zip --enable-sockets --with-snmp
make
make install

# php.ini
# 1 phpһҪexec()ִ
# 2 date.timezone = Asia/Chongqing

#װrrdtool
yum install rrdtool

#cactiʹõݿ,û

mysql --user=root --password=123456 <<EOF
CREATE DATABASE cacti;
GRANT ALL PRIVILEGES ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser';
FLUSH PRIVILEGES;
EOF

#cactiװ
tar zxvf cacti-0.8.8b.tar.gz -C ${apache_DocumentRoot}
#ѹcacti.sqlcacti,дmysqlϢURLwebʿʼװ

#װҪָ·php snmp

#װɺҪConsole->Settings->generaløİ汾
net-snmp -->5.x
rrdtool -->1.3x
snmp ---> version2

#Devices-->õϢ
snmp--> version2

#Ӽƻ
*/5 * * * * php poller.php > /dev/null 2&1

#Ļapache־кܶʾ


==========================================================



#װspine,һָЧѯƣ滻cactiԴ[poller type]--- cmd.php
#http://www.cacti.net/downloads/spine/ صַעcacti汾һ
tar zxvf cacti-spine-0.8.8b.tar.gz && cd cacti-spine-0.8.8b
./configure --prefix=/usr/local/spine
make && make install

#༭spineļ /usr/local/spine/etc/spine.conf,дȷݿϢ

#cactiConsole-->Settings-->Poller,ѯʽΪspine

============================================================


# ndoutils,nagiosռݴmysql,Ȼcactiȡʾ
tar zxvf ndoutils-1.5.2.tar.gz && cd  ndoutils-1.5.2
./configure --enable-mysql --with-mysql=/usr/local/mysql/

#Ĵ
../include/config.h:261:25: error: mysql/mysql.h: No such file or directory
../include/config.h:262:26: error: mysql/errmsg.h: No such file or directory

#
vi ndoutils-1.5.2/include/config.h
е/mysql/ȥ,ӦǸƴӣ#include/usr/local/mysql/include/(./configureָ)ƴϺߵı/usr/local/mysql/include/mysql/mysql.h,ԶһĿ¼ʾҲ
#include </mysql/mysql.h>
#include </mysql/errmsg.h>

make

cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo}  /usr/local/nagios/bin
#ndodb
mysql --user=root --password=123456 <<EOF
CREATE DATABAS ndodb;
GRANT ALL PRIVILEGES ON ndodb.* TO ndouser@localhost IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
EOF
 
cd ndoutils-1.5.2/db
#ndoutilsҪݿȣЩĬԡnagios_Ϊǰ׺
./installdb -u ndouser -p 123456 -h localhost -d ndodb
#installdbһperlűִҪõperlDBIDBD::mysqlģ飬ûȰװ 

#ơ༭ļ
cd ndoutils-1.5.2/config
cp ndo2db.cfg-sample  /usr/local/nagios/etc/ndo2db.cfg
cp ndomod.cfg-sample  /usr/local/nagios/etc/ndomod.cfg
chmod 644 /usr/local/nagios/etc/ndo*
chown nagios:nagios /usr/local/nagios/etc/ndo*
chown nagios:nagios /usr/local/nagios/bin/*

vi /usr/local/nagios/etc/nagios.cfg
event_broker_options=-1
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

#༭ndo2dbndomodļ
vi /usr/local/nagios/etc/ndo2db.cfg

socket_type=unix
socket_name=/usr/local/nagios/var/ndo.sock

db_servertype=mysql
db_host=localhost
db_port=3306
db_name=ndodb
db_prefix=nagios_
db_user=ndouser
db_pass=123456

vi /usr/local/nagios/etc/ndomod.cfg
output_type=unixsocket
output=/usr/local/nagios/var/ndo.sock

#ndo2db
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

#鿴ϵͳ־ȷ

#nagios,׹ر
service nagios stop
rm -f /usr/local/nagios/var/nagios.lock
service nagios start

#webҳ鿴nagios־ǷɹndomodģԼndo2dbǷӵɹӵmysql

=============================================================
#װntop

#ȰװGeoIP GeoIP-develĬϵyumԴûepel  yumԴ
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm

yum install ntop
#ntopԱ
ntop -A

#һͨûntop
useradd -M -s /sbin/nologin -r ntop
#ntop
ntop -i eth0 -d -L -u ntop
#鿴ntopЧ
http://ip:3000

==========================================================

#ntopnagiosϽcactiҲǸcactiװ

#ntop,װntop-v0.2-1.tgz
tar zxvf ntop-v0.2-1.tgz -C /data/www/cacti/plugins

#cacticonsole->Settings->Miscдntopdurl,http://192.168.126.130:3000
#Ȼcacticonsole->Plugin ManagementаװntopͿ


==========================================================

#nagios,װnpc(nagios-plgin-for-cacti)
tar zxvf npc-2.0.4.tar.gz -C /data/www/cacti/plugins
#cactiConsole-->Plugin Managementаװnpcװлcactinpc_*ݱṹ֮ǰװndoutilsʱndodb
#nagios_*һģnpcԺԭndodbûˣӦ޸ndo2dbãnagiosֱдcactiУnpc
#ȡndo2dbдݣȻcactiչֳ

#Console-->Settings-->NPCnagiosϢ
# Remote Commands [ѡ]
# Nagios Command File Path-->/usr/local/nagios/var/rw/nagios.cmd
# Nagios URL  http://xxxxx/nagios
#



# ޸ndo2dbļ
# db_name ndodbΪcacti
# db_prefix nagios_Ϊnpc_
# ȻҪȷndo2dbʹõûȨcactinpc_*д


#Ϊcactiеnpc_*ȱʧֶΣndo2dbڽnagiosռдcactinpc_дݵʱᱨȱlong_outputֶεĴ
mysql --user=root --password=123456 <<EOF
use cacti;
ALTER TABLE npc_eventhandlers ADD long_output TEXT NOT NULL AFTER output;
ALTER TABLE npc_hostchecks ADD long_output TEXT NOT NULL AFTER output;
ALTER TABLE npc_hoststatus ADD long_output TEXT NOT NULL AFTER output;
ALTER TABLE npc_notifications ADD long_output TEXT NOT NULL AFTER output;
ALTER TABLE npc_servicechecks ADD long_output TEXT NOT NULL AFTER output;
ALTER TABLE npc_servicestatus ADD long_output TEXT NOT NULL AFTER output;
ALTER TABLE npc_statehistory ADD long_output TEXT NOT NULL  AFTER output;
ALTER TABLE npc_systemcommands ADD long_output TEXT NOT NULL  AFTER output;
EOF



#ndo2dbnagios,ע⳹׹ر
# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
# service nagios start
#鿴ϵͳ־ȷndo2dbѾдcacti