现在开源界用得比较多的两款监控软件就是NAGIOS/CACTI,下面笔者全面讲解二者的安装与整合,其实网上这类文件也比较多,但是都比较零散,对于新手来说搭建起来很容易出问题,本人发一篇完全适合新手的教程!关于二者的差别,废话不多说!!


系统初使化软件库安装:

  1. yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel


-----------------------------------------------第一部分:nagios------------------------------------------

所有软件包都放在:/usr/local/src 或其它位置!  (养成好的习惯!!)


一、安装Nagios必须的基本组件的运行依赖于httpd、mysql、gd以及编译用到的gcc

  1. yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel openssl-devel

二、创建运行nagios的用户和组

  1. groupadd nagcmd  

  2. useradd -M nagios  

  3. usermod -a -G nagcmd nagios  

  4. usermod -a -G nagcmd apache  

  5. usermod -G nagios apache

三、安装nagios

  1. cd /usr/local/src  

  2. tar zxvf nagios-3.3.1.tar.gz  

  3. cd nagios  

  4. mkdir /usr/local/nagios  

  5. chown -R nagios:nagios /usr/local/nagios  

  6. ./configure --prefix=/usr/local/nagios  

  7. make all    

  8. make install    

  9. make install-init    

  10. make install-config    

  11. make install-commandmode    

  12. make install-webconf

创建认证用户:

  1. htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

PS: 此处用户名尽量使用默认nagiosadmin,否则就需要修改cgi.cfg文件中所有关于认证选项的用户.
启动apache
service httpd restart
这里你可以修改下apache配置文件的ServerName ,不然每次启动都非常慢!!!这个可以改成你的IP!

四、安装nagios-pugins插件
安装nagios常规插件

  1. cd ..  

  2. tar zxvf nagios-plugins-1.4.15.tar.gz  

  3. cd nagios-plugins-1.4.15  

  4. ./configure --prefix=/usr/local/nagios  

  5. make;make install

安装nagios-snmp-plugins插件

  1. wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz

  2. 安装这个插件要装几个perl模块:  

  3. Crypt::DES  

  4. Digest::MD5  

  5. Digest::SHA1  

  6. Digest::HMAC  

  7. Net::SNMP  

  8. 到www.cpan.org上下载!!  

  9. 下面安装这几个模块(最后安装Net::SNMP这个模块):  

  10. tar zxvf Crypt-DES-2.05.tar.gz  

  11. cd Crypt-DES-2.05  

  12. perl Makefile.PL  

  13. make;make install  

  14. cd ..  

  15. gunzip Digest-HMAC-1.03.tar.gz  

  16. tar xvf Digest-HMAC-1.03.tar  

  17. cd Digest-HMAC-1.03    

  18. perl Makefile.PL    

  19. make;make install    

  20. cd ..  

  21. tar zxvf Digest-MD5-2.51.tar.gz    

  22. cd Digest-MD5-2.51    

  23. perl Makefile.PL    

  24. make ;make install    

  25. cd ..  

  26. tar zxvf Digest-SHA1-2.13.tar.gz    

  27. cd Digest-SHA1-2.13    

  28. perl Makefile.PL    

  29. make;make install    

  30. cd ..  

  31. gunzip Net-SNMP-v6.0.1.tar.gz    

  32. tar xvf Net-SNMP-v6.0.1.tar    

  33. cd Net-SNMP-v6.0.1    

  34. perl Makefile.PL    

  35. make;make install  

  36. 现在开始安装nagios-snmp-plugins插件:  

  37. tar zxvf nagios-snmp-plugins.1.1.1.tgz  

  38. cd nagios_plugins  

  39. ./install.sh  

  40. 运行后一路回车!!!!!!!!!!!!!!!

PS: 我们也不必去cpan.org下载包下来进行安装,这里最简单的方法就是在shell命令行输入:perl -MCPAN -e shell
进入如 cpan> install nagios-snmp-plugins  来进行安装!不过有时这样不一定能安装的上!最好两种方法结合起来用最好!

