文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用cacti来监控服务器流量

使用cacti来监控服务器流量

时间:2009-07-22  来源:freyson

本人使用centOS4.5操作系统。服务器要有一个IP地址。有机器名。
使用cacti需要有php的环境,网络上有很多为什么使用cacti而不使用mrtg的评论,我这里就不多罗嗦了。
一、安装rrdtool
1、先安装libart_lgpl
 # cd /export1/soft
 # tar -zvxf libart_lgpl-2.3.17.tar.gz
 # make
 # make install
2、安装rrdtool
 # cd /export1/soft
 # tar -zvxf rrdtool-1.0.49.tar.gz(因为到了1.2后好多库都不是内置,为了方便我们安装1.0的)
 # cd rrdtool-1.0.49
 # ./configure --prefix=/export1/server/rrdtool --enable-shared
 # make
 # make install
二、 我们先安装运行环境。Apache+php+mysql
1、 mysql的安装,我使用的版本mysql-standard-4.0.18-pc-linux-i686.tar.gz可以去网上下载
 #  groupadd mysql
 #  useradd -g mysql mysql
 #  cd /export1/soft
 #  tar -zvxf mysql-standard-4.0.18-pc-linux-i686.tar.gz
 #  mv mysql-standard-4.0.18-pc-linux-i686.tar.gz /usr/local/mysql
 #  chown -R root /usr/local/mysql
 #  chgrp -R mysql /usr/local/mysql
 #  chown -R mysql /usr/local/mysql/data
 #  /usr/local/mysql/scripts/mysql_install_db -user=mysql(注意必须在/usr/local/mysql目录下运行该命令。)
#  /usr/local/mysql/bin/mysqld_safe -user=mysql &
#  /usr/local/mysql/bin/mysqladmin -uroot password ‘111111’
#  cp support-files/my-medium.cnf /etc/my.conf
  Mysql安装结束。
 
2、 安装apache。安装版本httpd-2.0.59.tar.gz
 #  cd /export1/soft
 #  tar -zvxf httpd-2.0.59.tar.gz
 #  cd httpd-2.0.59
 # ./configure --prefix=/export1/server/apache --enable-so --enable-mods-shared=most --enable-rewrite
 #  make
 #  make install
 #  /export1/server/apache/bin/apachectl start
打开<http://IP>能看到apache的页面,表示安装正常。
3、 安装php 版本php-4.4.7.tar.gz
 Php安装要加入一些库,用来php对图形的支持。
1) 安装jpeg6
# mkdir -p /export1/server/jpeg6
# mkdir -p /export1/server/jpeg6/bin
# mkdir -p /export1/ server/jpeg6/lib
# mkdir -p /export1/ server/jpeg6/include
# mkdir -p /export1/server/jpeg6/man
# mkdir -p /export1/lserver/jpeg6/man1
# mkdir -p /export1/server/jpeg6/man/man1
# cd /export1/soft/
# tar -zvxf jpegsrc.v6b.tar.gz
# cd jpeg-6b
# ./configure -prefix=/export1/server/jpeg6 -enable-shared -enable-static
# make
# make install
 
2) 安装libpng
# cd /export1/soft
# tar -zvxf libpng-1.2.8.tar.gz
# cd libpng-1.2.8
# cp scripts/makefile.std makefile
# make
# make install
3) 安装freetype
# cd /export1/soft
# tar -zvxf freetype-2.1.10.tar.gz
# cd freetype-2.1.10
# ./configure --prefix=/export1/server/freetype
# make;make install
4) 安装zlib
# cd /export1/soft/
#tar -zxvf zlib-1.2.3.tar.gz
#cd zlib.1.2.3
# ./configure
# make;make install
5) 安装GD库
  # cd /export1/soft/
