Chinaunix首页 | 论坛 | 博客
  • 博客访问: 384114
  • 博文数量: 114
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1219
  • 用 户 组: 普通用户
  • 注册时间: 2015-02-07 21:23
文章分类

全部博文(114)

文章存档

2018年(1)

2017年(5)

2016年(87)

2015年(21)

我的朋友

分类: 系统运维

2016-01-16 14:41:24

系统信息:
Centos5.8x86
LAMP:yum方式安装
软件信息:
cacti-0.8.8a.tar.gz
cacti-plugin-0.8.7g-PA-v2.9.tar.gz
nrpe-2.14.tar.gz
rrdtool-1.4.8.tar.gz
nagios-3.5.0.tar.gz
nagios-plugins-1.4.16.tar.gz
ndoutils-1.5.2.tar.gz
npc-2.0.4.tar.gz
php-json-ext-1.2.1.tar.bz2
一、安装ndoutils

  1. [root@cacti-nagios ~]# wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz
  2. [root@cacti-nagios ~]# tar -zxvf ndoutils-1.5.2.tar.gz
  3. [root@cacti-nagios ~]# cd ndoutils-1.5.2
  4. [root@cacti-nagios ndoutils-1.5.2]# ./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql LDFLAGS=-L/usr/lib/mysql --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
  5. [root@cacti-nagios ndoutils-1.5.2]# make
  6. [root@cacti-nagios ndoutils-1.5.2]# cd src/
  7. [root@cacti-nagios src]# cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/local/nagios/bin/
  8. [root@cacti-nagios src]# cd ../config
  9. [root@cacti-nagios config]# cp ndo* /usr/local/nagios/etc/
  10. [root@cacti-nagios config]# cp /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
  11. [root@cacti-nagios config]# chown -R nagios.nagios /usr/local/nagios/
  12. [root@cacti-nagios config]# vi /usr/local/nagios/etc/ndo2db.cfg
  13. # :102行修改为cacti的数据库名
  14. db_name=cacti
  15. # :120行修改为cacti的数据库用户名
  16. db_user=cacti
  17. # :121行修改为cacti数据库用户密码
  18. db_pass=123456
  19. [root@cacti-nagios config]# cd ../db
  20. [root@cacti-nagios db]# ./installdb -ucacti -p123456 -hlocalhost -d cacti
  21. DBD::mysql::db do failed: Table 'cacti.nagios_dbversion' does not exist at ./installdb line 51.
  22. ** Creating tables for version 1.5.2
  23.      Using mysql.sql for installation...
  24. ** Updating table nagios_dbversion

  25. [root@cacti-nagios db]# vi /usr/local/nagios/etc/nagios.cfg
  26. # :220行确认
  27. event_broker_options=-1
  28. # :248行添加:
  29. broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

  30. [root@cacti-nagios db]# vi /usr/local/nagios/etc/ndomod.cfg
  31. output=/usr/local/nagios/var/ndo.sock

  32. 启动ndo2db
  33. [root@cacti-nagios ~]# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

  34. 将启动命令写入rc.local文件,实现开机自启动
  35. [root@cacti-nagios ~]# echo "/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg">>/etc/rc.local
  36. [root@cacti-nagios ~]# /etc/init.d/nagios restart
  37. Running configuration check...done.
  38. Stopping nagios: .done.
  39. Starting nagios: done.

  40. 查看nagios.log日志,启动正常无错误
  41. [root@cacti-nagios ~]# tail /usr/local/nagios/var/nagios.log
  42. [1373072388] Caught SIGTERM, shutting down...
  43. [1373072388] Successfully shutdown... (PID=5663)
  44. [1373072388] ndomod: Shutdown complete.
  45. [1373072388] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' deinitialized successfully.
  46. [1373072389] Nagios 3.5.0 starting... (PID=5755)
  47. [1373072389] Local time is Sat Jul 06 08:59:49 CST 2013
  48. [1373072389] LOG VERSION: 2.0
  49. [1373072389] ndomod: NDOMOD 1.5.2 (06-08-2012) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
  50. [1373072389] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
  51. [1373072389] Finished daemonizing... (New PID=5760)