安装nagios中文插件(这个插件最好与nagios版本相同,我发现不同也没多大关系):

  1. cd /usr/local/src  

  2. tar jxvf nagios-cn-3.2.3.tar.bz2  

  3. cd nagios-cn-3.2.2  

  4. ./configure  

  5. make all;make install  

  6. 把nagios加入到系统服务:  

  7. chkconfig --add nagios    

  8. chkconfig nagios on

指定nagios指令的path
vi /etc/profile
大文件最后加入:
export PATH=$PATH:/usr/local/nagios/bin
再用 source /etc/profile 直接生效!

检查配置文件:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

PS: 检查配置文件只要配置文件中没有error配置就正常,有警告没关系!

chkconfig httpd on
chkconfig mysqld on
启动apache: service httpd start
启动mysqld: service mysqld start
启动nagios: service nagios start


五、nagios性能分析图表_PNP插件

  1. yum install perl-Time-HiRes  

  2. 先安装rrdtool  

  3. 32位系统  

  4. wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm

  5. rpm -Uvh rpmforge-release-0.5.1-1.el5.rf.i386.rpm  

  6. yum -y install rrdtool  

  7. 64位系统  

  8. wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm

  9. rpm -Uvh rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm  

  10. yum -y install rrdtool  

  11. 1.安装PNP  

  12. tar zxvf pnp4nagios-0.6.16.tar.gz  

  13. cd pnp4nagios-0.6.16  

  14. ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/bin/rrdtool  

  15. make all  

  16. make install  

  17. make install-webconf  

  18. make install-config  

  19. make install-init  

  20. 2.配置PNP  

  21. cd /usr/local/pnp4nagios/etc  

  22. mv misccommands.cfg-sample  misccommands.cfg  

  23. mv nagios.cfg-sample  nagios.cfg  

  24. mv rra.cfg-sample rra.cfg  

  25. cd pages  

  26. mv web_traffic.cfg-sample web_traffic.cfg  

  27. cd ../check_commands  

  28. mv check_all_local_disks.cfg-sample  check_all_local_disks.cfg  

  29. mv check_nrpe.cfg-sample  check_nrpe.cfg  

  30. mv check_nwstat.cfg-sample  check_nwstat.cfg  

  31. service npcd start  

  32. 3.修改 nagios 的配置文件,打开performance_data  

  33. cd /usr/local/nagios/etc  

  34. vi nagios.cfg  

  35. process_performance_data=1   //把0变成1,启动nagios的数据输出功能,这样nagios将收集的数据写入到某个文件当中,以备提取!

  36. host_perfdata_command=process-host-perfdata        //启用主机的数据输出功能

  37. service_perfdata_command=process-service-perfdata  //启用服务的数据输出功能

  38. 4.修改 commands.cfg  

  39. cd /usr/local/nagios/etc/objects  

  40. vim commands.cfg  

  41. 把默认的process-host-perfdata和process-service-perfdata 删除掉或注释掉,添加如下内容:

  42. # 'process-host-perfdata' command definition

  43. define command{  

  44.        command_name    process-host-perfdata  

  45.        command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl  

  46.        }

  47. # 'process-service-perfdata' command definition

  48. define command{  

  49.        command_name    process-service-perfdata  

  50.        command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl  

  51.        }  

  52. 5.添加模板  

  53. vim templates.cfg  

  54. 在配置文件最后添加  

  55. define host {  

  56. name       hosts-pnp  

  57. action_url /pnp4nagios/graph?host=$HOSTNAME$&  

  58. register   0  

  59. }  

  60. define service {  

  61. name       services-pnp  

  62. action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$  

  63. register   0  

  64. }  

  65. 6.最后在各服务器的hosts和services处添加hosts-pnp、services-pnp  

  66. 如:  

  67. define host{  

  68.        use               linux-server,hosts-pnp    

  69.        host_name         andy.com  

  70.        alias             andy_web.com  

  71.        address           192.168.1.101  

  72.        }  

  73. define service{  

  74.        use                        local-service,services-pnp        

  75.        host_name                  andy.com  

  76.        service_description        PING  

  77.        check_command              check_ping!100.0,20%!500.0,60%  

  78. }  

  79. 7.重启nagios  

  80. /etc/init.d/nagios restart