# tar -zvxf gd-2.0.33.tar.gz
# cd gd-2.0.33
# ./configure --prefix=/export1/server/gd2 --with-jpeg=/export1/server/jpeg6/
--with-png=/usr/local/lib/
--with-zlib=/usr/local/lib/
--with-freetype=/export1/server/freetype/
# make; make install
6) 安装curl库
# cd /export1/soft/
# tar -zxf curl-7.15.0.tar.gz
# ./configure --prefix=/export1/server/curl
# make; make install
接下来我们安装php4
  # cd /export1/soft
  # tar -zvxf php-4.4.7.tar.gz
  # cd php-4.4.7
  # ./configure --prefix=/export1/server/php --with-apxs2=/export1/server/apache/bin/apxs --with-mysql=/usr/local/mysql --with-curl=/export1/server/curl --enable-ftp --with-zlib-dir=/usr/local/lib --with-jpeg-dir=/export1/server/jpeg6 --with-png=/usr/local/lib --with-freetype-dir=/export1/server/freetype --with-gd=/export1/server/gd2 --enable-sysvmsg --enable-sockets --enable-sysvshm --enable-sysvsem --enable-gd-native-ttf -with-tiff-dir=/usr -enable-snmp
 # make
 # make install
 # cp php.ini-dist /export1/server/php/lib/php.ini
 
4、 配置apche让它支持php
  配置 httpd.conf 让 apache支持php
 # vi /export1/server/apache/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DiectoryIndex index.php
重启apache
# /usr/server/apache2/bin/apachectl restart
在htdocs目录里建一内容为 <? phpinfo(); ?> PHP文件, 输入URL地址查看PHP配置是否正确
三、安装net-snmp
 早期的版本是ucp-snmp,现在都使用net-snmp,首先rpm -qa | grep net-snmp。因为我使用的是centOS所以可以直接yum。
如果出现如下表示已经安装了
# net-snmp-libs-5.1.2-11.EL4.10.0.1
# net-snmp-perl-5.1.2-11.EL4.10.0.1
# net-snmp-devel-5.1.2-11.EL4.10.0.1
# net-snmp-utils-5.1.2-11.EL4.10.0.1
# net-snmp-5.1.2-11.EL4.10.0.1
更改:
####
# First, map the community name "public" into a "security name"
       sec.name  source          public
#com2sec notConfigUser    default         public
com2sec local    127.0.0.1           moniter
com2sec kbkle    192.168.168.130     moniter
####
# Second, map the security name into a group name:
#       groupName      securityModel securityName
group   notConfigGroup  v1            local
group   notConfigGroup  v2c           local
####
# Third, create a view for us to let the group have rights to:
# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
####
# Finally, grant the group read-only access to the systemview view.
#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access notConfigGroup ""        any       noauth    exact  all      none none
# -----------------------------------------------------------------------------        3、#view all    included  .1         80        将前面的 # 注释 去掉。 保存退出 :wq
# service snmp start
就OK了,可以查看安装了snmpwalk和snmpget命令没有,which snmpwakl.
测试:
 # snmpwalk -v 2c -c demopublic test.net-snmp.org system
SNMPv2-MIB::sysDescr.0 = HP-UX net-snmp B.10.20 A 9000/715
 SNMPv2-MIB::sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.hpux10
 SNMPv2-MIB::sysUpTime.0 = Timeticks: (586998396) 67 days, 22:33:03.96
 SNMPv2-MIB::sysContact.0 = Wes Hardaker [email protected]
 SNMPv2-MIB::sysName.0 = net-snmp
 SNMPv2-MIB::sysLocation.0 = UCDavis
 SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00
 SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
 SNMPv2-MIB::sysORID.2 = OID: IF-MIB::ifMIB
 SNMPv2-MIB::sysORID.4 = OID: IP-MIB::ip
 SNMPv2-MIB::sysORID.5 = OID: UDP-MIB::udpMIB
 SNMPv2-MIB::sysORDescr.1 = The Mib module for SNMPv2 entities.
 SNMPv2-MIB::sysORDescr.2 = The MIB module to describe generic objects for network interface sub-layers
 SNMPv2-MIB::sysORDescr.4 = The MIB module for managing IP and ICMP implementations
 SNMPv2-MIB::sysORDescr.5 = The MIB module for managing UDP implementations
 SNMPv2-MIB::sysORUpTime.1 = Timeticks: (82) 0:00:00.82
 SNMPv2-MIB::sysORUpTime.2 = Timeticks: (81) 0:00:00.81
 SNMPv2-MIB::sysORUpTime.4 = Timeticks: (83) 0:00:00.83
 SNMPv2-MIB::sysORUpTime.5 = Timeticks: (82) 0:00:00.82
这里我们遍历了test.net-snmp.org的网站。说明snmp运行正常,如果我们要用snmpget就要针对某个服务的MIB值来做。
 
