2009年11月20日 16:08
大体安装过程:
先装 rrd tools 再配置 cacti 在配置cacti的时候,就要开始配置 snmp客户端
然后配置apache插件 http://xok.la/2009/05/cacti_apache_templates.html 再安装mysql插件 http://www.faemalia.net/mysqlUtils/teMySQLcacti-20060810.tar.gz 再安装
http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7e-PA-v2.6.zip 这里安装不成功 是安装成功了,页面却乱了.无法访问了.
安装了monitor模块 http://cactiusers.org/downloads/monitor.gzip
接下来主要就是扩展了
非标准化安装 CACTI
1.把网页源码包放入apache 网页根目录 2.配置include/config.php文件 3.导入数据库文件
4.配置crontab自动运行的那个程序 */1 * * * * /var/www/html/cacti-0.8.7e/poller.php >/dev/null2>&1 5.把网页源码权限改成777
Cacti 插件/模块/自定义/优化
2009年11月24日 14:45
==安装cacti模板==
所有模板都在http://forums.cacti.net/about15067.html ----------->这里的东西完完整.详细 1) 安装mysql模板
下载模板 wget http://www.faemalia.net/mysqlUtils/teMySQLcacti-20060810.tar.gz tar xzfv teMySQLcacti-20060810.tar.gz
解出来后里面有几个xml文件,php文件,sh文件以及readme。 先把XML文件导入web页面的模板里面。(需要全部导入)
再把两个PHP文件即mysql_stats.php,dumpMemcachedStats.php文件复制到cacti目录下的scripts里面。
这个时候可以在添加设备的时候加入mysql模块了。
注:如果是要监控远端数据库,需要有访问远端数据库的权限。 在被监控机器上vi /etc/sysconfig/iptables 加入
-A RH-Firewall-1-INPUT -s yourip -m udp -p udp --dport 161 -j ACCEPT -A RH-Firewall-1-INPUT -s yourip -m tcp -p tcp --dport 3306 -j ACCEPT
然后进入数据库
GRANT PROCESS ON * TO cacti@'cactimachine' IDENTIFIED by 'cactipasswd'; GRANT SUPER ON * TO cacti@%'cactimachine' IDENTIFIED BY 'cactipasswd';
mysql -uroot -p
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'yourip' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
再在监控机上测试mysql -h ip -uroot -pyourpasswor
如果可以连的上就说明配置成功,就可以在添加设备的时候添加监控mysql模块了。否则poller.php执行不过去会导致不画图。 总结:
1.在mysql服务器上添加cacti服务器mysql访问权限
GRANT PROCESS ON * TO cacti@'cactimachine' IDENTIFIED by 'cactipasswd'; GRANT PROCESS ON * TO cacti@'152.104.141.18' IDENTIFIED by 'cactianlai'; GRANT SUPER ON * TO cacti@%'cactimachine' IDENTIFIED BY 'cactipasswd'; GRANT SUPER ON * TO cacti@'152.104.141.18' IDENTIFIED by 'cactianlai'; 2.http://www.faemalia.net/mysqlUtils/teMySQLcacti-20060810.tar.gz上下载源码 3.把源码当中的php文件放入cacti/scripts/目录 4.在cacti界面当中import templates 5.创建图表,成功
2) 安装apache模板
下载后得到apachestats-0.4.zip
解开后里面有三个文件夹docs,xml,scripts
与上面一样,把XML文件导入模板,scripts里面的文件复制到cacti目录里面的scripts。 现在就可以在添加设备里面添加监控apache了。
cacti添加apache监控模板 以下网站有详细方法 http://xok.la/2009/05/cacti_apache_templates.html 总结:
1.在apache服务器上开始server-status功能 2.在服务器上下载源码
3.把源码当中的php文件放入cacti/scripts/目录 4.在cacti界面当中import templates 5.创建图表,成功
3) 其他模板都是与同样的方式安装,基本常用的模板在上面说的网站中都可以找到
==安装cacti插件==
插件可以在 http://cactiusers.org/downloads/ 1)安装Plugin Architecture 这个是安装所有插件所必须装的 wget
http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7e-PA-v2.6.zip
解开以后里面有file-08.6x,对应你所安装的cacti版本, cd file-0.8.6i
把里面的所有文件复制到cacti 目录里面, cp * /usr/local/apache/htdocs/cacti/ 2) 安装monitor插件 下载monitor插件
wget http://cactiusers.net/downloads/plugins/monitor-0.7.tar.gz tar zvxf monitor-0.7.tar.gz 把该目录复制到plugins里
cp -r monitor /usr/local/apache/htdocs/cacti/plugins/ 然后修改include里的config.php文件
vi /usr/local/apache/htdocs/cacti/include/config.php 加上$plugins[] = 'monitor'; 保存修改 3)安装thold插件
方式与安装monitor插件一样。
源文档 自定义步骤: Cacti进阶应用二:使用cacti获取snmp发送的自定义信息后作图 我的步骤: 1.在被监控端服务器上添加获取并发的脚本,在/etc/snmp/snmpd.conf添加以下语句,然后重启snmpd exec .1.3.6.1.4.1.2021.51 channels /usr/bin/php -q /var/lib/asterisk/agi-bin/ChannelsMonitor.php ;注意修改以下代码当中连接服务器的manager账号 2.在cacti监控端执行 snmpwalk -v 1 xxx.xxx.xx.xx -c public .1.3.6.1.4.1.2021.51 snmpwalk -v 1 xxx.xxx.xx.xx -c public .1.3.6.1.4.1.2021.51.101.1 snmpwalk -v 1 xxx.xxx.xx.xx -c public .1.3.6.1.4.1.2021.51.101.2 看看是否有数据获取到,如果能够得到,那就成功了,然后就根据下面的步骤,先创建Data tempalte -->graph template,在Devices对需要执行此监控的服务器添加此监控模板,然后在创建此监控报表,此至完成 总结: 对于asterisk channels的监控有两种做法 a. 在cacti服务器,使用AMI远程登录asterisk服务器,获取通道信息, 问题在于snmp是否要创建多个exec呢?那这样就需要创建多个模板,然后就是在本地服务器上创建监控报表,感觉这种方案虽对AMI的维护方便,但数据的创建及区别比较麻烦。 b. 在cacti服务器使用snmp与其他各服务器asterisk通信,其他asterisk服务器获取数据后,使用snmp传送到总服务器。此方针对客户端服务器只需要监控总的并发,比较方便,只需要创建一种模板,但如果客户端要分别监控单条E1的时候,这也不省力了。 源文档 snmp提供了发送自定义信息的功能。查看snmpd.conf会看到有一个小节是关于外部脚本的,Executables/scripts。这个小节里面也举了例子,告诉你怎么通过snmp发送信息。 在snmpd.conf任意位置添加一行: exec .1.3.6.1.4.1.2021.18 tcpCurrEstab /etc/tcpconn.sh 其中tcpCurrEstab是命令的名称,后面是命令以及参数。命令的名称可以随便起。脚本执行的结果类似下面: # /etc/tcpconn.sh 80 脚本内容如下: 1. 2. 3. 4. $ cat tcpconn.sh #!/bin/sh conn=`netstat -s -t | grep connections\\ established |awk '{print $1}'` echo $conn 复制代码 重启snmpd,然后远程通过snmpwalk接收一下数据看看: 5. 6. 7. 8. 9. # snmpwalk -c public -v 2c 127.0.0.1 .1.3.6.1.4.1.2021.18 UCD-SNMP-MIB::ucdavis.18.1.1 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.18.2.1 = STRING: \"tcpCurrEstab\" UCD-SNMP-MIB::ucdavis.18.3.1 = STRING: \"/etc/tcpconn_total.sh\" UCD-SNMP-MIB::ucdavis.18.100.1 = INTEGER: 0 10. UCD-SNMP-MIB::ucdavis.18.101.1 = STRING: \"488\" 11. UCD-SNMP-MIB::ucdavis.18.102.1 = INTEGER: 0 12. UCD-SNMP-MIB::ucdavis.18.103.1 = \"\" 复制代码 其中我们需要的是UCD-SNMP-MIB::ucdavis.18.101.1 = STRING: “488″这一行: 13. # snmpwalk -v 1 192.168.1.201 -c public .1.3.6.1.4.1.2021.18.101.1 14. UCD-SNMP-MIB::ucdavis.18.101.1 = STRING: \"488\" 复制代码 能采集到数据之后,就可以配置cacti来接收了。在cacti界面中console->Templates->Data Templates,然后点击右上角的Add,Data Templates中的name是给这个数据模板的命名,Data Source中的name将来显示在Data Sources中,我这里添加“|host_description| - Tcp Conn. - ESTBLISHED”,选get snmp data,Internal Data Source Name也可以随便添,这个用来给rrd文件命名。设置完后就可以save了,save之后会发现下面多了一些选项,在最下面那个添上我们需要的数据的 OID“.1.3.6.1.4.1.2021.18.101.1”,可以保存了。 此后需要创建一个Graph Templates,好让cacti生成图片。在cacti界面中 console->Templates->Graph Templates,然后点击右上角的Add,Templates中的name是给这个数据模板的命名,Graph Template中的name是将来显示在图片上面中间的内容,我这里添加“|host_description| - Tcp Conn. - ESTBLISHED”,其他保持默认,保存之后上面会出来一些选项。 在Graph Template Items中添加一个item,Data Source选之前添加的,color选择一个图片的颜色,Graph Item Type选AREA,也就是区域,也可以选其他的线条,Text Format设置说明。然后再添加一个,Graph Item Type选GPRINT,Consolidation Function选LAST,也就是当前的值,Text Format输入current。你还可以添加一些Graph Item Type为COMMENT的注释说明等。 现在只要为host添加这个画图模板就可以看到画出来的图了。 源文档 cacti设置一分钟刷新 Submitted by 林刚 on 2009, September 16, 10:47 AM. 系统运维与监控 cacti默认是5分钟采集下数据库,总是感觉反应太慢,对一些变化比较大的数据明显不准确,就一直考虑将采集时间修改为1分钟,因为需要监控的服务器很少,对系统负荷影响不大 1. 将crontab从5分钟一次更改为1分钟一次 2. Poller Interval和Cron Interval修改为每分钟 3.Data Sources 的step(采样时间)修改为60,heartbeat(超时)修改为120,也可以简单用SQL命令修改下 UPDATE data_template_data SET rrd_step=60 WHERE rrd_step=300; UPDATE data_template_rrd SET rrd_heartbeat=120 WHERE rrd_heartbeat=600; UPDATE poller_item SET rrd_step = 60 WHERE rrd_step = 300; 4. 修改RRAs,将显示时间修改为1分钟,画图时间还是保留5分钟 将RRAS的年月日的steps缩小五倍,Rows增加五倍,也可以用SQL语句 DELETE FROM rra; — 4 rows affected INSERT INTO rra VALUES (1,’c21df5178e5c955013591239eb0afd46′,’Daily (1 Minute Average)’,0.5,1,8000,800); INSERT INTO rra VALUES (2,’0d9c0af8b8acdc7807943937b3208e29′,’Weekly (30 Minute Average)’,0.5,30,1600,604800); INSERT INTO rra VALUES (3,’6fc2d038fb42950138b0ce3e9874cc60′,’Monthly (2 Hour Average)’,0.5,120,1600,2678400); INSERT INTO rra VALUES (4,’e36f3adb9f152adfa5dc50fd2b23337e’,'Yearly (1 Day Average)’,0.5,1440,1600,33053184); 5、就是放弃原来以每5分钟取得的数据,把rra目录下的文件都删除了 源文档 RRD tools 2009年11月20日 16:08 RRDBUILD(1) rrdtool RRDBUILD(1) RRD TOOLs 安装步骤: NAME rrdbuild - Instructions for building RRDtool OVERVIEW If you downloaded the source of RRDtool you have to compile it. This document will give some information on how this is done. RRDtool relies on services of third part libraries. Some of these libraries may already be installed on your system. You have to compile copies of the other ones before you can build RRDtool. This document will tell you about all the necessary steps to get going. These instructions assume you are using a bash shell. If you use csh/tcsh, then you can either type bash to switch to bash for the compilation or if you know what you are doing just replace the export bits with setenv. We further assume that your copies of tar and make are actually GNU tar and GNU make respectively. It could be that they are installed as gtar and gmake on your system. OPTIMISTIC BUILD Before you start to build RRDtool, you have to decide two things: 1. In which directory you want to build the software. 2. Where you want to install the software. Once you have decided. Save the two locations into environment variables. 注意:不建议使用rrdtools 1.4版本,会导致自定义snmp数据无法显示,这是因为当前cacti 0.8.7a只支持到rrdtoolss 1.3.X,对1.4版本支持不好。建议使用rrdtools 1.2.30 所有的源码包在下载rrdtools的地方就会有, http://oss.oetiker.ch/rrdtool/pub/ http://oss.oetiker.ch/rrdtool/pub/libs/ BUILD_DIR=/tmp/rrdbuild INSTALL_DIR=/usr/local/rrdtool-1.4.2 Export BUILD_DIR Export INSTALL_DIR If your /tmp is mounted with the option noexec (RHEL seems todo that) you have to choose a different directory! Now make sure the BUILD_DIR exists and go there: mkdir -p $BUILD_DIR cd $BUILD_DIR Lets first assume you already have all the necessary libraries pre- installed. wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.2.tar.gz gunzip -c rrdtool-1.4.2.tar.gz | tar xf - cd rrdtool-1.4.2 ./configure --prefix=$INSTALL_DIR && make && make install Ok, this was very optimistic. This try will probably have ended with configure complaining about several missing libraries. INSTALLING DEPENDENCIES If your OS lets you install additional packages from a software repository, you may get away with installing the missing packages. When the packages are installed, run configure again and try to compile again. Below you find some hints on getting your OS ready for compiling RRDtool. Additions to this list are welcome. In general RRDtool should work with the latest versions of the libraries. The versions listed here are just what was current when I tested this. Debian / Ubuntu Use apt-get to make sure you have all that is required. A number of packages will get added through dependencies. apt-get install libpango1.0-dev libxml2-dev Gentoo In Gentoo installing RRDtool is really simple you just need to emerge rrdtool. All dependencies will be handled automatically by the portage system. The only thing you should care about are USE flags, which allow you fine tune features RRDtool will be built with. Currently the following USE flags are available: doc - install .html and .txt documentation into /usr/share/doc/rrdtool-1.x.xx/ perl - build and install perl language bindings python - build and install python language bindings ruby - build and install ruby language bindings tcl - build and install tcl language bindings rrdcgi - build and install rrdcgi After you've decided which USE flags you need, set them either in make.conf or /etc/portage/package.use and finally run: # emerge -va rrdtool Take a look at Gentoo handbook for further details on how to manage USE flags: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2 BUILDING DEPENDENCIES But again this may have been too optimistic still, and you actually have to compile your own copies of some of the required libraries. Things like libpng and zlib are pretty standard so you will probably have them on your system anyway. Freetype, Fontinst, Cairo, Pango may be installed, but it is possible that they are pretty old and thus don't live up to our expectations, so you may want to compile their latest versions. General build tips for AIX If you are working with AIX, you may find the --disable-shared option will cause things to break for you. In that case you may have to install the shared libraries into the RRDtool PREFIX and work with --disable-static instead. Another hint to get RRDtool working on AIX is to use the IBM XL C Compiler: export CC=/usr/vac/bin/cc export PERLCC=$CC (Better instructions for AIX welcome!) Build Instructions Some libraries want to know where other libraries are. For this to work, set the following environment variable export PKG_CONFIG_PATH=${INSTALL_DIR}/lib/pkgconfig export PATH=$INSTALL_DIR/bin:$PATH The above relies on the presence of the pkgconfig program. Below you find instructions on how to compile pkgconfig. Since we are compiling libraries dynamically, they must know where to find each other. This is done by setting an appropriate LDFLAGS. Unfortunately, the syntax again differs from system to system: Solaris export LDFLAGS=-R${INSTALL_DIR}/lib if you are using the Sun Studio/Forte compiler, you may also want to set CFLAGS=\"-xO3 -xcode=pic13\" (SPARC) CFLAGS=\"-xO3 -Kpic\" (x86) Linux export LDFLAGS=\"-Wl,--rpath -Wl,${INSTALL_DIR}/lib\" yum install cairo-devel pango-devel HPUX export LDFLAGS=\"+b${INSTALL_DIR}/lib\" AIX export LDFLAGS=\"-Wl,-blibpath:${INSTALL_DIR}/lib\" If you have GNU make installed and it is not called 'make', then do export MAKE=gmake export GNUMAKE=gmake otherwise just do export MAKE=make Building pkgconfig As mentioned above, without pkgconfig the whole build process will be lots of pain and suffering, so make sure you have a copy on your system. If it is not available natively, here is how to compile it. wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.23.tar.gz gunzip -c pkg-config-0.23.tar.gz | tar xf - cd pkg-config-0.23 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" $MAKE $MAKE install After installing pkgconfig in a custom directory, setting up the corresponding environment variable will be helpful. export PKG_CONFIG=$INSTALL_DIR/bin/pkg-config Building zlib Chances are very high that you already have that on your system ... 这里的zlib可以使用yum install 的方法来安装 cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/zlib-1.2.3.tar.gz gunzip -c zlib-1.2.3.tar.gz | tar xf - cd zlib-1.2.3 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" --shared $MAKE $MAKE install Building libpng Libpng itself requires zlib to build, so we need to help a bit. If you already have a copy of zlib on your system (which is very likely) you can drop the settings of LDFLAGS and CPPFLAGS. Note that the backslash (\\) at the end of line 4 means that line 4 and line 5 are on one line. cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.18.tar.gz gunzip -c libpng-1.2.18.tar.gz | tar xf - cd libpng-1.2.10 env CFLAGS=\"-O3 -fPIC\" ./configure --prefix=$INSTALL_DIR $MAKE $MAKE install Building freetype cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.3.5.tar.gz gunzip -c freetype-2.3.5.tar.gz | tar xf - cd freetype-2.3.5 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" $MAKE $MAKE install If you run into problems building freetype on Solaris, you may want to try to add the following at the start the configure line: env EGREP=egrep Building LibXML2 cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/libxml2-2.6.32.tar.gz gunzip -c libxml2-2.6.32.tar.gz | tar xf - cd libxml2-2.6.32 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" $MAKE $MAKE install Building fontconfig Note that fontconfig has a run time configuration file in INSTALL_DIR/etc you may want to adjust that so that fontconfig finds the fonts on your system. Run the fc-cache program to build the fontconfig cache after changing the config file. cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/fontconfig-2.4.2.tar.gz gunzip -c fontconfig-2.4.2.tar.gz | tar xf - cd fontconfig-2.4.2 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" --with-freetype-config=$INSTALL_DIR/bin/freetype-config $MAKE $MAKE install Building Pixman cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/pixman-0.10.0.tar.gz gunzip -c pixman-0.10.0.tar.gz | tar xf - cd pixman-0.10.0 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" $MAKE $MAKE install Libraries have been installed in: /usr/local/rrdtool-1.4.2/lib If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. LD_LIBRARY_PATH=\"/usr/local/rrdtool-1.4.2/lib\" export LD_LIBRARY_PATH LIBDIR =\"/usr/local/rrdtool-1.4.2/lib\" LD_RUN_PATH=$LIBDIR export LIBDIR export LD_RUN_PATH Building Cairo ;下面这一步是找到pixman-1.pc,然后后到/usr/lib/pkgconfig当中,目的目录也有可能是/usr/lib/pkg-config cp /tmp/rrdbuild/pixman-0.10.0/pixman-1.pc /usr/lib/pkgconfig/ cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/cairo-1.6.4.tar.gz gunzip -c cairo-1.6.4.tar.gz | tar xf - cd cairo-1.4.10 ./configure --prefix=$INSTALL_DIR \\ --enable-xlib=no \\ --enable-xlib-render=no \\ --enable-win32=no \\ CFLAGS=\"-O3 -fPIC\" $MAKE $MAKE install Building Glib 可以用yum install 安装 cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/glib-2.15.4.tar.gz gunzip -c glib-2.15.4.tar.gz | tar xf - cd glib-2.15.4 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" $MAKE $MAKE install Building Pango pango也可以使用yum install 安装 cd $BUILD_DIR wget http://oss.oetiker.ch/rrdtool/pub/libs/pango-1.21.1.tar.bz2 bunzip2 -c pango-1.21.1.tar.bz2 | tar xf - cd pango-1.21.1 ./configure --prefix=$INSTALL_DIR CFLAGS=\"-O3 -fPIC\" --without-x $MAKE $MAKE install Building rrdtool (second try) Now all the dependent libraries are built and you can try again. This time you tell configure where it should be looking for libraries and include files. This is done via environment variables. Depending on the shell you are running, the syntax for setting environment variables is different. And finally try building again. We disable the python and tcl bindings because it seems that a fair number of people have ill configured python and tcl setups that would prevent RRDtool from building if they are included in their current state. cd $BUILD_DIR/rrdtool-1.4.2 ./configure --prefix=$INSTALL_DIR --disable-tcl --disable-python $MAKE clean $MAKE $MAKE install SOLARIS HINT: if you want to build the Perl module for the native Perl (the one shipping with Solaris) you will need the Sun Forte compiler installed on your box or you have to hand-tune bindings/perl-shared/Makefile while building! Now go to $INSTALL_DIR/share/rrdtool/examples/ and run them to see if your build has been successful. AUTHOR Tobias Oetiker 1.4.2 2009-11-15 RRDBUILD(1) cacti 2009年11月20日 16:51 yum install php-snmp net-snmp yum install php-gd php-ldap php-xml 支持Cacti运作的PHP+RRDtool环境配置方法 (1) 发布时间:2009.05.07 08:39 来源:赛迪网 作者:范绰耘 【赛迪网-IT技术报道】Cacti功能类似于我们所熟悉的MRTG。MRTG确实是非常好的老牌系统监控工具,但由于他历史实在很久了,使得许多功能以及配置等方面都比较落后。实现得比较费劲,管理起来很麻烦。比如我有几百个被监测点,分布在不同的机房,而且我需要将这些服务器和网络设备分类,这样的话我就要将这些被监测点放在不同的mrtg配置文件中,运行多个crontab,而且还要自己写了一些html页面对其进行管理。 Cacti其实是一套php程序,一个rrdtool工具。它运用snmpget采集数据,使用rrdtool绘图。界面非常漂亮,它提供了强大的数据管理和用户管理功能,一张图是属于一个host的,每一个host又可以挂载到一个树状的结构上。 用户的管理上,作为一个开源软件,它做到为指定一个用户能查看的“树”、host、甚至每一张图,还可以与LDAP结合进行用户的验证。Cacti还提供自己增加模板的功能,让你添加自己的snmp_query和script。功能相当强大! 本文前半部分是教程,主要介绍了Cacti以及其PHP运行环境的安装配置。后半部分将实际举例如何使用Cacti监控诸如Linux,Windows。以及支持SNMP管理协议的路由器等网络设备。 环境搭建 Cacit运行环境需要PHP+Mysql+rrdtool以及snmp工具的支持。 下边是本次配置需要用到的软件。 Catci: 1.cacti-0.8.6j.tar.gz 2.rrdtool-1.2.27.tar 3.net-snmp-5.0.9-2.30E.15 4.net-snmp-devel-5.0.9-2.30E.15 5.net-snmp-libs-5.0.9-2.30E.15 6.net-snmp-utils-5.0.9-2.30E.15 PHP: 1.php-5.2.6.tar.gz 2.curl-7.15.0.tar.gz 3.freetype-2.1.9.tar.gz 4.gettext-0.16.1.tar.gz 5.gd-2.0.35.tar.gz 6.jpegsrc.v6b.tar.gz 7.libart_lgpl-2.3.17.tar.gz 8.libpng-1.2.18.tar.gz 9.libxml2-2.6.32.tar.gz 10.ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz 11.zlib-1.2.3.tar.gz 12.libxml2-2.6.32.tar.gz Apache: httpd-2.2.6.tar.gz Mysql: mysql-5.1.24-rc.tar.gz 开始构建完整的PHP运行的环境,我们以全新安装的RedHatAs4updata4操作系统环境为例。 首先编译安装Apachehttpdserver 1.#tarzxvfhttpd-2.2.6.tar.gz 2.#cdhttpd-2.2.6 3.#./configure--prefix=/usr/local/apache26--enable -module=so--with-mpm=worker--enable-module=rewrite 4.#make&&makeinstall 第二步安装PHP+GD等所需的支持插件 编译安装libxml 1.#tarzxvf libxml2-2.6.32.tar.gz 2.#cdlibxml2-2.6.32.tar.gz 3.#./configure--prefix=/usr/local/libxml2/ 4.#make&&makeinstall 编译安装zlib 1.#tarzxvf zlib-1.2.3.tar.gz 2.#cdzlib-1.2.3 3.#./configure--prefix=/usr/local/zlib2/ 4.#make&&makeinstall 编译安装jpeg支持 1.#tar-zxf jpegsrc.v6b.tar.gz 2.#cdjpeg-6b/ 3.#./configure--prefix=/usr/local/jpeg6 4.#make 5.#make install-lib 6.#makeinstall (该版本的jpeg在实际安装过程中,makeinstall的时候会出现好几个找不到目录,或目录不存在的error。只需按照提示人手创建缺失目录,然后再令其makeinstall直到无任何错误提示且顺利完成为止。) 编译安装libpng 1.#tarzxvflibpng-1.2.18.tar.gz 2.#cdlibpng-1.2.18.tar.gz 3.#cpscripts/makefile.gcmmxmakefile 4.#./configure--disable-shared--prefix=/usr/local/libpng2/ 5.#make&&makeinstall 编译安装freetype 1.#tarzxvffreetype-2.1.9.tar.gz 2.#cdfreetype-2.1.9 3.#./configure--disable-shared--prefix=/usr/local/freetype2/ 4.#make&&makeinstall 编译安装libart_lgpl 1.#tarzxvflibart_lgpl-2.3.17.tar.gz 2.#cdibart_lgpl-2.3.17 3.#./configure--disable-shared--prefix=/usr/local/libart/ 4.#make&&makeinstall 编译安装gettext 1.#tarzxvfgettext-0.16.1.tar.gz 2.#cdgettext-0.16.1 3.#./configure--prefix=/usr/local/gettext/ 4.#make&&makeinstall 编译安装gd库: 1.#tarzxvf gd-2.0.35.tar.gz 2.#cd gd-2.0.35 3.#./configure--prefix=/usr/local/gd2--with-zlib=/usr/local/zlib2/ --with-png=/usr/local/libpng2/--with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype2/--with-libart=/usr/ local/libart/--with-gettext=/usr/local/gettext/--with-libxml=/usr/local/libxml2 4.#make&&makeinstall 编译安装Curl支持 1.#tarzxvfcurl-7.15.0.tar.gz 2.#cdcurl-7.15.0 3.#./configure--prefix=/usr/local/curl 4.#make&&makeinstall 编译安装PHP 1.#tar zxvf php-5.2.6.tar.gz 2.#cd php-5.2.6 3.#./configure--prefix=/usr/local/php--with-apxs2=/usr/local/apache26/bin/apxs --with-jpeg-dir=/usr/local/jpeg6/--with-png-dir=/usr/local/libpng2/--with- gd=/usr/local/gd2/--with-freetype-dir=/usr/local/freetype2/-- with-zlib-dir=/usr/local/zlib2/--with-mysql=/usr/local/mysql--with- curl=/usr/local/curl--with-gettext=/usr/local/gettext 4.#make&&makeinstall 5.#cpphp.ini-dist/usr/local/php/lib/php.ini(拷贝PHP配置文件至安装目录) 6.#vi/usr/local/apach26/conf/httpd.conf (修改apache配置文件并加载PHP支持) 要改的有如下几处 1.一般都在#AddTypeapplication/x-tar.tgz下加一行: #LoadModulephp5_modulemodules/libphp5.so AddTypeapplication/x-httpd-php.php 1.如果你搜索其它地方没有以下这行: LoadModulephp5_modulemodules/libphp5.so 请把上面的#号去掉,还有找到 DirectoryIndexindex.htmlindex.html.var 在后面加index.php让它把index.php做为默认页 1.保存httpd.conf文件. 启动apache #/usr/local/apache2/bin/apachectlstart 如果没有出错,写一个测试页放到你网页目录下.访问就应该可以看到php的版本等信息了! 用ZendOptimizer加速PHP 1.#tarzxvfZendOptimizer-2.5.3-linux-glibc21-i386.tar.gz 2.#cdZendOptimizer-2.5.3-linux-glibc21-i386 3.#./install.sh 安装的时候注意输入正确的安装apache的路径等内容! 安装完毕,再看看phpinfo页面的zend选项就发现了!! 安装MYSQL#groupaddmysql #useradd-gmysqlmysql #tarzxvfmysql-5.1.24-rc.tar.gz #cdmysql-5.1.24-rc #./configure--prefix=/usr/local/mysql --localstatedir=/data/mysql(指定数据文件目录) --without-innodb--without-debug--with-extra-charsets=gbk --with-extra-charsets=all--enable-assembler--with-pthread --enable-thread-safe-client--with-client-ldflags=-all-static #make&&makeinstall #cp./support-files/mysql.server/etc/init.d/mysql(复制Mysql启动服务至系统) #chmod777/etc/init.d/mysql (赐予可执行权限) #chownmysql:mysql/data/mysql(设置数据文件目录属性) 设置数据文件目录属性这一步相当重要,许多朋友第一次使用tar包安装Mysql的时候就因该目录权限问题导致Mysql无法启动。相当头大. #/usr/local/mysql/bin/mysql_install_db (初始化数据库) #servicemysqlstart (启动Mysql) #/usr/local/mysql/bin/mysqladmin-uroot-ppassword'xxxxx'(设置管理员密码xxx默认值为空) 好了,至此mysql安装完毕. 这样构建Cacit运行的PHP+Mysql环境就基本上完成了。 下边开始安装Cacit所需要的rrdtools图形工具以及snmp工具 编译安装rrdtools #tarzxvfrrdtool-1.2.27.tar #cdrrdtool-1.2.27 #./configure--prefix=/usr/local/rrdtool #make&&makeinstall 如果./configure时出现下面这个错误 configure:error:Pleasefixthelibraryissueslistedaboveandtryagain. 表明系统有功能缺失,需安装libart_lgpl-devel.rpm这个包 如果还是提示听样的错误,有可能是找不到FreeType 把/usr/local/freetype2/lib/pkgconfig下的.pc文件拷贝到/usr/lib/pkgconfig下即可 如果makeinstall时出现[tclrrd.o]错误 就安装tcl-8.4.7-2.i386.rpm以及tcl-devel-8.4.7-2.i386.rpm这2个包 这里需要重点注册.如果以下包没有装完,会导致: snmpwalk和snmpget 命令 没有 yum install net-snmp-utils 安装net-snmp、snmpwalk和snmpget命令 #rpm-qa|grepnet-snmp (查看系统中有否已经装有所需的软件) net-snmp-5.0.9-2.30E.15 net-snmp-devel-5.0.9-2.30E.15 net-snmp-libs-5.0.9-2.30E.15 net-snmp-utils-5.0.9-2.30E.15 没有或者缺少的话都需要逐一安装上。 而且还很有可能会因rpm的依存关系无法顺利安装,须使用--nodeps参数。 以上所需的rpm安装包都能在RedHatAs4安装光盘上找到。 安装配置 至此,Cacti所需的运行环境都已经准备好了,接下来开始进行安装以及配置。 稍微修改系统中snmp的配置 #vi /etc/snmp/snmpd.conf 1.这个:om2sec notConfigUser default public 改为:com2sec notConfigUser 127.0.0.1 public 2.access notConfigGroup \"\" any noauth exact systemview none none 改为:access notConfigGroup \"\" any noauth exact all none none 3.#view all included .1 80 将前面的#注释去掉。 保存退出:wq 配置完成snmpd.conf后,执行: 之前遇到snmp error 好像是多一个配置文件就OK了 cp /etc/snmp/snmpd.conf /etc/snmp/snmp.local.conf 4.重新启动snmp服务 #service snmpd restart 安装/配置cacti 1.#tar zxvf cacti-0.8.6j.tar.gz 2.#mv cacti-0.8.6j/data/web_server/admin/cacti (把cacit剪切到自定的web目录下) 3.#chmod777–Rf/data/web_server/admin/cacti (设置目录权限,避免因权限问题而导致目录无法写入) 4.#cd/data/web_server/admin/cacti 在Mysql中创建一个新的库,并导入cacti目录中cacti.sql并设置好该表的用户权限,然后编辑cacti的数据库配置文件。 5.#vi/data/web_server/admin/cacti/include/config.php$database_type=“mysql”; $database_default=“数据库名称”; $database_hostname=“默认是localhost”; $database_username=“用户名”; $database_password=“密码”; 更改用户、密码等项与上面给出的对应保存退出 6.#crontab–e(加入自动执行规则,每5分钟执行。)*/5 * * * * /var/www/html/cacti/poller.php >/dev/null2>&1 (其中/usr/local/php/bin/php这个为php的安装目录) 7.保存退出:wq 8.在apache上设置好cacti所在web目录 9.打开浏览器http://youhostname/cacti 10.进入cacti的初始设置页面 第一次默认登陆账号:admin密码admin 登陆后它就会让你立即修改新密码 说一下cacti设置页中各项“零件”的路径。 这里要注意路径的配置,如果这里没有配置好,可以先进去,然后在 进行配置 选项卡的方式 Configuration Settings 当修改好新密码进入,第一个显示出的页面就是让你设置rrdtool,snmp等工具的路径。这是个很重要的环节,必须无误,要不然cacti将无法生成出统计图。 snmpwalkBinaryPath:/usr/bin/snmpwalk snmpgetBinaryPath:/usr/bin/snmpget RRDToolBinaryPath:/usr/local/rrdtool/bin/rrdtool PHPBinaryPath:/usr/local/php/bin/php CactiLogFilePath:/data/web_server/admin/cacti/log/cacti.log CactidPollerFilePath:/data/web_server/admin/cacti/poller.php 默认的配置中会出现许多“NotFound” 按照上边的路径把“NotFound”的项都重新填上。 手动运行一次 /usr/local/php/bin/php/data/web_server/admin/cacti/poller.php>/dev/null2>&1 你就能在顶上graphs中localhost里头看到本机的内存,CPU,登陆用户等的统计图. 图1.Cacti统计图 但默认Cacti是没有创建网卡流量的监控图的。要我们自己来加。 回到console菜单 选择Devices监控设备。 图2.设备监控 图3.添加设备 然后点击右上角的Add进行添加 Description设备名称(可随意输入) Hostname设备地址(如果是本机就填127.0.0.1) HostTemplate设备的类型(选择ucd/netSNMPHost) 然后其他按照默认即可,如下图 图4.添加的新设备 点create创建。 如果刚才填写的地址无误,创建成功后,会在该页面左上方出现所新建设备的SNMPInformation 然后点击隔壁醒目的*CreateGraphsforthisHost即开始创建监控图表 图5.创建图表-1 图6.创建图表-2 如图6,沟选你所要监控的网卡以及IP,点create。 这样就完成了你所指定设备统计图的创建。 图7.添加的设备统计图 点击菜单中的GraphManagement即可浏览到你刚才所创建的图表,如图7箭头所示。 图8.统计图表 有一个小技巧,初次要求cacti创建指定设备的统计图表,通过GraphManagement进入图8所示页面时,统计表图片会是一个X(叉)。这是因为在配置初期指定系统中每5分钟执所行的php语句还没到点运作。要么你就等5分钟,要么你就直接进入系统手动执行: /usr/local/php/bin/php/data/web_server/admin/cacti/poller.php>/dev/null2>& 然后曲线表中就能出现第一个峰值,每5分钟自动更新。24小时后,曲线图就能完整地出现在你眼前。 回到图7Graph Management的界面勾选新建的图表项,然后在下边 Choose an action框中选择PlaceonaTree(defaultTree) 就能把该图表类似快捷方式的样子张贴到本文图1所示的Graphs,Defaulttree栏目中。然而你也能自己在菜单栏的GraphTrees中新建定制栏目,然后用相同的方法把新建的统计图往你所定制的栏目中放。 Cacti的强大功能不单止可以通过snmp获取装有Linux,Unix操作系统服务器的运行状态,还能监控Windows系统服务器。跟诸如Cisco,Linksys,路由器,交换机,无线AP。或者其他支持snmp管理协议的网络设备。 实际应用 下边我们举出实应用的例子。 设备结构: 1.网络入口路由器LinksysRV042。 Linksys的一款路由器,主要负责,接入路由,防火墙,以及端口映射。 2.server1WEB应用服务器 操作系统:LinuxRedHatAs4 Eth0,Eth1双网卡工作。前者接入路由器映射至。后者直连至server2 进行反向代理(proxy)以及数据备份以及同步等功能。 IP分别为192.168.3.2以及192.168.10.2 3.server2储存,FTP与WEB应用服务器 操作系统:Windows2003r2 与server1网络环境相仿,双网卡工作。 IP分别为192.168.3.3以及192.168.10.3 Cacti已经配置完成,安装在server1上。第一台添加到监控表里边的是路由器RV042。打开路由器的WEB设置页面,勾选并启用SNMP功能。如图9 SendSNMPTrapto:192.168.3.2(server1的IP) 然后其他输入框按照默认留空即可,但需留意GetCommunityName:所填写的组名:public。保存设置。 图9.保存设置 登陆Cacti,console菜单栏中点击Devices。跟前边图1至8添加新设备以及创建统计图表的步骤相同 Description设备名称(我们这里自定为LinksysRV042) Hostname设备地址(路由器的地址192.168.3.1) HostTemplate设备的类型(选择ucd/netSNMPHost或者是CiscoRouter) 然后其他按照默认即可。 创建成功后,也会在该页面左上方出现所新建设备的LinksysRV042SNMPInformation 点击隔壁*CreateGraphsforthisHost创建监控图表 图10.创建监控图表 路由器RV042的端口以及IP等数据都取出来了。 勾选好所要监控的端口,点击create就能完成路由器监控图表的建立。 Cacti运行在Server1上,所以配置方式跟前边所介绍是一样的,这里就掠过了。但顺带说一下,如果环境中还存在Server3,而且跟Server1一样都是Linux系统,需要添加到cacti里头。哪么只需在该服务器上修改snmp配置,修改的内容也跟server1上几乎一样,不同的是。 编辑/etc/snmp/snmpd.conf的时候,原来填127.0.0.1(本机地址)的地方换成Cacti所在运行的服务器IP,即server1:192.168.3.2 1.com2secnotConfigUserdefaultpublic 改为:com2secnotConfigUser192.168.3.2(server1地址)public 1.accessnotConfigGroup\"\"anynoauthexactsystemviewnonenone 改为:accessnotConfigGroup\"\"anynoauthexactallnonenone 1.#viewallincluded.180 将前面的#注释去掉。 1.保存退出:wq 重新启动snmp服务 #servicesnmpdrestart 在Cacti,Devices中创建新设备, 填写Server3IP地址,设备类型:ucd/netSNMPHost,创建图表,完成。 到Server2的win2003系统了。 1.给Windows安装SNMP协议支持 通常由于SNMP是一个建议关闭的协议(因为有安全漏洞),所以Windows2003不是缺省安装的。但Cacti用的就是SNMP协议,而且服务器处于内网中,有路由器防火墙对外隔着,所以装吧。 控制面板–>添加或删除程序–>添加/删除Windows组件–>管理和监视工具–>简单网络管理协议(SNMP) 2.修改SNMP的安全设置 这台服务是被监控方,所以需要像刚才举例的Server3那样修改SNMP的配置。否则在server1里头的Cacti则永远也收不到SNMP的消息。打开Services窗口并找到SNMP服务, 打开右键菜单,选择属性。在打开的窗口中找到“安全”选项页。在选项页中有两部分设置,上半部分是指SNMP服务接受哪种Community指示字,缺省情况下Windows2003不对任何指示字反馈,我一般都添加设置为。 团体名称:public,权限:只读 下半部分添加可信任的主机名、IP或是IPX名称。这里就也是添加server1的IP192.168.3.2如图11 图11.修改SNMP的安全设置 3.修改防火墙 如果你安装了防火墙,还要记得打开UDP161端口。 完成后重新启动SNMPserver服务 登陆Cacti点Devices创建新设备。 填写Server2IP地址,设备类型:Windows2000/XPhosts 从Windows上获取到的SNMP信息也挺多,CPU,内存,虚拟内存,硬盘空间使用,网卡流量,一应俱全。最后创建图表,完成。 图12.修改防火墙 总结 Cacti真是一个世界。在正式使用Cacti接管原来的MRTG负责服务器状态监控的这段时间,我所能最深刻感受到的,不止是它漂亮的界面跟图表。而且是对监控设备的创建,跟管理,都有着史无前例地简单,高效。作为系统管理员,我当感激Cacti的作者能开发出这一套如此拔尖的监控程序。 虽然它所运行的PHP环境以及RRDtool在前期配置的时候要花好多的时间跟功夫, 但也未尝不是一个新的选择。试想一下,你只需一阵子的功夫在一台服务器上把环境配好,Cacti装好。以后,无论你要再添更多的服务器,要了解他们的”情绪”,就只需简单地在浏览器上登陆Cacti–>新建设备–>新建图表。区区几步,整整有条的服务器列表,CPU,硬盘,网卡等等读数的曲线都能一清二楚地显示在你面前。 当然!Cacti带来的强大功能以及方便还远不止这些,就交由大家之后去使用,去体验了。 [关于作者]范绰耘,服务器软硬件技术架构、开源软件的热衷者,现任职广州市摩息技术有限公司系统管理员。 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- nryq.cn 版权所有 赣ICP备2024042798号-6
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务