- 论坛徽章:
- 0
|
近日研究mrtg的使用,有一些心得,希望能够跟大家共同分享.网上介绍在linux AS 3.0版本上调试mrtg的文章很少,下面我把我实作的笔记提供给大家,希望对大家有些帮助!
环境:linux AS 3.0
ip:192.168.1.127
需要gcc,net-snmp的支持
1.安装zlib-1.2.3
#tar zxvf zlib-1.2.3.tar.gz
#cd zlib-1.2.3
#./configure --prefix=/usr/local/zlib
#make
#make install
2.安装libpng-1.2.20.tar.gz
#tar zxvf libpng-1.2.20.tar.gz
#cd libpng-1.2.20
#cp scripts/makefile.std makefile
#make
#make install
3.安装sysstat-8.0.0.tar.tar
#tar zxvf sysstat-8.0.0.tar.tar
#cd sysstat-8.0.0
#./configure --prefix=/usr/local/sysstat
#make
#make install
4.安装gd-2.0.33.tar.gz
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/usr/local/gd
make
make install
5.安装apache-2.2.6
tar zxvf httpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure --prefix=/usr/local/apache
make
make install
6.安装mrtg-2.15.2.tar.gz
#tar zxvf mrtg-2.15.2.tar.gz
#cd mrtg-2.15.2
#./configure --prefix=/usr/local/mrtg --with-gd=/usr/local/gd/include --with-gd-lib=/usr/local/gd/lib --with-gd-
inc=/usr/local/gd/include --with-png=/usr/local/include --with-png-lib=/usr/local/lib --with-zlib=/usr/local/zlib/include --
with-zlib-lib=/usr/local/zlib/lib
#make
#make install
关于snmpd
vi /etc/snmp/snmpd.conf
access notConfigGroup "" any noauth exact systemview none none
改成
access notConfigGroup "" any noauth exact mib2 none none
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
去掉前面的#号
/etc/rc.d/init.d/snmpd start 启动snmp服务
[root@localhost home]# netstat -ntulp |grep snmp
tcp 0 0 0.0.0.0:199 0.0.0.0:* LISTEN 31786/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 31786/snmpd
关于apache
建议把/usr/local/apache/conf/httpd.conf备份,cp httpd.conf httpd.conf.bak,这样如有配置异常可以再恢复
httpd.conf下的文档根目录为:
DocumentRoot "/usr/local/apache/htdocs"
这个目录路径可以根据你的需要进行改动,我使用的是上面默认的根路径
启动apache服务
[root@localhost home]# /usr/local/apache/bin/apachectl start
如需每次开机自动启动apache服务,请在/etc/rc.local下加入/usr/local/apache/bin/apachectl start即可
mrtg调试
创建/usr/local/apache/htdocs/mrtg目录,其下创建cpu,ram,net,lsof目录
[root@localhost mrtg]# /usr/local/mrtg/bin/cfgmaker --output=/usr/local/apache/htdocs/mrtg/net/net.cfg public@192.168.1.251
注:这里的192.168.1.251为监视的服务器
[root@localhost net]# vi net.cfg
#WorkDir: /home/http/mrtg
改为:WorkDir: /usr/local/apache/htdocs/mrtg/net(去掉#号注释然后要顶格写,否则启动mrtg会报错)
# Options[_]: growright, bits
去掉前面的#号注释
再添加一行配置项:Language:GB2312
[root@localhost net]# /usr/local/mrtg/bin/mrtg /usr/local/apache/htdocs/mrtg/net/net.cfg会报错,依照提示使用:
[root@localhost net]# env LANG=C /usr/local/mrtg/bin/mrtg /usr/local/apache/htdocs/mrtg/net/net.cfg
连续运行3次,会发现没有报错提示,说明正常,否则检查错误的原因.
生成mrtg显示信息页面
[root@localhost net]# /usr/local/mrtg/bin/indexmaker --output=/usr/local/apache/htdocs/mrtg/net/index.html --title=netloading
/usr/local/apache/htdocs/mrtg/net/net.cfg
linux计划任务:
crontab -l是显示自定义的计划任务,而crontab -e则为编辑自定的计划任务,使用crontab -e编辑定时自动运行mrtg来生成统计信息
*/5 * * * * /usr/local/mrtg/bin/mrtg /usr/local/apache/htdocs/mrtg/net/net.cfg
PS:关于linux 添加计划任务详情请查阅crontab的用法,/etc/cron.*的可以编制相应的脚本程序进行计划任务的运用,在这里我就不再多作说明
了.
重启snmp和apache服务
[root@localhost net]# service snmpd restart
[root@localhost net]# /usr/local/apache/bin/apachectl restart
浏览url:
http://192.168.1.127/mrtg/net可以观察到网络流量图了
下篇是关于mrtg的监控配置,准备更新中......... |
|