首页 > √linux > Linux下cacti完整安装指南
viyin.net

Linux下cacti完整安装指南

2009年8月12日 发表评论 阅读评论

初衷:

网上的cacti教程不够全面。vi看了多篇。郁闷了许久。才安装成功。

写此文目的,为自己做个备忘,为后来者做为参考,共同进步。如有误,欢迎指导。

环境: 5.3 0.8.7e
mysql 5.1.36 apache2.2.3 php 5.2.10 net- 5.3.2.2

一、安装步骤:

1.基本需求:
 
1).先必须安装LAMP (参见另一篇博文)

2)安装libart_lgpl ,libart_lgpl-devel

2.依次安装net-snmp,,cacti

1). [root@vi ~]#yum -y install net-snmp*
#如果php之前不支持snmp,必须安装php-snmp
编辑/etc/snmp/snmpd.conf 编辑以下几项:
查找
#sec.name source community
com2sec notConfiUser default public 改为 com2sec notConfigUser 127.0.0.1 public
查找

  1. ####
  2. # Finally, grant the group read-only access to the systemview view.
  3. # group context sec.model sec.level prefix read write notif
  4. access notConfigGroup “” any noauth exact systemview none none

将”read”字段改为all.
代码:
#access notConfigGroup “” any noauth exact all none none
查找
## incl/excl subtree mask
#view all included .1 80
去掉view前面的#
查找

  1. #       name           incl/excl     subtree         mask(optional)
  2. #view   systemview      included        .1
  3. view    systemview    included   .1.3.6.1.2.1.1
  4. view    systemview    included   .1.3.6.1.2.1.25.1.1

将下面两个view前#去掉
启动snmpd服务:/etc/init.d/snmpd start

验证SNMP是否配置正确,可用以下命令:

[root@vi ~]# snmpwalk -v 2c -c vivivi 127.0.0.1 if

如果返回以下字段,既成功:

  1. IF-MIB::ifIndex.1 = INTEGER: 1
  2. IF-MIB::ifIndex.2 = INTEGER: 2
  3. IF-MIB::ifIndex.3 = INTEGER: 3
  4. IF-MIB::ifDescr.1 = STRING: lo
  5. IF-MIB::ifDescr.2 = STRING: eth0
  6. IF-MIB::ifDescr.3 = STRING: sit0
  7. IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
  8. IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
  9. IF-MIB::ifType.3 = INTEGER: tunnel(131)
  10. IF-MIB::ifMtu.1 = INTEGER: 16436
  11. IF-MIB::ifMtu.2 = INTEGER: 1500
  12. IF-MIB::ifMtu.3 = INTEGER: 1480
  13. IF-MIB::ifSpeed.1 = Gauge32: 10000000
  14. IF-MIB::ifSpeed.2 = Gauge32: 1000000000
  15. IF-MIB::ifSpeed.3 = Gauge32: 0
  16. IF-MIB::ifPhysAddress.1 = STRING:
  17. IF-MIB::ifPhysAddress.2 = STRING: 0:c:29:4d:ea:47
  18. IF-MIB::ifPhysAddress.3 = STRING:
  19. IF-MIB::ifAdminStatus.1 = INTEGER: up(1)
  20. IF-MIB::ifAdminStatus.2 = INTEGER: up(1)
  21. IF-MIB::ifAdminStatus.3 = INTEGER: down(2)
  22. IF-MIB::ifOperStatus.1 = INTEGER: up(1)
  23. IF-MIB::ifOperStatus.2 = INTEGER: up(1)
  24. IF-MIB::ifOperStatus.3 = INTEGER: down(2)
  25. IF-MIB::ifLastChange.1 = Timeticks: (0) 0:00:00.00
  26. IF-MIB::ifLastChange.2 = Timeticks: (0) 0:00:00.00
  27. IF-MIB::ifLastChange.3 = Timeticks: (0) 0:00:00.00
  28. IF-MIB::ifInOctets.1 = Counter32: 213202822
  29. IF-MIB::ifInOctets.2 = Counter32: 3312338633
  30. IF-MIB::ifInOctets.3 = Counter32: 0
  31. IF-MIB::ifInUcastPkts.1 = Counter32: 1874738
  32. IF-MIB::ifInUcastPkts.2 = Counter32: 33706098
  33. IF-MIB::ifInUcastPkts.3 = Counter32: 0
  34. IF-MIB::ifInNUcastPkts.1 = Counter32: 0
  35. IF-MIB::ifInNUcastPkts.2 = Counter32: 0
  36. IF-MIB::ifInNUcastPkts.3 = Counter32: 0
  37. IF-MIB::ifInDiscards.1 = Counter32: 0
  38. IF-MIB::ifInDiscards.2 = Counter32: 0
  39. IF-MIB::ifInDiscards.3 = Counter32: 0
  40. IF-MIB::ifInErrors.1 = Counter32: 0
  41. IF-MIB::ifInErrors.2 = Counter32: 0
  42. IF-MIB::ifInErrors.3 = Counter32: 0
  43. IF-MIB::ifInUnknownProtos.1 = Counter32: 0
  44. IF-MIB::ifInUnknownProtos.2 = Counter32: 0
  45. IF-MIB::ifInUnknownProtos.3 = Counter32: 0
  46. IF-MIB::ifOutOctets.1 = Counter32: 213202822
  47. IF-MIB::ifOutOctets.2 = Counter32: 571095627
  48. IF-MIB::ifOutOctets.3 = Counter32: 0
  49. IF-MIB::ifOutUcastPkts.1 = Counter32: 1874738
  50. IF-MIB::ifOutUcastPkts.2 = Counter32: 36540389
  51. IF-MIB::ifOutUcastPkts.3 = Counter32: 0
  52. IF-MIB::ifOutNUcastPkts.1 = Counter32: 0
  53. IF-MIB::ifOutNUcastPkts.2 = Counter32: 0
  54. IF-MIB::ifOutNUcastPkts.3 = Counter32: 0
  55. IF-MIB::ifOutDiscards.1 = Counter32: 0
  56. IF-MIB::ifOutDiscards.2 = Counter32: 0
  57. IF-MIB::ifOutDiscards.3 = Counter32: 0
  58. IF-MIB::ifOutErrors.1 = Counter32: 0
  59. IF-MIB::ifOutErrors.2 = Counter32: 0
  60. IF-MIB::ifOutErrors.3 = Counter32: 0
  61. IF-MIB::ifOutQLen.1 = Gauge32: 0
  62. IF-MIB::ifOutQLen.2 = Gauge32: 0
  63. IF-MIB::ifOutQLen.3 = Gauge32: 0
  64. IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero
  65. IF-MIB::ifSpecific.2 = OID: SNMPv2-SMI::zeroDotZero
  66. IF-MIB::ifSpecific.3 = OID: SNMPv2-SMI::zeroDotZero</span>

