在Redhat Linux 9.0系统中的MRTG简单实验配置
2007-06-04 kenthy#qingdaonews.com
############################################
系统环境:Redhat Linux 9.0 [ 2.4.20.8 ]
软件版本:
perl-CGI-2.81-88
mrtg-2.9.17-13
httpd-2.0.40-21
libpng10-1.0.13-8
libpng-1.2.2-16
目标功能:
Server1: 192.168.1.1/24
###############################################
一、安装
各软件使用RH9光盘中自带的rpm包安装,[步骤略]
二、配置
1、配置snmpd
# vi /etc/snmp/snmpd.conf
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
access notConfigGroup "" any noauth exact mib2 none none
# /etc/init.d/snmpd start
2、创建web流量监控脚本/etc/mrtg/
# vi /etc/mrtg/
#!/bin/bash
all=`netstat -a | grep www|awk '{print $5}'|sort | wc -l|awk '{print$1 - 1}'`
user=`netstat -a | grep www|awk '{print $5}'|cut -d":" -f1|sort| uniq |wc -l | awk '{print $1 - 1}'`
if [ "$all" = "-1" ]; then
echo 0
else
echo $all
fi
if [ "$user" = "-1" ]; then
echo 0
else
echo $user
fi
UPtime=`/usr/bin/uptime | awk '{print $3 " " $4 " " $5}'`
echo $UPtime
hostname
# chmod +x /etc/mrtg/
3、配置mrtg.cfg
# mkdir -p /var/www/html/mrtg
# cfgmaker --global "WorkDir:/var/www/html/mrtg" --global "Options[_]:growright,bits" --global "Language:GB2312" --
ifref=ip --output /etc/mrtg/mrtg.cfg
#cat >> /etc/mrtg.cfg << "EOF"
Target[www]: `/opt/mrtg/`
MaxBytes[www]: 500
Options[www]: nopercent, growright
YLegend[www]: Online Users
ShortLegend[www]: %
LegendI[www]: Connect :
LegendO[www]: Online :
Title[www]: WWW Connect
PageTop[www]:
WWW Connect Statistic
EOF
4、启动mrtg,创建index.html文件
# /usr/bin/mrtg /etc/mrtg/mrtg.cfg
# /usr/bin/indexmaker /etc/mrtg/mrtg.cfg > /var/www/html/mrtg/index.html
# crontab -e
*/5 * * * * /usr/bin/mrtg /etc/mrtg/mrtg.cfg
# chkconfig --level 2345 crond on
# service crond start
5、配置httpd
# vi /etc/httpd/conf/httpd.conf
ServerName
DocumentRoot "/var/www/html/"
# /etc/init.d/httpd start
三、测试
使用浏览器访问
阅读(886) | 评论(0) | 转发(0) |