六、Nconf的安装与配置(可选性安装,我这里只是介绍下安装与配置过程 )

  1. 1.nconf的准备工作  

  2. mysql -uroot -p  

  3. mysql> create database nconf;  

  4. mysql> grant all privileges on nconf.* to nconf@"%" identified by 'nconf';  

  5. mysql> flush privileges;  

  6. mysql> quit  

  7. 2.安装nconf  

  8. 下载: http://sourceforge.net/projects/nconf/files/nconf/

  9. tar nconf-1.3.0-0.tgz  

  10. mv nconf /usr/local  

  11. chown -R apache:apache /usr/local/nconf  

  12. 3.在apache添加nconf目录虚拟主机  

  13. vi /etc/httpd/conf.d/nconf.conf  

  14. 加入如下内容:  

  15. <VirtualHost *:80>  

  16. DocumentRoot /usr/local  

  17. ServerName 192.168.1.151  

  18. </VirtualHost>  

  19. 重启apache  

  20. service httpd restart  

  21. 4.进入Web页面在按照安装提示一步步安装---比较简单!!  

  22. 5.使用上面建立的数据库和用户(nconf)成功连接mysql数据库,之后一切保持默认,直到下面认证设置时选择"ture",再设置nconf管理员密码,默认登录用户为admin!  

  23. 6.安装完成之后,提示删除安装时的初始化文件  

  24. cd /usr/local/nconf  

  25. rm -rf INSTALL INSTALL.php UPDATE UPDATE.php  

  26. ln -s /usr/local/nagios/bin/nagios bin/nagios  

  27. chmod +x /usr/local/nconf/bin/generate_config.pl  

  28. chown -R apache.apache bin  

  29. chmod +x /usr/local/nagios/bin/nagios  

  30. chmod +x /usr/local/nconf/ADD-ONS/deploy_local.sh  

  31. 7.重新刷新页面,输入admin/您设置的密码,进入nconf页面  

  32. 8.点击Generate Nagios config尝试生成配置文件,以测试是否与nagios成功关联  

  33. deploy_local.sh是nconf自带配置文件导入脚本  

  34. /usr/local/nconf/ADD-ONS/deploy_local.sh  

  35. 手动执行此脚本,将在/usr/local/nagios/etc下生成两目录Default_collector与global  

  36. 修改nagios主配置文件  

  37. vim /usr/local/nagios/etc/nagios.cfg

  38. # 将其中cfg_file=*******字段全部注释 ,并加入

  39. cfg_dir=/usr/local/nagios/etc/Default_collector  

  40. cfg_dir=/usr/local/nagios/etc/global  

  41. service nagios reload

  42. # 重载nagios配置文件使之生效


------------------------------------------------第二部分:nagios配置文件分配问题---------------------------------------
配置文件的规划--有两种常规方案

  1. 方案一:根据主机服务分开,主机一个独立配置文件,服务一个对应配置文件  

  2. 系统文件统一放在objects目录下:  

  3. commands.cfg  localhost.cfg  timeperiods.cfg  contacts.cfg  templates.cfg  

  4. 主机目录:建立hosts目录存放主机  

  5. 服务目录:建立services目录存放服务  

  6. 命令目录:建立commands目录存放命令  

  7. 在nagios.cfg配置文件中修改相应地方如下:  

  8. cfg_file=/usr/local/nagios/etc/objects/commands.cfg  

  9. cfg_file=/usr/local/nagios/etc/objects/contacts.cfg  

  10. cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg  

  11. cfg_file=/usr/local/nagios/etc/objects/templates.cfg  

  12. cfg_file=/usr/local/nagios/etc/objects/localhost.cfg  

  13. cfg_dir=/usr/local/nagios/etc/services  

  14. cfg_dir=/usr/local/nagios/etc/hosts  

  15. cfg_dir=/usr/local/nagios/etc/commands  

  16. 方案二:每个服务器独立配置文件  

  17. 系统文件统一放在objects目录下:  

  18. commands.cfg  localhost.cfg  timeperiods.cfg  contacts.cfg  templates.cfg  

  19. 第个被监控服务器独立一个配置文件:  

  20. 如:192.168.1.100.cfg  

  21. 在配置文件中修改相应地方如下:  

  22. cfg_file=/usr/local/nagios/etc/objects/commands.cfg  

  23. cfg_file=/usr/local/nagios/etc/objects/contacts.cfg  

  24. cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg  

  25. cfg_file=/usr/local/nagios/etc/objects/templates.cfg  

  26. cfg_file=/usr/local/nagios/etc/objects/localhost.cfg  

  27. cfg_file=/usr/local/nagios/etc/linux_srv/192.168.1.100.cfg  

  28. ...  

  29. ...  

  30. ...  

  31. cfg_file=/usr/local/nagios/etc/linux_srv/192.168.1.110.cfg  

  32. 根据情况自己做选择!!


