Chinaunix

标题: 在CentOS 5.2上安装Nagios 3.06+Centreon 2.0.1 (二) [打印本页]

作者: samuelshi    时间: 2009-03-13 17:58
标题: 在CentOS 5.2上安装Nagios 3.06+Centreon 2.0.1 (二)

                                                                   五、安装 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、设置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'来设置一个密码)
  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、设置NDO2DB服务
# 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服务
# service ndo2db start
验证ndo2db TCP端口是否打开:
# netstat -tl (如下图红框所示)

# service nagios start
# tail -f /var/log/nagios/nagios.log

必须有如红框所示信息,表示ndo2db安装启动成功。

      
      
      

               
               
               
               
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93504/showart_1862376.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2