CentOS5.5X64安装配置Nagios监控

 

  
  
  
  
  1. 通过整合pnp4nagios,ndoutils,nconf提供了关于nagios的一套完整的配置方案
  2. 操作系统Centos5.5
  3. 目前nagios最新版本的nagios3.4.1
  4. 首先把编译环境准备好,我们这里把开发库先都装上
  5. yum groupinstall "Development Libraries" "Development Tools" "Legacy Software Development"
  6. "X Software Development" -y
  7. 相关依赖包
  8. yum -y install  mysql perl mysql-server perl-DBI perl-DBD-MySQL httpd gcc glibc glibc-common gd gd-devel ruby
  9. ruby-devel2 ruby-devel mysql-devel libpng libpng-devel libjpeg libjpeg-devel zlib zlib-devel
  10. yum默认安装的是5.1版本的php,但是pnp4nagios-0.6.6需要5.2以上版本的php,我们这里就装5.3的
  11. yum search php 看看有没有php53相关的包,没有请配置好相关的源
  12. yum install php53-*
  13. 准备如下软件包
    -rw-r--r-- 1 root root  1782817 Jul  9 08:45 nagios-3.4.1.tar.gz
    -rw-r--r-- 1 root root  2087089 Jul  9 14:36 nagios-plugins-1.4.16.tar.gz
    -rw-r--r-- 1 root root   491706 Jul  6 14:40 nconf-1.3.0-0.tgz
    -rw-r--r-- 1 root root  2135521 Jul  6 14:42 ndoutils-1.4b9.tar.gz
    -rw-r--r-- 1 root root   405725 Dec 14  2011 nrpe-2.12.tar.gz
    -rw-r--r-- 1 root root  2815857 Sep 15  2011 pnp4nagios-0.6.15.tar.gz
    -rw-r--r-- 1 root root  2135521 Jul  6 14:42 ndoutils1.4b9_light.patch
  14. 建立相关用户和组
  15. useradd -m nagios
    groupadd nagcmd
    usermod -a -G nagcmd nagios
    usermod -a -G apache nagios
  16. 安装nagios
  17. tar zxvf nagios-3.4.1.tar.gz -C /usr/src
    cd /usr/src/nagios-3.4.1
    ./configure  --prefix=/usr/local/nagios --with-command-group=nagcmd
  18. --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
  19. make all
    make install
    make install-init
    make install-commandmode
    make install-config
    make install-webconf
  20. 生成web管理界面用户和密码
  21. htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  //登录nagios web界面时的
  22. 用户为nagiosadmin 下面输入的密码为此用户密码
  23. chkconfig --add nagios
    chkconfig nagios on
    chkconfig httpd on
    chkconfig mysqld on
  24. 安装插件
  25. tar zxvf nagios-plugins-1.4.16.tar.gz -C /usr/src
    cd /usr/src/nagios-plugins-1.4.16
    ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
    make
    make install
  26. service nagios start
    service httpd start
    service mysqld start

  27. 使用http://localhost/nagios/来访问
  28. 点开service会看到本机的httpd服务有个告警,并提示HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.002
  29. second response time
  30. 修改下面的配置文件即可消除错误
  31. vim /usr/local/nagios/etc/objects/localhost.cfg
  32. define service{
    use local-service ; Name of service template to use
    host_name localhost
    service_description HTTP
    check_command check_http
    notifications_enabled 1    #######此处改为1
  33. define service{
    use local-service ; Name of service template to use
    host_name localhost
    service_description SSH
    check_command check_ssh
    notifications_enabled 1    ########此处改为1
    }
  34. 提示HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.002 second response time是因为在目前网站根目录下面没
  35. 有首页文件,可自己建立一个index.html的文件放在/var/www/html/下面,如果是源码安装的请放在定义的网站根下面。
  36. 重启Nagios和httpd服务刷新页面即可
  37. ################################################################################################################
  38. pnp4nagios的安装和配置,能够把nagios捕获到的数据绘制成图片
  39. 安装前准备
  40. yum install rrdtool-perl rrdtool-devel rrdtool
  41. tar zxvf pnp4nagios-0.6.15.tar.gz -C /usr/src
    cd /usr/src/pnp4nagios-0.6.15
    ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
    make all
    make install
    make install-webconf
    make install-config
    make isntall-init
    make fullinstall
  42. pnp4nagios官方提供了三种配置方法,我这里选取一种
    vi /usr/local/nagios/etc/nagios.cfg

  43. process_performance_data=1  //此处修改为1
  44. 添加如下行
  45. #
    # service performance data
    #
    service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
    service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::
  46. $SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::
  47. $HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
    service_perfdata_file_mode=a
    service_perfdata_file_processing_interval=15
    service_perfdata_file_processing_command=process-service-perfdata-file
     
    #
    # host performance data starting with Nagios 3.0
    #
    host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
    host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::
  48. $HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
    host_perfdata_file_mode=a
    host_perfdata_file_processing_interval=15
    host_perfdata_file_processing_command=process-host-perfdata-file

  49. vi /usr/local/nagios/etc/objects/commands.cfg 修改最后两行为
  50. define command{
           command_name    process-service-perfdata-file
           command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --
  51. bulk=/usr/local/pnp4nagios/var/service-perfdata
    }
    define command{
           command_name    process-host-perfdata-file
           command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-
  52. perfdata
    }
    cd /usr/local/pnp4nagios/share
    mv install.php install.php.bak
  53. 访问测试 http://localhost/pnp4nagios
  54. ############################################################################
  55. 让nagios显示小太阳图标
    在pnp4nagios的源码包下面执行
  56. cp contrib/ssi/* /usr/local/nagios/share/ssi/
  57. 然后在服务或者主机定义里面添加action_url
  58. #vi /usr/local/nagios/etc/objects/templates.cfg
  59. define host{
            use                     linux-server          
            host_name               localhost
            alias                   localhost
            address                 127.0.0.1
            action_url              /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips'
  60. rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_                       //添加此行
            }
  61. define service{
            use                             local-service         ; Name of service template to use
            host_name                       localhost
            service_description             PING
            check_command                   check_ping!100.0,20%!500.0,60%
            action_url                      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$'
  62. class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$       //添加此行
            }
  63. 此时在web界面的ping旁边会显示一个小的图标,把鼠标放上去会放大

  64. ########################################################################################################
  65. 安装nconf实现nagios的图形化配置,可以直接在web界面操作,不用去编辑配置文件
  66. tar zxvf nconf-1.3.0-0.tgz -C /var/www/html/
    chown -R apache.apache /var/www/html/nconf/
  67. 为nconf创建数据库,默认Mysql安装后没有密码,后面要用到密码,这里提前设置一个密码
  68. mysqladmin -u root password "p@ssw0rd"
  69. mysql -u root -p
  70. create database nconf;
  71. grant all privileges on nconf.* to 'nconf'@localhost identified by 'nconf' with grant option;

  72. cp /usr/local/nagios/bin/nagios /var/www/html/nconf/bin
  73. chown apache.nagios /var/www/html/nconf/bin/nagios
  74. 然后通过浏览器访问: http://localhost/nconf
  75. 按照提示安装,并输入上面创建的数据库和用户及密码
  76. 根据提示进行安装 然后删除/var/www/html/nconf/下面的 INSTALL/  INSTALL.php  UPDATE/  UPDATE.php重新刷新页面就可以
  77. 使用了!
  78. 如果用WEB配置时提示mysql、nconf错误时,可手工设置/var/www/html/nconf/config下的mysql.php与nconf.php文件
  79. 把mysql.php里的相应相应项做更改,如:
  80. define('DBHOST', "localhost"); 
    define('DBNAME', "nconf");
    define('DBUSER', "nconf");
    define('DBPASS', "nconf");

  81.  
  82. nconf.php文件:
  83. define('NCONFDIR',     "/var/www/html/nconf");
  84. define('NAGIOS_BIN',   "/var/www/html/nconf/bin/nagios");
  85.  
  86. 如要做Nconf认证,使用file认证类型 //web配置时如果使用认证才可以配置,那么先按照如下配置再进行
  87. 修改/var/www/html/nconf/config/authentication.php如下:
  88. define('AUTH_ENABLED', '1');
  89.  
  90. 此时默认帐号是admin,密码nconf,具体可见/var/www/html/nconf/include/login_check.php
  91. 及/var/www/html/nconf/./index.php
  92. 帐号密码保存在/var/www/html/nconf/config/.file_accounts.php文件中,帐号密码格式如下
  93. #username::password::authorization(user|admin)::[user's full name (optional)]::
    admin::nconf::admin::Administrator::
  94. 然后再打开http://localhost/nconf,此时跟前面的会不一样,全部下一步就好,最好提示删除INSTALL/ INSTALL.php UPDATE/
  95. UPDATE.php,照做就行

  96. ###############################################################################################################
  97. 安装配置ndoutils把nagios的数据导入mysql数据库
    mysql -u root -p
    mysql>CREATE DATABASE nagios;
    mysql>GRANT ALL ON nagios.* TO 'nagios'@localhost IDENTIFIED BY ‘nagios’     #授权nagios用户,密码为 nagios
    mysql>FLUSH PRIVILEGES;

  98. wget http://prdownloads.sourceforge.net/sourceforge/nagios/ndoutils-1.4b9.tar.gz
    wget http://svn.centreon.com/trunk/ndoutils-patch/ndoutils1.4b9_light.patch
  99. tar zxvf ndoutils-1.4b9.tar.gz /usr/src
    cd /usr/src/ndoutils-1.4b9
  100. 把补丁包放在/usr/src/ndoutils-1.4b9目录下面
  101. patch -p1 -N < ndoutils1.4b9_light.patch
    提示补丁成功打上
  102. ./configure --prefix=/usr/local/nagios/ --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-
  103. group=nagios
    make
    cd db/
    ./installdb -u root -p 数据库密码 -d nagios

  104. mysql -u root -p
  105. mysql>USE nagios;
    mysql>SHOW TABLES; //查看验证表已经生成
  106. cd ndoutils-1.4b9
  107.  cp ./src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
     cp ./src/ndo2db-3x /usr/local/nagios/bin/ndo2db
     cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
     cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
     chmod 774 /usr/local/nagios/bin/ndo*
     chown nagios:nagios /usr/local/nagios/bin/ndo*
     chown nagios:nagios /usr/local/nagios/etc/ndo*
    vi ndo2db.cfg
    db_name=nagios
    db_user=nagios //修改为nagios
    db_pass=nagios //修改为nagios
  108. vi /usr/local/nagios/etc/nagios.cfg
  109. 添加以下行
  110. broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
  111. cp ./daemon-init /etc/init.d/ndo2db
    chmod +x /etc/init.d/ndo2db
    chkconfig --add ndo2db
    service nagios restart
  112. 如果启动失败使用命令检查,看看是什么地方出错,并修正
  113. /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

  114. service ndo2db start
  115. tail -f /usr/local/nagios/var/nagios.log
  116. [root@test ndoutils-1.4b9]# cat /usr/local/nagios/var/nagios.log                           
    [1345086976] Nagios 3.4.1 starting... (PID=22899)
    [1345086976] Local time is Thu Aug 16 11:16:16 CST 2012
    [1345086976] LOG VERSION: 2.0
    [1345086976] Finished daemonizing... (New PID=22900)
    [1345088085] Finished daemonizing... (New PID=27417)
    [1345088175] SERVICE ALERT: localhost;HTTP;OK;HARD;4;HTTP OK: HTTP/1.1 200 OK - 302 bytes in 0.001 second
  117. response time
    [1345089958] Caught SIGTERM, shutting down...
    [1345089958] Successfully shutdown... (PID=27417)
    [1345089958] Nagios 3.4.1 starting... (PID=8993)
    [1345089958] Local time is Thu Aug 16 12:05:58 CST 2012
    [1345090128] LOG VERSION: 2.0
    [1345090128] ndomod: NDOMOD-MERETHIS 1.4b9-merethis (10-27-2009) Copyright (c) 2009 Nagios Core Development Team
  118. and Community Contributors
    [1345090128] ndomod: Successfully connected to data sink.  0 queued items to flush.
    [1345090128] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.  //初始化成功
    [1345090128] Finished daemonizing... (New PID=9360)
  119. 二、php session权限问题
  120. 访问pnp4nagios时有
  121. An error was detected which prevented the loading of this page. If this problem persists, please contact the
  122. website administrator.
  123. /usr/local/pnp4nagios/lib/kohana/system/libraries/Session.php [160]:
  124. session_start(): open(/var/lib/php/sess_d1suf0cpph46v95efp1b7l0cbtt0q7nr, O_RDWR) failed: Permission denied (13)
  125. 错误
  126. 检查 /var/lib/php5目录的权限,发现原来是root才可以读写,而apache采用了nagios的用户来运行,所以php的session数据没
  127. 有权限写入,于是更改/var/lib/php的写入权限
    chown -R nagios.nagios /var/lib/php       或
    chown -R 777 /var/lib/php
  128.  
  129. ---------------------------------------------出自运维联盟-----------------------------------------

 

你可能感兴趣的:(centos,监控,nagios)