一、配置监控Linux主机实例

1.安装nagios-plugins插件

  1. tar zxvf nagios-plugins-1.4.15.tar.gz  

  2. cd nagios-plugins-1.4.15  

  3. ./configure --prefix=/usr/local/nagios  

  4. make;make install

2.监控linux时是通过nrpe来建立连接,所以要在服务端和客户端先安装上pcre
服务端的安装:

  1. wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz/download tar zxf nrpe-2.13.tar.gz cd nrpe-2.13 ./configure:make all:make install-plugin


  2. 测试插件与客户端是否正常通信  

  3. /usr/local/nagios/libexec/check_nrpe -H 192.168.8.30  

  4. NRPE v2.13  

  5. 说明之间是连通的!!  

  6. 定义check_nrpe监控命令  

  7. vi /usr/local/nagios/etc/objects/commands.cfg  

  8. 添加如下内容:

  9. # 'check_nrpe' command definition

  10. define command{  

  11.        command_name    check_nrpe  

  12.        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$  

  13.        }  

  14. 客户端的安装:  

  15. tar zxvf nrpe-2.13.tar.gz  

  16. cd nrpe-2.13  

  17. ./configure  

  18. make all  

  19. make install-plugin  

  20. make install-daemon  

  21. make install-daemon-config  

  22. 修改nrpe配置文件  

  23. vi /usr/local/nagios/etc/nrpe.cfg  

  24. 找到下面两处并修改成如下样子:  

  25. server_address=192.168.8.30    //这是客户端本身自己IP地址,这里一定要写真实IP

  26. allowed_hosts=192.168.8.130,127.0.0.1   //192.168.8.130是我的nagios监控机

  27. 启动nrpe  

  28. /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d  

  29. netstat -tunpl |grep 5566  

  30. lsof -i:5666