不成功的提示如下:

Timeout: No Response from 127.0.0.1

这时要查看SNMP是否配置正确。 是否正确设置 community

2).安装rrdtool
[root@vi ~]# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.2.30.tar.gz
[root@vi ~]# tar zxvf rrd rrdtool-1.2.30.tar.gz
[root@vi ~]# cd rrdtool-1.2.30
[root@vi ~]# ./configure –prefix=/usr/local/rrdtool
[root@vi ~]# make
[root@vi ~]# make install

3).配置mysql,导入脚本
[root@vi ~]# useradd -p cacti -s /sbin/bash cacti
#增加一个用于执行监控的用户cacti
[root@vi ~]# mysqladmin -uroot -p create cacti
#在mysql里增加用户cacti
[root@vi ~]#grant all on cacti.* to cacti@localhost identified by ‘viyin.net’;
#赋予cacti用户对数据库cacti有全部权限,并且设置密码为viyin.net
[root@vi ~]# flush privileges;
[root@vi ~]# mysql -uroot -p cacti < cacti.sql
#导入脚本文件cacti.sql,这步操作必须在cacti解压缩后的目录上执行,不然可能找不到该文件

4).安装cacti
[root@vi ~]# wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz
[root@vi ~]# tar zxvf cacti-0.8.7e.tar.gz
[root@vi ~]#mv cacti-.8.7e /www/viyinnet/cacti
[root@vi ~]# cd /www/viyinnet/cacti
[root@vi ~]# vi ./include/config.php  编辑数据库配置文件
$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “cacti”;
$database_password = “cacti”;
[root@vi ~]#chown -R cacti /www/viyinnet/cacti 改变目录所有者

[root@vi ~]#chmod -R 777 /www/viyinnet/cacti   设置权限

5).打开IE,输入http://你的域名或IP/cacti/  自动转向安装页面,填写路径,如果出现打不开,肯定是路径不对,安装完成后,默认后台管理员用户名和密码都是admin,输入后需要立即修改密码。