二、安装配置NPC
1. 下载npc并解压

  1. [root@cacti-nagios ~]# wget http://sourceforge.net/projects/gibtmirdas/files/npc-2.0.4.tar.gz
  2. [root@cacti-nagios ~]# tar -zxvf npc-2.0.4.tar.gz
2. 将NPC移动到”cacti安装目录/plugins” 下,我的cacti安装在/var/www/html里

  1. [root@cacti-nagios ~]# mv npc /var/www/html/plugins/
3. 登录cacti,在Console—Plugin Management里,将NPC插件启用

4. 在Console—Settings—NPC里,填写相关信息

5. 启用后可以看到多了一个NPC选项卡,但是点击进去却是空白的
这是因为NPC需要php-json组件支持,但是服务器上却没安装导致
6. 安装php-json

  1. 安装php-json时需要先安装php-devel
  2. [root@cacti-nagios ~]# yum install -y php-devel
  3. [root@cacti-nagios ~]# wget http://pkgs.fedoraproject.org/repo/pkgs/php-json/php-json-ext-1.2.1.tar.bz2/e06e701412a055f3372775216ec3d604/php-json-ext-1.2.1.tar.bz2
  4. [root@cacti-nagios ~]# tar jxf php-json-ext-1.2.1.tar.bz2
  5. [root@cacti-nagios ~]# cd php-json-ext-1.2.1
  6. [root@cacti-nagios php-json-ext-1.2.1]# ./configure
  7. [root@cacti-nagios php-json-ext-1.2.1]# make
  8. [root@cacti-nagios php-json-ext-1.2.1]# make install
  9. [root@cacti-nagios ~]# vi /etc/php.d/json.ini
  10. extension=json.so
  11. [root@cacti-nagios ~]# /etc/init.d/httpd restart

  12. php -m查看json是否加载成功
三、NPC无法显示数据
1. 页面上显示Nagios状态为Off,但是服务器上Nagios状态为运行中

  1. [root@cacti-nagios ~]# /etc/init.d/nagios status
  2. nagios (pid 10896) is running...
2. 在NPC选项卡里点击Hosts或Services看不到任何数据,但是在nagios页面里可以看到被监控的主机和服务
3. 这是因为NPC启用后会在cacti数据库里创建前缀为ncp_*的表,并读取里面的数据,但nagios(ndoutil)却是将数据存在前缀为nagios_*的表里,所以导致NPC无法显示Hosts和Services信息。

  1. [root@cacti-nagios ~]# mysql -uroot
  2. mysql> use cacti;
  3. mysql> show tables;
  4. mysql> select * from npc_commands;
  5. Empty set (0.00 sec)
4. 将nagios存储数据的表修改为npc_,使数据存到npc_表里从而可以在NPC选项卡里显示出来

  1. root@cacti-nagios ~]# vi /usr/local/nagios/etc/ndo2db.cfg
  2. # :111行将前缀修改为npc_
  3. db_prefix=npc_
  4. kill掉ndo2db进程
  5. [root@cacti-nagios ~]# ps -ef|grep ndo2db
  6. [root@cacti-nagios ~]# rm -rf /usr/local/nagios/var/ndo.sock
  7. 重启ndo2db
  8. [root@cacti-nagios ~]# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
  9. 重启nagios
  10. [root@cacti-nagios ~]# /etc/init.d/nagios restart