----------------------------------第三部分:cacti部分-----------------------------------------------------------
一、cacti服务器配置部分
++++++++++++++++++++++++++++++++++++++++++++++++++

  1. cacti安装与配置  

  2. 1.cacti绘图要用到rrdtool这个工具  

  3. 可以用源码安装,也可用yum来安装。。  

  4. rrdtool前面在安装nagios--pnp时已经装了,这里只说下  

  5. 这里介绍用yum来安装:  

  6. wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

  7. rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm  

  8. yum -y install rrdtool  

  9. 2.安装依赖包  

  10. 在主监控机上安装apache+php+gd的web环境,为了方便就用yum安装了!  

  11. yum -y install php php-devel php-mysql php-snmp mysql mysql-server net-snmp net-snmp-libs net-snmp-utils php-pdo perl-DBD-MySQL  

  12. 由于本机上同时装了nagios,所以这里php与mysql相关的软件包就不用装了!  

  13. yum -y install php-devel php-snmp  net-snmp net-snmp-libs net-snmp-utils  

  14. 3.配置snmp  

  15. vi /etc/snmp/snmp.conf

  16. #将下边这行中的default 改为127.0.0.1

  17. com2sec notConfigUser defaultpublic

  18. com2sec notConfigUser 127.0.0.1 public

  19. #将下边这行中的systemview 改为all

  20. access notConfigGroup "" any noauth exact systemview none none  

  21. access notConfigGroup "" any noauth exact all none none

  22. #将下边这行的注释“#”号去掉

  23. #view all included .1 80

  24. 启动snmpd服务  

  25. service snmpd start  

  26. 4.安装cacti  

  27. cd /usr/local/src/cacti  

  28. wget http://www.cacti.net/downloads/cacti-0.8.7h.tar.gz

  29. tar zxvf cacti-0.8.7h.tar.gz  

  30. mv cacti-0.8.7h /usr/local/cacti  

  31. 5.在数据库中建库、授权、导入数据库结构  

  32. 先启动mysql服务  

  33. service mysqld start

  34. #注意导入cacti.sql时该文件的路径

  35. mysql  

  36. mysql> create database cacti;  

  37. mysql> grant all privileges on cacti.* to cacti@localhost identified by 'cacti'with grant option;  

  38. mysql> grant all privileges on cacti.* to cacti@127.0.0.1 identified by 'cacti'with grant option;  

  39. mysql> use cacti;  

  40. mysql> source /usr/local/cacti/cacti.sql;  

  41. 配置cacti以连接数据库  

  42. vi /usr/local/cacti/include/config.php  

  43. 改成如下:  

  44. */  

  45. /* make sure these values refect your actual database/host/user/password */

  46. $database_type = "mysql";  

  47. $database_default = "cacti";  

  48. $database_hostname = "localhost";  

  49. $database_username = "cacti";  

  50. $database_password = "cacti";  

  51. $database_port = "3306";  

  52. /* Default session name - Session name must contain alpha characters */

  53. #$cacti_session_name = "Cacti";

  54. 保存退出!!  

  55. 同时也修改下 /usr/local/cacti/include/global.php  按以上形式修改.  

  56. 6.在apache中配置cacti的虚拟主机配置文件  

  57. vi /etc/http/conf.d/cacti.conf  

  58. 加入如下内容:  

  59. Alias /cacti "/usr/local/cacti"

  60. <Directory "/usr/local//cacti ">  

  61. Options FollowSymLinks MultiViews  

  62. AllowOverride None  

  63. Order allow,deny  

  64. Allow from all  

  65. </Directory>  

  66. 重新启动apache  

  67. service httpd restart  

  68. 7.浏览器进行cacti初使配置  

  69. 用浏览器打开 http://IP/cacti  #这里IP是cacti服务器的IP

  70. 这个很简单。。就不用说了!  

  71. 8.先手工生成图表  

  72. php /usr/local/cacti/poller.php  

  73. 创建任务计划  

  74. crontab -e  

  75. */1 * * * * php /usr/local/cacti/poller.php > /dev/null 2>&1  

  76. 确保 /usr/local/cacti/rra/目录存在  

  77. 过几分种后,我们打开cacti web监控页面,点击graphs ,就可以查看到cacti 监控本机的图表~~~