6).设置自动获取数据
[root@vi ~]# crontab -u cacti -e
*/5 * * * * /usr/local/php/bin/php /www/web/viyinnet/cacti/poller.php > /dev/null 2>&1

注意红色字体部份。路径要完整。是php的二进制路径。

写入crtontab 作用是每5分钟生成一次图表。

7).登陆http://IP/cacti进行配置
到目前为止安装已经完成!

二、配置监控设备

1. 监控本机
打开后台console-devices-add-:
Description 写localhost,Hostname是本机IP,Host Template 选择Local Linux Machine,其他默认
然后建立图形,选择Create Graphs for this Host:
勾选Graph Templates 下面所有项,选择create
选择Management–Graph Management 添加模板以及选择主机
然后再Management–Graph Trees 里添加服务器

2.监控远程linux主机

必须先开启远程主机snmpd服务
打开后台console-devices-add-:
Description 写远程主机名,Hostname是远程主机IP,Host Template 选择ucd/net SNMP host,snmp options–snmp version 选择v1,SNMP Community
public,其他默认
然后建立图形,选择Create Graphs for this Host:
勾选Graph Templates 下面所有项,选择create
选择Management–Graph Management 添加模板以及选择主机
然后再Management–Graph Trees 里添加服务器
也可以在官方论坛下载模板:http://forums.cacti.net/forum-12.html

3.监控windows 主机

其他都差不多,首先必须在windows 机器上安装snmp组件,并且将服务属性–安全–勾选“发送身份验证陷进”,团体名称为cacti服务器snmpd.confLi 里设置的public,权限为只读,另外在下面添加cacti主机IP

三、问题集锦

1.编译rrdtool时候出错:

configure: WARNING:
—————————————————————————-
* I found a copy of pkgconfig, but there is no libpng.pc file around.
  You may want to set the PKG_CONFIG_PATH variable to point to its
  location.
—————————————————————————-

configure: WARNING:
—————————————————————————-
* I could not find a working copy of libpng. Check config.log for hints on why
  this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
  so that compiler and the linker can find libpng and its header files. If
  you have not installed libpng, you can get it either from its original home on

     http://prdownloads.sourceforge.net/libpng/

  You can find also find an archive copy on

     http://oss.oetiker.ch/rrdtool/pub/libs

  The last tested version of libpng is 1.2.10.

       LIBS=-lz -lart_lgpl_2 -lm
   LDFLAGS=
  CPPFLAGS= -I/usr/include/libart-2.0

—————————————————————————-
               
checking for FT_Init_FreeType in -lfreetype… no
checking for pkg-config… (cached) pkg-config
configure: WARNING:
—————————————————————————-
* I found a copy of pkgconfig, but there is no freetype2.pc file around.
  You may want to set the PKG_CONFIG_PATH variable to point to its
  location.
—————————————————————————-

configure: WARNING:
—————————————————————————-
* I could not find a working copy of freetype2. Check config.log for hints on why
  this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
  so that compiler and the linker can find libfreetype and its header files. If
  you have not installed freetype2, you can get it either from its original home on

     http://prdownloads.sourceforge.net/freetype/

  You can find also find an archive copy on

     http://oss.oetiker.ch/rrdtool/pub/libs

  The last tested version of freetype2 is 2.1.10.

       LIBS=-lz -lart_lgpl_2 -lm
   LDFLAGS=
  CPPFLAGS= -I/usr/include/libart-2.0 -I/usr/include/freetype2

—————————————————————————-
               
configure: error: Please fix the library issues listed above and try again.

解决:

将freetype2.pc libpng*.pc 拷贝到/usr/lib/pkgconfig 后正常,之前也有同样提示,是因为系统找不到这些*.pc文件,从/usr/lib/pkgconfig上将这些文件拷贝到rrd目录 /tmp/rrdbuild/lb/lib/pkgconfig

如果以上操作还不能正确编译,那换个低一点版本的rrtool,vi遇到的就是这样,后来换了个低版本。顺利解决。

2. 编译rrdtools提示:
/usr/bin/ld: cannot find -lpng
collect2: ld returned 1 exit status
make[4]: *** [blib/arch/auto/RRDs/RRDs.so] Error 1
make[4]: Leaving directory `/opt/rrdtool-1.2.30/bindings/perl-shared’
make[3]: *** [perl_shared] Error 2
make[3]: Leaving directory `/opt/rrdtool-1.2.30/bindings’
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/opt/rrdtool-1.2.30/bindings’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/rrdtool-1.2.30′
make: *** [all] Error 2