以上是用系统本身自带的包安装net-snmp,我这里再给一中用源代码安装的方式。首先去www.net-snmp.org <http://www.net-snmp.org>上下载。
  1、tar -zvxf net-snmp-5.x.x.tar.gz
  2、 cd net-snmp-5.x.x
  3、 ./configure -prefix=/usr/local/snmp(这里有很多询问,没有关系,一路回车)
  4、 make && make install
  5、至此已经全部安装完成,现在就是开始设置snmpd.conf文件,这个文件是不能安装创建的,而是在安装的目录下生成了一个叫EXAMPLE.conf的文件,可以将这个文件拷贝到/etc/snmp/snmdp.conf。
  6、cp EXAMPLE.conf /etc/snmp/snmpd.conf(然后这个文件的设置同上)
四、安装cacti 我们使用cacti-0.8.6j
 1、安装cacti
# useradd cactiuser -g users
# passwd cactiuser (pwd:cactipw)
# cd /export1/soft
# tar -zvxf cacti-0.8.6j.tar.gz
# cp -r cacti-0.8.6j /var/www/cacti
# cd /var/www/cacti
创建数据库cacti
# /usr/local/mysql/bin/mysql -uroot -p
Mysql> create database cacti;
Mysql>\q
# /usr/local/mysql/bin/mysql -u root -p111111 -f -D cacti<cacti.sql
# chown -R cactiuser rra/ log/
# cd scripts
# chown cactiuser:user *
# /usr/local/mysql/bin/mysql -uroot -p
Mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY ‘111111’
Mysql>WITH GRANT OPTION;
Mysql>flush privileges;
Mysql>\q
# vi /var/www/cacti/include/config.php
$database_type = “mysql”;
$database_default = “cacti”; $database_hostname = “localhost”; $database_username = “cactiuser”; $database_password = “cactipw”;
安装补丁,可以去它的官方网站上下载。www.cacti.net <http://www.cacti.net>
# wget http://www.cacti.net/downloads/patches/0.8.6j/ping_php_version4_snmpgetnext.patch
# wget http://www.cacti.net/downloads/patches/0.8.6j/tree_console_missing_hosts.patch
# wget http://www.cacti.net/downloads/patches/0.8.6j/thumbnail_graphs_not_working.patch
# wget http://www.cacti.net/downloads/patches/0.8.6j/graph_debug_lockup_fix.patch
# wget http://www.cacti.net/downloads/patches/0.8.6j/snmpwalk_fix.patch
patch -p1 -N < ping_php_version4_snmpgetnext.patch
patch -p1 -N < tree_console_missing_hosts.patch
patch -p1 -N < thumbnail_graphs_not_working.patch
patch -p1 -N < graph_debug_lockup_fix.patch
patch -p1 -N < snmpwalk_fix.patch
只要按照cacti的存放路径,补足路径就可以把补丁打上了。
# crontab -u cactiuser -e
加入
*/5 * * * * /export1/server/php/bin/php /www/htdocs/cacti/poller.php > /dev/null 2>&1
保存退出:wq
全部设置完毕。
打开浏览器 http://192.168.1.99/cacti 进入cacti的初始设置页面 第一次默认登陆账号:admin 密码 admin J 登陆后在新改个密码就OK 需要说明的还有路径
snmpwalk Binary Path : /usr/bin/snmpwalk
snmpget Binary Path: /usr/bin/snmpget RRDTool Binary Path: /export1/server/rrdtool/rrdtool PHP Binary Path: /export1/server/php/bin/php Cacti Log File Path: /var/www/cacti/log/cacti.log Cactid Poller File Path: /var/www/cacti/poller.php 如果你是按我的步骤做的 那上面的路径一定不会错。   注:此时graphs还不能显示图形,需要将服务重新启动一下
[root@Bleach scripts]# service snmpd restart
[root@Bleach scripts]# service mysql restart [root@Bleach scripts]# service httpd restart
再打开你就能看到抓取的图形了。如果出现问题,按照上面的步骤仔细查看,一定能找出问题来。
相关阅读 更多 +
排行榜 更多 +
盒子小镇2游戏手机版下载

盒子小镇2游戏手机版下载

冒险解谜 下载
世界盒子模组版下载最新版本

世界盒子模组版下载最新版本

模拟经营 下载
音乐搜索app最新版本下载

音乐搜索app最新版本下载

趣味娱乐 下载