二、cacti常用插件安装

  1. cacti-plugin、npc、monitor、setting、thold、weathermap等。。。。  

  2. 1.先安装cacti扩展模块  

  3. cd /usr/local/src/cacti  

  4. wget http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7h-PA-v3.0.tar.gz

  5. tar xvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz  

  6. alias cp=cp  

  7. cp -R cacti-plugin-arch/* /usr/local/cacti/  

  8. cd /usr/local/cacti/  

  9. mysql -ucacti -pcacti cacti < pa.sql  

  10. patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff  

  11. PS:为cacti配置文件打补丁的时候有可能它将 include/config.php.dist给打补丁了!!  

  12. vi /usr/local/cacti/include/config.php  

  13. 加入此条语句:$url_path = "/cacti/"

  14. ......

  15. #$cacti_session_name = "Cacti";

  16. $url_path = "/cacti/";  

  17. .......  

  18. 打开插件管理功能:  

  19. 打开“Console----> User Management----> admin”然后在“Realm Permissions”选  

  20. 项卡中勾选“Plugin Management”,然后点击Save 进行保存!  

  21. 此时我们会在控制台---> Configuration 选项卡下多了一个Plugin Management 选项卡,到此cacti 架构扩展完成!!  

  22. 2.settings 安装  

  23. 可以到此站点下载:http://docs.cacti.net/plugin:settings

  24. tar zxvf settings-v0.71-1.tgz  

  25. mv settings /usr/local/cacti/plugins/  

  26. 回到web控制台:点击Console---> Plugin Management,我们看到多了一个settings 插件,然后点击蓝色向下箭头,再点击向右蓝色箭头启用!!  

  27. 再点击 Console ---> Settings 后我们会发现多了一个Mail/DNS 选项卡!  

  28. 在 cacti 配置文件中添加settings 插件:  

  29. vi /usr/local/cacti/include/config.php  

  30. $plugins[] = 'settings';  

  31. 3.Monitor 安装  

  32. 下载:http://docs.cacti.net/plugin:monitor

  33. tar zxvf monitor-v1.3-1.tgz  

  34. mv monitor /usr/local/cacti/plugins/  

  35. cd /usr/local/cacti/plugins/monitor/  

  36. mysql -ucacti -pcacti cacti < monitor.sql  

  37. 修改 cacti 配置文件,添加monitor 插件  

  38. vi /usr/local/cacti/include/config.php  

  39. 加入如下内容:  

  40. $plugins[] = 'monitor';  

  41. 启用方法同其它插件方法一样!!!!!!!!!!!!!!!!!  

  42. 4.thold 安装  

  43. 下载:http://docs.cacti.net/plugin:thold

  44. tar zxvf thold-v0\[1\].4.9-3.tgz  

  45. mv thold /usr/local/cacti/plugins/  

  46. 启用方法同其它插件方法一样!!!!!!!!!!!!!!!!!  

  47. 回到控制台,我们会发现多了一个“thold”选项  

  48. 打开“Console --->Settings”,发现多了一个“thresholds”选项卡  

  49. 5.Weathermap 安装  

  50. 下载:wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip

  51. unzip php-weathermap-0.97a.zip  

  52. mv weathermap /usr/local/cacti/plugins/  

  53. chmod -R 777 /usr/local/cacti/plugins/weathermap  

  54. 启用方法同其它插件方法一样!!!!!!!!!!!!!!!!!  

  55. 回到控制台,我们会发现多了一个“weathermap”选项!  

  56. 到此为止,几个常用插件安装完成!!!!!!!!!!!!!!  

  57. PS:其它大部分插件可以到这个网站下载:http://docs.cacti.net/plugins


----------------------------------第四部分:整合nagios与cacti---------------------------------------------------


整合cacti和nagios是利用了cacti的一个插件nagios for cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。

  1. 1.首先需要安装ndoutils以将nagios的数据能导入到mysql数据库中  

  2. yum -y install mysql-devel  

  3. 下载并安装ndoutils  

  4. wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz/download

  5. tar zxvf ndoutils-1.4b9.tar.gz  

  6. cd ndoutils-1.4b9  

  7. ./configure --prefix=/usr/local/nagios LDFLAGS=-L/usr/lib64 --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios  

  8. make  

  9. 2.建立配置文件  

  10. cp src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin  

  11. cd db  

  12. ./installdb -ucacti -pcacti -d cacti  

  13. cd ..  

  14. cp config/{ndo2db.cfg-sample,ndomod.cfg-sample} /usr/local/nagios/etc  

  15. mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg  

  16. mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg  

  17. chmod 644 /usr/local/nagios/etc/ndo*  

  18. chown nagios:nagios /usr/local/nagios/etc/*  

  19. chown nagios:nagios /usr/local/nagios/bin/*  

  20. 3.修改nagios.cfg配置文件以适应当前环境  

  21. vi /usr/local/nagios/etc/nagios.cfg  

  22. 在文件中添加如下内容:  

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

  24. 4.修改ndo2db.cfg以适应当前环境  

  25. vi /usr/local/nagios/etc/ndo2db.cfg  

  26. 把与下面相关的参数修改成如下形式(有此不用改):  

  27. socket_type=tcp  

  28. db_servertype=mysql  

  29. db_host=localhost  

  30. db_port=3306  

  31. db_name=cacti  

  32. db_prefix=nagios_  

  33. db_user=cacti  

  34. db_pass=cacti  

  35. 5.修改ndomod.cfg以适应当前环境  

  36. vi /usr/local/nagios/etc/ndomod.cfg  

  37. 把与下面相关的参数修改成如下形式:  

  38. output_type=tcpsocket  

  39. output=127.0.0.1  

  40. 6.让ndo2db开机启动  

  41. 方法一:  

  42. 加入到开机启动配置文件:  

  43. echo 'rm -f /usr/local/nagios/var/ndo.sock' >> /etc/rc.local  

  44. echo '/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg' >> /etc/rc.local  

  45. 方法二:  

  46. cd /usr/local/src/ndoutils-1.4b9  

  47. cp ./daemon-init /etc/init.d/ndo2db  

  48. vi /etc/init.d/ndo2db  

  49. 把Ndo2dbBin=/usr/local/nagios/bin/ndo2db改成  

  50. Ndo2dbBin=/usr/local/nagios/bin/ndo2db-3x  

  51. chmod +x /etc/init.d/ndo2db  

  52. service ndo2db start  

  53. 启动时出现如下错误:  

  54. Starting ndo2db:Support for the specified database server is either not yet supported, or was not found on your system.  

  55. done.  

  56. 这个是由于没有安装mysql-devel这个包造成的@!@@@@  

  57. 解决办法:  

  58. yum -y install mysql-devel  

  59. ./configure --prefix=/usr/local/nagios LDFLAGS=-L/usr/lib64 --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios  

  60. make  

  61. alias cp=cp  

  62. cp src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin  

  63. alias cp="cp -i'  

  64. 7..npc安装  

  65. tar zxvf npc-2.0.4.tar.gz  

  66. mv npc /usr/local/cacti/plugins/  

  67. 修改 cacti 配置文件,添加npc 插件  

  68. vi /usr/local/cacti/include/config.php  

  69. 加入:  

  70. $plugins[] = 'npc';  

  71. 启用方法同其它插件方法一样!!!!!!!!!!!!!!!!!  

  72. 回到控制台,我们会发现多了一个“npc”选项  

  73. 安装 npc支持:json  

  74. wget http://pecl.php.net/get/json-1.2.1.tgz

  75. tar zxvf json-1.2.1.tgz  

  76. cd json-1.2.1  

  77. phpize  

  78. ./configure ;make ;make install  

  79. 查看是否安装成功:  

  80. root@nagios_cacti json-1.2.1]# ll /usr/lib64/php/modules  

  81. 总计 840  

  82. -rwxr-xr-x 1 root root  32344 2010-01-14 dbase.so  

  83. -rwxr-xr-x 1 root root 337768 2010-01-14 gd.so  

  84. -rwxr-xr-x 1 root root  92798 03-14 06:05 json.so  

  85. -rwxr-xr-x 1 root root 119568 2010-01-14 mysqli.so  

  86. -rwxr-xr-x 1 root root  53008 2010-01-14 mysql.so  

  87. -rwxr-xr-x 1 root root  28264 2010-01-14 pdo_mysql.so  

  88. -rwxr-xr-x 1 root root  92464 2010-01-14 pdo.so  

  89. -rwxr-xr-x 1 root root  24200 2010-01-14 pdo_sqlite.so  

  90. -rwxr-xr-x 1 root root  15416 2009-09-04 phpcups.so  

  91. -rwxr-xr-x 1 root root  28568 2010-01-14 snmp.so  

  92. 修改php.ini文件添加对json的支持  

  93. vi /etc/php.ini  

  94. 添加如下内容:  

  95. extension=json.so  

  96. 重新启动apache  

  97. service httpd restart  

  98. 查看是否加载了这个模块:  

  99. php -m |grep json  

  100. 接着在右侧栏目中选择settings,点选npc的标签  

  101. 钩选Remote Commands  

  102. Nagios Command File Path: /usr/local/nagios/var/rw/nagios.cmd  

  103. <这个文件启动nagios后会产生,根据实际的位置写>  

  104. Nagios URL: http://IP/nagios/  (这里ip为nagios服务器IP)

  105. 保存就可以了。

------------------------------------------------------------------------------------------


附:linux客户端通用配置

在被监控的linux主机上安装net-snmp
yum -y install net-snmp
vi /etc/snmp/snmpd.conf
将下边这行中的default 改为192.168.1.151 (cacti服务器的IP地址)
com2sec notConfigUser default public

com2secnotConfigUser 172.28.12.36 public
将下边这行中的systemview改为all
access notConfigGroup "" any noauth exact systemview none none

access notConfigGroup "" any noauth exact all none none
将下边这行的注释“#”号去掉
#view all included .1 80

启动snmp
service snmpd start


这配置全是通用的,大家可以慢慢去尝试造!