<?php

系统监控配置之cacti+rrdtool+netsnmp

一,安装rrdtool 官网: http://oss.oetiker.ch/rrdtool/

/usr/bin/wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.2.tar.gz
/bin/tar xzf rrdtool-1.4.2.tar.gz
cd rrdtool-1.4.2
./configure --prefix=/home/rrdtool

提示以下warning信息:
configure: WARNING:
—————————————————————————-
* I found a copy of pkgconfig, but there is no pangocairo.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 pangocairo. 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 libpango-1.0 and its header files. If
  you have not installed pangocairo, you can get it either from its original home on

     http://ftp.gnome.org/pub/GNOME/sources/pango/1.17

  You can find also find an archive copy on

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

  The last tested version of pangocairo is 1.17.

       LIBS=-lm  -lglib-2.0 
   LDFLAGS= -L/lib64   
  CPPFLAGS= -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include 

—————————————————————————-
               
checking for xmlParseFile in -lxml2… yes
checking libxml/parser.h usability… yes
checking libxml/parser.h presence… yes
checking for libxml/parser.h… yes
configure: error: Please fix the library issues listed above and try again.

信息表明缺了pango的头文件,因此要先安装pango-devel

/usr/bin/yum install pango-devel

接下来重新编译

./configure --prefix=/home/rrdtool

这次编译通过:
Config is DONE!

make && make install

做一个软连接

/bin/ln -s /home/rrdtool/bin/* /usr/local/bin/
cd ..

这样就完成了rrdtool的安装,

 

二,安装net-snmp 官网: http://www.net-snmp.org/

先下载net-snmp的最新版本5.5

/usr/bin/wget http://downloads.sourceforge.net/project/net-snmp/net-snmp/5.5/net-snmp-5.5.tar.gz?use_mirror=nchc
/bin/tar xzf net-snmp-5.5.tar.gz
cd net-snmp-5.5
./configure #一切按照默认值来编译(默认安装到/usr/loca/)
make && make install

运行以下snmpget,检查是否安装成功

/usr/loca/bin/snmpget

我这里就遇到了问题,提示信息是:
/usr/local/bin/snmpget: error while loading shared libraries: libnetsnmp.so.20: cannot open shared object file: No such file or directory
先通过ldd查看snmpget需要加载哪些库

[root@test_server net-snmp-5.5]# /usr/bin/ldd /usr/local/bin/snmpget
        libnetsnmp.so.20 => not found
        libcrypto.so.6 => /lib64/libcrypto.so.6 (0×0000003c1fc00000)
        libc.so.6 => /lib64/libc.so.6 (0×0000003c1d000000)
        libdl.so.2 => /lib64/libdl.so.2 (0×0000003c1d400000)
        libz.so.1 => /usr/lib64/libz.so.1 (0×0000003c1ec00000)
        /lib64/ld-linux-x86-64.so.2 (0×0000003c1cc00000)
可见需要加载的库文件大都放在/lib64/下的;
再查一下libnetsnmp.so.20是在什么位置

/usr/bin/whereis libnetsnmp.so.20
libnetsnmp.so: /usr/local/lib/libnetsnmp.so /usr/local/lib/libnetsnmp.so.20

ok, 至此我们就知道怎么解决问题了:

/bin/ln -s /usr/local/lib/libnetsnmp.so.20 /lib64/libnetsnmp.so.20

再执行一次snmpget

/usr/local/bin/snmpget
Created directory: /var/net-snmp
Created directory: /var/net-snmp/mib_indexes
No hostname specified.
USAGE: snmpget [OPTIONS] AGENT OID [OID]...

  Version:  5.5
  Web:      <a href="http://www.net-snmp.org/">http://www.net-snmp.org/</a>
  Email:    <a href="mailto:net-snmp-coders@lists.sourceforge.net">net-snmp-coders@lists.sourceforge.net</a>

OPTIONS:
  -h, --help            display this help message
...

一切OK

三, 安装cacti 官网: http://www.cacti.net/
值得注意的是cacti的环境需求:
RRDTool 1.0.49 or 1.2.x or greater
MySQL 4.1.x or 5.x or greater
PHP 4.3.6 or greater, 5.x greater highly recommended for advanced features
A Web Server e.g. Apache or IIS

先确认是否满足,然后:

cd ..
/usr/bin/wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz
/bin/tar xzf cacti-0.8.7e.tar.gz
/bin/mv cacti-0.8.7e cacti

然后就可以把cacti转移到web目录下

/bin/mv cacti /data/htdocs/cacti
cd /data/htdocs/cacti
/home/mysql/bin/mysql cacti &lt; cacti.sql #导入数据库结构
/bin/chown www:www -R .
/bin/vi include/config.php

修改数据库连接信息:
$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “root”;
$database_password = “”;
$database_port = “3306″;

增加后台任务,每两分钟搜集一次数据

*/5 * * * * /usr/local/bin/php /usr/local/apche2/htdocs/cacti/poller.php > /dev/null 2>&1

接下来就从前台访问cacti的安装目录
http://zhys9.com/cacti/install/
按照以下图片中的标红提示完成配置

1

2

3
最后通过默认账号密码: admin/admin 登录,然后系统会提示修改密码;

 

接下来的事情就只是用了 ;)

Tags: , , ,

Leave a Reply