解决:原来是libpng安装有问题,重新执行安装,并不要指定安装路径,然后重新make rrdtool即可!

3.mysql 启动失败

[root@centos ~]# tail /var/log/mysqld.log
090709 14:42:20 [ERROR] Can’t start server: Bind on TCP/IP port: Cannot assign requested address
090709 14:42:20 [ERROR] Do you already have another mysqld server running on port: 3306 ?
090709 14:42:20 [ERROR] Aborting

090709 14:42:20  InnoDB: Starting shutdown…
090709 14:42:22  InnoDB: Shutdown completed; log sequence number 0 168351
090709 14:42:22 [Note] /usr/libexec/mysqld: Shutdown complete
090709 14:42:22  mysqld ended

查看/etc/my.cnf

发现:bind-address = 10.155.30.1
但是目前本机IP是10.155.30.64,将bind-address = 10.155.30.1注释掉或者将IP改为10.155.30.64后正常

4.设置字体路径:

后台–console–configure–settings–path-RRDTool Default Font Path
/usr/local/rrdtool/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf

5.执行snmpwalk测试提示:Timeout: No Response from 127.0.0.1
[root@centos rra]# snmpwalk -v 2c -c public 127.0.0.1 if
Timeout: No Response from 127.0.0.1

解决:

/etc/snmp/snmpd.conf 设置问题,改为:com2sec notConfigUser  127.0.0.1       public

/etc/init.d/snmpd restart

6. 执行# snmpwalk -v 2c -c smallfish 127.0.0.1 if 提示:
IF-MIB::ifTable = No Such Object available on this agent at this OID

解决:
[root@vi ~]# vi /etc/snmp/snmpd.conf 找到:
access  notConfigGroup “”      any       noauth    exact  systemview none none将 systemview 改为all

7.关注最多的,没有图的问题

首先必须确认rra下有*.rrd文件,如果没有,将rra,log权限设置为777,再过5分钟看看,一般设置5分钟自动执行获取数据
或者直接执行执行: /usr/bin/php /var/www/html/cacti/poller.php 产生数据,也可以加参数 –force 强制生成数据

8. 有图没有数据,全部为nan

执行:/opt/rrdtool-1.2.30/src/rrdtool fetch test_proc_8.rrd AVERAGE 测试
                           proc
1247124900: nan
1247125200: nan
1247125500: nan
1247125800: nan
1247126100: nan
1247126400: nan
1247126700: nan
1247127000: nan
1247127300: nan
1247127600: nan
。。。 。。。
先确定有rrd文件,权限都没问题,以及日志是否有错误提示,如果都没问题,可能是模板选择有问题,重新选择模板,另外关注后台console–devices–查看设备状态是否为Unknown

9.没有生成rrd文件

检查设备模板是否正常,以及设备状态(Status)是否为Unknown,正常显示为UP

viyin.net
分类: √linux 标签: , , , , ,
  1. 2009年8月12日10:38 | #1

    很高深的样子。。catti是啥东西。。呼。。

  2. 2009年8月12日10:52 | #2

    流量监控工具。基于SNMP@simaopig

  3. 2009年8月25日08:48 | #3

    回来看看,是怎么解决问题的

  4. 2009年8月25日08:59 | #4

    太不厚道啦。当初郁闷了半天也不出来。@牧羊者社区

  5. KY
    2009年9月16日08:41 | #5

    为什么我的snmp得到timeout?
    我是按照上面的步骤做的。

    [root@utl ~]# snmpwalk -v 2c -c vivivi 127.0.0.1 if
    Timeout: No Response from 127.0.0.1

  6. wanl0401
    2010年2月1日15:21 | #6

    8. 有图没有数据,全部为nan

    执行:/opt/rrdtool-1.2.30/src/rrdtool fetch test_proc_8.rrd AVERAGE 测试
    proc
    1247124900: nan
    1247125200: nan
    1247125500: nan
    1247125800: nan
    1247126100: nan
    1247126400: nan
    1247126700: nan
    1247127000: nan
    1247127300: nan
    1247127600: nan

    我是这个情况,windows下的,权限给了RRA和LOG给了运行php poller.php的用户777权限

    snmpwalk没问题。 有图无数据
    你这里说的模板是主机模板吗。?

  1. 本文目前尚无任何 trackbacks 和 pingbacks.