5. 重新测试访问NPC选项卡,显示Nagios状态正常,但是仍然看不到Hosts和Servies信息
6. 查看message日志,发现有报错

  1. [root@cacti-nagios ~]# tail -f /var/log/message
  2. Jul 6 10:39:47 Cacti last message repeated 2 times
  3. Jul 6 10:40:03 Cacti nagios: Nagios 3.5.0 starting... (PID=11264)
  4. Jul 6 10:40:03 Cacti nagios: Local time is Sat Jul 06 10:40:03 CST 2013
  5. Jul 6 10:40:03 Cacti nagios: LOG VERSION: 2.0
  6. Jul 6 10:40:03 Cacti nagios: ndomod: NDOMOD 1.5.2 (06-08-2012) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
  7. Jul 6 10:40:03 Cacti nagios: ndomod: Successfully connected to data sink. 0 queued items to flush.
  8. Jul 6 10:40:03 Cacti nagios: Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
  9. Jul 6 10:40:03 Cacti ndo2db-3x: Warning: Retrying message send. This can occur because you have too few messages allowed or too few total bytes allowed in message queues. You are currently using 64 of 16 messages and 65536 of 65536 bytes in the queue. See README for kernel tuning options.
  10. Jul 6 10:40:03 Cacti nagios: Finished daemonizing... (New PID=11269)
  11. Jul 6 10:40:04 Cacti ndo2db-3x: Message sent to queue.
  12. Jul 6 10:40:04 Cacti ndo2db-3x: Warning: queue send error, retrying...
  13. Jul 6 10:40:04 Cacti ndo2db-3x: Error: mysql_query() failed for 'INSERT INTO npc_hoststatus SET instance_id='1', host_object_id='62', status_update_time=FROM_UNIXTIME(1373078403), output='CRITICAL - Host Prohibited (192.168.10.248)', long_output='', perfdata='', current_state='1', has_been_checked='1', should_be_scheduled='1', current_check_attempt='1', max_check_attempts='5', last_check=FROM_UNIXTIME(1373078311), next_check=FROM_UNIXTIME(1373078381), check_type='0', last_state_change=FROM_UNIXTIME(1373078321), last_hard_state_change=FROM_UNIXTIME(1373075821), last_hard_state='0

查找报错关键字mysql_error: ‘Unknown column ‘long_output’ in ‘field list”,最后在cacti官方论坛上找到,修改如下表

[root@cacti-nagios etc]# mysql -ucacti -p123456
mysql> use cacti;
mysql> alter table npc_eventhandlers add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_hostchecks add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_hoststatus add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_notifications add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_servicechecks add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_servicestatus add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_statehistory add long_output TEXT NOT NULL default '' after output;
mysql> alter table npc_systemcommands add long_output TEXT NOT NULL default '' after output;
[root@cacti-nagios ~]# /etc/init.d/nagios restart
[root@cacti-nagios ~]# /etc/init.d/httpd restart

7. 刷新浏览器,点击npc选项卡,看到Hosts和Services里被监控的信息已经出来了



一、安装配置ntop
编译要使用到的软件包有GeoIP GeoIP-devel libpcap-devel libpcap
#tar xf ntop-4.0.1.tar.gz #cd ntop-4.0.1 #./autogen.sh -prefix=/usr/local #make #make install
 修改ntop目录的属主   
#chown -R nobody /usr/local/var/ntop #ntop -A  修改ntop密码 #ntop -i eth0 -d -L -u ntop
  以ntop身份运行,并监控eth0网卡
  ntop监听在tcp3000端口
开机启动:
 
echo ‘ntop -i eth0 -d -L -u ntop &> /dev/null’ >> /etc/rc.d/rc.local
 
我们可以通过浏览器来查看ntop所监听的网卡的状况

内容如下:
二、安装ntop-0.1.tar.gz插件,整合cacti和ntop
这里只需将ntop插件解压到cacti/plugins目录中就行
下载地址:
 
#tar xf ntop-0.1.tar.gz -C /var/www/cacti/plugins
在cacti配置文件中添加对ntop的支持
编辑/www/cacti/include/conf.php
  添加
$plugins[] = 'ntop';
三、在cacti控制台中将ntop添加到cacti界面中去,
在User Management 中选中admin中,选中View NTop复选框,save保存,ntop就会出现在cacti的控制台中了


阅读(1110) | 评论(0) | 转发(0) |
0

上一篇:Nagios安装配置

下一篇:一.Extmai添加yum仓库

给主人留下些什么吧!~~