一、什么是Nagios
Nagios是一款用于系統(tǒng)和網(wǎng)絡(luò)監(jiān)控的應(yīng)用程序。它可以在你設(shè)定的條件下對主機和服務(wù)進行監(jiān)控,在狀態(tài)變差和變好的時候給出告警信息。
Nagios更進一步的特征包括:
Update of Channel "pear.php.net" succeeded
四、安裝nagios軟件包
A、安裝 Nagios
# yum install nagios nagios-devel
此處所安裝的nagios是3.0.6版本
B、安裝Nagios-plugins
# yum install nagios-plugins
C、配置Nagios登錄用戶
# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
New password: nagiosadmin
Re-type new password: nagiosadmin
Adding password for user nagiosadmin
D、登錄web界面,檢查Nagios是否成功運行
# service httpd start
# service nagios start
訪問http://x.x.x.x//nagios(x.x.x.x為服務(wù)器ip地址)
出現(xiàn)以下畫面,表示nagios正常運行
五、安裝 Ndoutils
A、下載Ndoutils
# wget http://nchc.dl.sourceforge.net/sourceforge/nagios/ndoutils-1.4b7.tar.gz
B、安裝Ndoutils
# tar -zxvf ndoutils-1.4b7.tar.gz
# cd ndoutils-1.4b7
# ./configure --prefix=/usr/lib/nagios --enable-mysql --disable-pgsql --with-ndo2db-user=nagios--with-ndo2db-group=nagios
# make clean
# make
# cp config/ndomod.cfg /etc/nagios
# cp config/ndo2db.cfg /etc/nagios
# mkdir /usr/lib/nagios/bin
# cp src/ndomod-3x.o /usr/lib/nagios/bin/ndomod.o
# cp src/ndo2db-3x /usr/lib/nagios/bin/ndo2db
# cp src/log2ndo /usr/lib/nagios/bin/log2ndo
# cp src/sockdebug /usr/lib/nagios/bin/sockdebug
# cp src/file2sock /usr/lib/nagios/bin/file2sock
# vi /etc/nagios/nagios.cfg (更改如下所示)
broker_module=/usr/lib/nagios/bin/ndomod.o config_file=/etc/nagios/ndomod.cfg
event_broker_options=-1
# vi /etc/nagios/ndomod.cfg (更改如下所示)
output_type=tcpsocket
#output_type=unixsocket
output=127.0.0.1
#output=/usr/local/nagios/var/ndo.sock
buffer_file=/var/nagios/ndomod.tmp
# vi /etc/nagios/ndo2db.cfg (更改如下所示)
#socket_type=unix
socket_type=tcp
#socket_name=/usr/local/nagios/var/ndo.sock
db_servertype=mysql
db_name=ndo
db_user=ndouser
db_pass=ndopassword
debug_level=-1
debug_verbosity=2
debug_file=/var/log/nagios/ndo2db-debug.log
# touch /var/log/nagios/ndo2db-debug.log
# chown nagios.nagios /var/log/nagios/ndo2db-debug.log
C、設(shè)置NDO DB
# wget http://download.centreon.com/centreon/centreon-2.0.1.tar.gz
# tar -zxvf centreon-2.0.1.tar.gz
# cd centreon-2.0.1
# service mysqld start
# mysql -u root -p (密碼為空,可以通過mysqladmin -u root -p 'password'來設(shè)置一個密碼)
mysql> CREATE DATABASE `ndo` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql>exit;
# mysql -u root -p ndo < /$centreon-2.0.1-path$/www/install/createNDODB.sql
# mysql -u root -p
mysql> GRANT SELECT , INSERT , UPDATE , DELETE ON `ndo` . * TO 'ndouser'@'localhost' IDENTIFIED BY 'ndopassword';
mysql>flush privileges;
mysql>exit;
D、設(shè)置NDO2DB服務(wù)
# vi /etc/init.d/ndo2db
#!/bin/sh
#
#
# chkconfig: 345 99 01
# description: Nagios to mysql
#
# Author : Ga?tan Lucas
# Realase : 07/02/08
# Version : 0.1 b
# File : ndo2db
# Description: Starts and stops the Ndo2db daemon
# used to provide network services status in a database.
#
status_ndo ()
{
if ps -p $NdoPID > /dev/null 2>&1; then
return 0
else
return 1
fi
return 1
}
printstatus_ndo()
{
if status_ndo $1 $2; then
echo "ndo (pid $NdoPID) is running..."
else
echo "ndo is not running"
fi
}
killproc_ndo ()
{
echo "kill $2 $NdoPID"
kill $2 $NdoPID
}
pid_ndo ()
{
if test ! -f $NdoRunFile; then
echo "No lock file found in $NdoRunFile"
echo -n " checking runing process..."
NdoPID=`ps h -C ndo2db -o pid`
if [ -z "$NdoPID" ]; then
echo " No ndo2db process found"
exit 1
else
echo " found process pid: $NdoPID"
echo -n " reinit $NdoRunFile ..."
touch $NdoRunFile
chown $NdoUser:$NdoGroup $NdoRunFile
echo "$NdoPID" > $NdoRunFile
echo " done"
fi
fi
NdoPID=`head $NdoRunFile`
}
# Source function library
# Solaris doesn't have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
prefix=/usr/lib/nagios
exec_prefix=${prefix}
NdoBin=/usr/lib/nagios/bin/ndo2db
NdoCfgFile=/etc/nagios/ndo2db.cfg
NdoRunFile=/var/nagios/ndo2db.run
NdoLockDir=/var/lock/subsys
NdoLockFile=ndo2db.lock
NdoUser=nagios
NdoGroup=nagios
# Check that ndo exists.
if [ ! -f $NdoBin ]; then
echo "Executable file $NdoBin not found. Exiting."
exit 1
fi
# Check that ndo.cfg exists.
if [ ! -f $NdoCfgFile ]; then
echo "Configuration file $NdoCfgFile not found. Exiting."
exit 1
fi
# See how we were called.
case "$1" in
start)
echo -n "Starting ndo:"
touch $NdoRunFile
chown $NdoUser:$NdoGroup $NdoRunFile
daemon $NdoBin -c $NdoCfgFile
if [ -d $NdoLockDir ]; then
touch $NdoLockDir/$NdoLockFile;
fi
ps h -C ndo2db -o pid > $NdoRunFile
if [ $? -eq 0 ]; then
echo " done."
exit 0
else
echo " failed."
$0 stop
exit 1
fi
;;
stop)
echo -n "Stopping ndo: "
pid_ndo
killproc_ndo
# now we have to wait for ndo to exit and remove its
# own NdoRunFile, otherwise a following "start" could
# happen, and then the exiting ndo will remove the
# new NdoRunFile, allowing multiple ndo daemons
# to (sooner or later) run
#echo -n 'Waiting for ndo to exit .'
for i in 1 2 3 4 5 6 7 8 9 10 ; do
if status_ndo > /dev/null; then
echo -n '.'
sleep 1
else
break
fi
done
if status_ndo > /dev/null; then
echo
echo 'Warning - ndo did not exit in a timely manner'
else
echo 'done.'
fi
rm -f $NdoRunFile $NdoLockDir/$NdoLockFile
;;
status)
pid_ndo
printstatus_ndo ndo
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: ndo {start|stop|restart|status}"
exit 1
;;
esac
# End of this script
接著:
# chmod 755 /etc/init.d/ndo2db
# chkconfig --level 345 ndo2db on
# mv /etc/rc3.d/S99ndo2db /etc/rc3.d/S97ndo2db
# mv /etc/rc5.d/S99ndo2db /etc/rc5.d/S97ndo2db
# service nagios stop ## 必須先停止Nagios服務(wù)
# service ndo2db start
驗證ndo2db TCP端口是否打開:
# netstat -tl (如下圖紅框所示)
# service nagios start
# tail -f /var/log/nagios/nagios.log
# visudo (更改如下所示)
# Defaults requiretty
重新確定PHP-PEAR能正常更新
B、執(zhí)行Centreon安裝腳本
# ./install.sh –i
Centreon安裝完成后,你可以通過http://yourServerIPAddress/centreon來訪問