q36988 发表于 2019-1-10 11:51:26

cacti及其相关插件的安装

  cacti是什么?
  1. cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。
  

  2. Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量。
  

  3. snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。
  

  cacti的工作流程可以用下图表示:

  http://blog.运维网.com/attachment/201310/200319849.jpg
  

  cacti的安装:
  配置本地yum
  # vim /etc/yum.repos.d/rhel-debuginfo.repo
  Server]
  name=Red Hat Enterprise Linux Server
  baseurl=file:///mnt/cdrom/Server
  enabled=1
  gpgcheck=1
  gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
  

  

  # mkdir /mnt/cdrom
  # mount /dev/cdrom/mnt/cdrom/
  mount: block device /dev/cdrom iswrite-protected, mounting read-only
  

  # yum install httpd php php-mysql php-snmp mysql-serverperl-DBD-MySQL php-pdo net-snmp net-snmp-libs net-snmp-utils net-snmp-develruby –y
  

  # service httpd start
  # chkconfig httpd on
  

  # service mysqld start
  # chkconfig mysqld on
  

  # mysqladmin -u root -ppassword '123'
  

  # mysql -u root –p
  mysql> CREATE DATABASE cacti;
  mysql> grant all privileges on cacti.* to cacti@localhostidentified by 'cacti';
  mysql> grant all privileges on cacti.* to cacti@127.0.0.1identified by 'cacti';
  mysql> grant all privileges on cacti.* tocacti@192.168.2.0 identified by 'cacti';
  mysql> flush privileges;
  mysql> quit
  

  上传需要用的软件
http://blog.运维网.com/attachment/201310/200436989.jpg
  软件资料下载地址http://down.运维网.com/data/994246
  cacti-0.8.7g.tar.gz cacti的主程序
  cacti-plugin-0.8.7g-PA-v2.8.tar.gz 插件管理器
  feition.tar.bz2 用于飞信报警的程序
  monitor-latest.tgz 实现只管监测的插件
  sendMsg.zip 发送MSN消息的应用
  settings-latest.tgz 增强功能的插件,例如发送电子邮件
  thold-latest.tgz 实现达到预值告警的插件
  

  

  # yum localinstallrrdtool* --nogpgcheck –y
  

  安装cacti的主程序
  # tar -zxvf cacti-0.8.7g.tar.gz -C /var/www/html/
  # cd /var/www/html/
  # mv cacti-0.8.7g/ cacti
  

  # service snmpd start
  # chkconfig snmpd on
  # vim /etc/snmp/snmpd.conf
  添加一行view systemview included .1.3.6.1.2.1.25.1.6 /////使能监控tcp流量
  

  

  编辑计划任务
  # crontab -e
  */5 * * * * php/var/www/html/cacti/poller.php >/dev/null 2>&1
  

  导入数据库
  # mysql -u root -p cacti>/var/www/html/sendMsg/msn.txt.1
  cat /var/www/html/cacti/plugins/thold/alert.log>>/var/www/html/sendMsg/msn.txt.1
  now=`date +%Y-%m-%d-%H:%M`
  SA=(test)
  msnaddr=(接收信息的帐号)
  sendMsg()
  {
  num=0
  while [ $num -lt 1 ];
  do
  wget ?post-data"sender=发送信息的帐号&password=密码&recipient=${1}&message=${2}"http://127.0.0.1/sendMsg/index.php -O /var/www/html/sendMsg/index.php.1>/dev/null 2>&1
  if [ -f /var/www/html/sendMsg/index.php.1]; then
  if cat /var/www/html/sendMsg/index.php.1|grep -i successfully >/dev/null 2>&1;then
  num=1
  elif cat /var/www/html/sendMsg/index.php.1|grep -i "The user appears to be offline" >/dev/null2>&1;then
  num=1
  echo "The user is offline."
  exit 0
  elif cat /var/www/html/sendMsg/index.php.1 |grep-i "Something went wrong trying to connect to the server">/dev/null 2>&1;then
  num=1
  echo "MSN server is online."
  exit 0
  else
  num=0
  fi
  rm -f /var/www/html/sendMsg/index.php.1
  else
  num=0
  fi
  done
  }
  mv /var/www/html/sendMsg/msn.txt/var/www/html/sendMsg/bak/msn$now.txt -f 1>/dev/null 2>&1
  mv /var/www/html/sendMsg/msn.txt.1/var/www/html/sendMsg/msn.txt -f 1>/dev/null 2>&1
  rm /var/www/html/cacti/plugins/thold/alert.log -f 1>/dev/null 2>&1
  for i in 0
  do
  if cat /var/www/html/sendMsg/msn.txt ; then
  messages=`cat /var/www/html/sendMsg/msn.txt`
  sendMsg "${msnaddr[$i]}""$messages"
  else
  continue
  fi
  done
  

  

  配置支持飞信报警
  # tar -jxvf feition.tar.bz2
  # mkdir -pv /var/www/html/sendsms/linuxso
  # cp linuxso_20101113/* /lib/
  # mv linuxso_20101113/* /var/www/html/sendsms/linuxso/
  # vim /var/www/html/cacti/plugins/thold/thold_functions.php
  添加这两行
  562 exec("echo $subject>>/var/www/html/cacti/plugins/thold/alert.log");
  563 exec("/var/www/html/cacti/plugins/thold/sendsms.sh");
  

  # vim /var/www/html/cacti/plugins/thold/sendsms.sh
  #!/bin/sh
  #send sms by fetion
  #Write by pingsun2010@hotmail.com
  if [ ! -e"/var/www/html/cacti/plugins/thold/alert.log" ];then
  echo "Usage:alert.log does notexist"
  exit
  fi
  if [ -n "`cat/var/www/html/cacti/plugins/thold/alert.log`" ]; then
  admin="接收信息的帐号?
  echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log`>>/var/www/html/cacti/plugins/thold/sms.txt
  echo "exit" >>/var/www/html/cacti/plugins/thold/sms.txt
  else
  echo "Usage:no alert"
  exit
  fi
  if [ -n "`cat/var/www/html/cacti/plugins/thold/sms.txt`" ] ;then LD_LIBRARY_PATH=/var/www/html/sendsms/linuxso/var/www/html/sendsms/linuxso/fetion --mobile=发送信息的账户 --pwd=密码 --to=$admin --file-utf8=/var/www/html/cacti/plugins/thold/sms.txt
  rm -f /var/www/html/cacti/plugins/thold/sms.txt 1>/dev/null 2>&1
  rm -f /var/www/html/cacti/plugins/thold/alert.log 1>/dev/null 2>&1
  else
  echo "Usgae:no message to send"
  exit
  fi
  

  # chmod a+x send*
  给新建的脚本添加可执行权限
  

  vim /var/www/html/cacti/plugins/thold/alert.log
  随便写点儿内容,当飞信程序执行的时候会自动删除里面的内容
  可以新建alert.log以及sms.txt,其中在alert.log中添加一个内容。然后手工运行脚本进行测试,需要保证本机能正常接入互联网。
  

  目前cacti的环境已经搭建完成,cacti的使用还需要好好学习……



页: [1]
查看完整版本: cacti及其相关插件的安装