在Redhat Linux 9.0系统中的MRTG简单实验配置
时间:2007-06-04 来源:一路狂笑
在Redhat Linux 9.0系统中的MRTG简单实验配置
2007-06-04 kenthy#qingdaonews.com
[完善配置参考:《基于Ubuntu6.06的MRTG网络流量分析统计》]
############################################
系统环境: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: www.redhat.com 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/www.sh
# vi /etc/mrtg/www.sh
#!/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/www.sh 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 [email protected]
#cat >> /etc/mrtg.cfg << "EOF"
Target[www]: `/opt/mrtg/www.sh`
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]: <H1> WWW Connect Statistic </H1>
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 www.redhat.com
DocumentRoot "/var/www/html/"
# /etc/init.d/httpd start 三、测试
使用浏览器访问http://192.168.1.1/mrtg/
系统环境: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: www.redhat.com 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/www.sh
# vi /etc/mrtg/www.sh
#!/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/www.sh 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 [email protected]
#cat >> /etc/mrtg.cfg << "EOF"
Target[www]: `/opt/mrtg/www.sh`
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]: <H1> WWW Connect Statistic </H1>
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 www.redhat.com
DocumentRoot "/var/www/html/"
# /etc/init.d/httpd start 三、测试
使用浏览器访问http://192.168.1.1/mrtg/
相关阅读 更多 +