大湖之子 发表于 2019-1-16 11:38:08

Linux监控 cacti nagios整合

  最新cacti安装
  环境要求:
  yum install -y httpd mysql php gd gd-devel gcc
  yum -y install net-snmp-*
  下载cacti以对应的patch plugin
  http://cactiusers.org/ http://cacti.net
  mkdir -p /root/monitor
  wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz
  wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7e-PA-v2.6.zip
  下载三方源 (主要为了安装rrdtool)
  http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm 32位 (centos5.0)
  http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm 64位(centos 5.0)
  rpm -Uvh rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
  yum -y install rrdtool
  cd /root/monitor
  tar xzvf cacti-0.8.7e.tar.gz
  mv cacti-0.8.7e /var/www/html/cacti
  mysql -u root -p
  mysql>create database cacti; 创建一个数据库供 cacti 使用
  mysql>use cacti;
  Mysql>source /var/www/html/cacti/cacti.sql; 导入 mysql 数据库

  Mysql>grant all privileges on cacti.* to cacti@localhost>  Mysql>flush privileges;
  vim /var/www/html/cacti/include/config.php
  修改数据库配置信息
  然后在IE中输: http://xxx.xxx.xxx.xxx/cacti
  在出来的安装界面
http://www.selfcai.com.cn/wp-content/uploads/2010/03/003.jpeg
http://www.selfcai.com.cn/wp-content/uploads/2010/03/cacti-install-3.jpeg
  完成后安装后.初始的用户名和密码是: admin :admin
  接下来.我们安装plug
  cd /root/monitor
  unzip cacti-plugin-0.8.7e-PA-v2.6.zip
  cp -R cacti-plugin-arch/* /var/www/html/cacti/
  mysql -u root -p cacti patch -p1 -N < cacti-plugin-0.8.7e-PA-v2.6.diff
  这样做完后,可能会图象不对(前提,你设置的url是http://xxx/cacti),那么需要修改如下的内容.
  vim include/global.php
  $config['url_path'] = ‘/cacti/’;
  
  进入”用户管理”->点admin->区域权限->Plugin Management启用.(为以后npc做准备)
  为了用cacti监控流量,配置cacti采集任务:
  添加cacti用户
  useradd cacti -d /var/www/html/cacti -s /bin/false
  chown cacti:cacti /var/www/html/cacti/rra /var/www/html/cacti/log
  让系统一分钟采集一次
  */1 * * * * php /var/www/html/cacti/poller.php &>/dev/null也可手工跑一次:
  /var/www/html/cacti/poller.php 
  如果提示没有权限.则可: chmod -R 777 /var/www/html/cacti
  如果运行报错如下:
  /var/www/html/cacti/poller.php
  /var/www/html/cacti/poller.php: line 1: ?php: No such file or directory
  /var/www/html/cacti/poller.php: line 2: /bin: is a directory
  /var/www/html/cacti/poller.php: line 3: +————————————————————————-+: command not found
  /var/www/html/cacti/poller.php: line 4: syntax error near unexpected token `|’
  /var/www/html/cacti/poller.php: line 4: ` | Copyright (C) 2004-2009 The Cacti Group                                 |’
  则在poller.php的最前面,也就是第一行加入
  #!/usr/bin/php -q
  解决cacti图形上中文显示问题
  下载并安装cjkuni-fonts中文字体,字体名ukai.ttf,下载地址http://ftp.tw.debian.org/debian/pool/main/t/ttf-arphic-ukai/ttf-arphic-ukai_0.1.20060928.orig.tar.gz
  安装完成后注意在”设置”中更改下面两个必改项. 常规->RRDTool应用程序版本 改为1.2.x,默认为1.0.x.不改可能图像不能正常显示出来. 路径->RRDTool默认字体路径 改为上面安装的ukai.ttf的文件路径,如/usr/share/fonts/ukai.ttf
  来个中文的图
http://www.selfcai.com.cn/wp-content/uploads/2010/03/chines.jpeg
  上一文讲了cacti的安装:接下来.是nagios的安装和ndoutils工具的配合使用.
  nagios的安装就不用说了.网上的文档太多了.
  整合NPC 要用的包如下:
  PHP 5.1

[*]PDO and JSON support are required(http://aurore.net/projects/php-json/php-json-4.3.2_1.2.1-1.aurore.src.rpm)
[*]Latest NPC>
[*]NDOUtils 1.4b7 (这个版本很重要,不要换,我换了1.4b8 1.4b9都是报数据库查询错误)
[*]Nagios 3.x
[*]Cacti 0.8.7b
[*]Cacti Plugin Architecture v2.0
[*]NPC下载  svn co http://svn2.assembla.com/svn/npc/trunk npc
  用以上描述的包,就可以正常工作了.
  在/usr/local/nagios/etc/nagios.cfg 中最后加入:
  check_external_commands=1
  command_check_interval=-1
  event_broker_options=-1
  broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
  process_performance_data=1
  文件/usr/local/nagios/etc/ndo2db.cfg 如下:
  ndo2db_user=nagios
  ndo2db_group=nagios
  socket_type=tcp
  socket_name=/usr/local/nagios/var/ndo.sock
  tcp_port=5668
  db_servertype=mysql
  db_host=localhost
  db_port=3306
  db_name=cacti
  db_user=cacti
  db_pass=cactipass
  db_prefix=npc_
  max_timedevents_age=1440
  max_systemcommands_age=10080
  max_servicechecks_age=10080
  max_hostchecks_age=10080
  max_eventhandlers_age=44640
  debug_level=1
  debug_verbosity=1
  debug_file=/usr/local/nagios/var/ndo2db.debug
  max_debug_file_size=1000000
  文件 /usr/local/nagios/etc/ndomod.cfg 内容如下
  instance_name=default
  output_type=tcpsocket
  output=localhost
  tcp_port=5668
  output_buffer_items=5000
  buffer_file=/usr/local/nagios/var/ndomod.tmp
  file_rotation_interval=14400
  file_rotation_timeout=60
  reconnect_interval=15
  reconnect_warning_interval=15
  data_processing_options=-1
  config_output_options=2
  然后启动ndo2db就可以了.
  在cacti中的NPC中就可以看到nagios配置的监控信息了.如下图
http://www.selfcai.com.cn/wp-content/uploads/2010/03/cacti-npc1.jpeg
http://www.selfcai.com.cn/wp-content/uploads/2010/03/cacti-npc2.jpeg
  参考文档:
  http://trac2.assembla.com/npc/wiki/QuickStartGuide

页: [1]
查看完整版本: Linux监控 cacti nagios整合