Bu kısacık belgede;
1. Router (ADSL Modem) Trafiğinin MRTG ile İzlenmesi
2. MRTG+SNMP Kurulu Sunucunun Trafiğinin MRTG ile İzlenmesi
anlatılmaktadır. Bu işlem i�in bir adet Debian Sarge kurulu linux sunucu ve bir adet router yeterli olmaktadır.
Router IP: 192.168.1.1
Debian IP: 192.168.1.2
# apt-get install mrtg mrtgutils mrtg-contrib libsnmp-session-perl rrdtool librrds-perl
# cd /etc # cp mrtg.cfg mrtg.cfg.orig
Menu 22 - SNMP Configuration SNMP: Get Community= public Set Community= public Trusted Host= 192.168.1.2 Trap: Community= public Destination= 0.0.0.0
# cfgmaker --global 'WorkDir: /var/www/mrtg' \ --global 'Options[_]: bits,growright' \ --output /root/mrtg.cfg \ [email protected]
MaxBytes[192.168.1.1_1]: 64000 <TR><TD>Max Speed:</TD> <TD>512.0 kbits/s</TD></TR> MaxBytes[192.168.1.1_2]: 64000 <TR><TD>Max Speed:</TD> <TD>512.0 kbits/s</TD></TR>
LogFormat: rrdtool
IconDir: /mrtg
# cp /root/mrtg.cfg /etc/
# cd /root # wget ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz # tar xzvf mrtg-rrd-0.7.tar.gz # cd mrtg-rrd-0.7 # vim mrtg-rrd.cgi BEGIN { @config_files = qw(/etc/mrtg.cfg); } # cp mrtg-rrd.cgi /var/lib/cgi-bin/
# /usr/bin/mrtg /etc/mrtg.cfg
0-55/5 * * * * root if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; \ then env LANG=C /usr/bin/mrtg /etc/mrtg.cfg >> /var/log/mrtg/mrtg.log 2>&1; fi
Eğer yukarıdaki �alışmıyorsa aşağıdaki gibi bir satır da crontab'a eklenebilir.
# crontab -e */5 * * * * /usr/bin/mrtg /etc/mrtg.cfg --logging /var/log/mrtg/mrtg.log
# chown www-data /etc/mrtg.cfg # chown www-data /var/www/mrtg # chown www-data /var/www/mrtg/*
$links http://localhost/cgi-bin/mrtg-rrd.cgi
# apt-get install snmp snmpd
# vim /etc/snmp/snmpd.conf
com2sec paranoid default public #com2sec readonly default public #com2sec readwrite default private
#com2sec paranoid default public com2sec readonly 127.0.0.1 public #com2sec readwrite default private
# /etc/init.d/snmpd restart
# sysv-rc-conf
$ snmpwalk -v 1 -OS -c public localhost interfaces.ifTable.ifEntry.ifDescr
IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: eth0
# cfgmaker --global 'WorkDir: /var/www/mrtg' \ --global 'Options[_]: bits,growright' \ --output /root/mrtg_local.cfg \ [email protected]
### Interface 2 >> Descr: 'eth0' | Name: '' | Ip: '192.168.1.2' | Eth: '00-e0-40-00-03-f5' ### Target[127.0.0.1_2]: 2:[email protected]: SetEnv[127.0.0.1_2]: MRTG_INT_IP="192.168.1.2" MRTG_INT_DESCR="eth0" MaxBytes[127.0.0.1_2]: 12500000 Title[127.0.0.1_2]: Traffic Analysis for 2 -- mor PageTop[127.0.0.1_2]: <H1>Traffic Analysis for 2 -- mor</H1> <TABLE> <TR><TD>System:</TD> <TD>mor in Unknown (configure /etc/snmp/snmpd.local.conf)</TD></TR> <TR><TD>Maintainer:</TD> <TD>Root <root@localhost> (configure /etc/snmp/snmpd.local.conf)</TD></TR> <TR><TD>Description:</TD><TD>eth0 </TD></TR> <TR><TD>ifType:</TD> <TD>ethernetCsmacd (6)</TD></TR> <TR><TD>ifName:</TD> <TD></TD></TR> <TR><TD>Max Speed:</TD> <TD>100.0 Mbits/s</TD></TR> <TR><TD>Ip:</TD> <TD>192.168.1.2 (mor.arena.lan)</TD></TR> </TABLE>
MaxBytes[127.0.0.1_2]: 64000 <TR><TD>Max Speed:</TD> <TD>512.0 kbits/s</TD></TR>
# /usr/bin/mrtg /etc/mrtg_local.cfg
$ firefox http://localhost/cgi-bin/mrtg-rrd.cgi
Kurulum işlemi bittikten sonra, network trafiğimizi kem g�zlerden sakınmak(sadece belirli IP'lerden bağlanılabilmesi) i�in apache web sunucunda bazı ayarlar yapmamız gerekmektedir.
# vim /etc/apache/httpd.conf
<Directory /var/www/mrtg> order deny,allow deny from all allow from </Directory>
MRTG logları "/var/log/mrtg.log" dosyasında tutulamktadır. Bu dosyanın d�zenli olarak d�nd�r�lmesi i�in gerekli "logrotate" dosyası aşağıdaki gibidir. Bu dosya apt-get ile mrtg kurulumu sırasında oluşur.
# vim /etc/logrotate.d/mrtg
/var/log/mrtg/mrtg.log { weekly rotate 12 compress missingok }
Kaynaklar:
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/mrtg-unix-guide.html
http://apt-get.dk/mrts/
http://www.geocities.com/paulcwilliamson/mrtg/rateup2rrd.html