วันจันทร์ที่ 30 ธันวาคม พ.ศ. 2556

MRTG (Multi Router Traffic Grapher)

 ในการบริหารจัดการเครือข่ายคอมพิวเตอร์ภายในองค์กรจำเป็นต้องมีเครื่องมือที่สามารถช่วยวิเคราะห์ มอนิเตอร์ดู Traffic Load บน Network Links ซึ่ง โปรแกรมที่สามารถมอนิเตอร์ระบบเครือข่าย นำข้อมูลมารวบรวมไว้ และนำเสนอเป็นรูปกราฟผ่านเว็บเพจโดยผู้จัดการระบบสามารถมอนิเตอร์ ข้อมูลผ่านโปรแกรมเว็บบราวเซอร์ได้ทันที ซึ่งโปรแกรมที่กล่าวมาคือโปรแกรม MRTG (Multi Router Traffic Grapher) การติดตั้งมีรายละเอียด ดังต่อไปนี้
 
โปรแกรมต่างๆ ที่เกี่ยวข้อง
gd-2.0.33.tar.gz ดาว์นโหลดได้จากเว็บไซต์ http://www.boutell.com 
mrtg-2.16.2.tar.gz ดาว์นโหลดได้จากเว็บไซต์ 
http://oss.oetiker.ch/mrtg/download.en.html
zlib-1.2.3.tar.gz ดาวน์โหลดได้จากเว็บไซต์ http://www.zlib.net/zlib-1.2.3.tar.gz
libpng-1.2.29.tar.gz ดาวน์โหลดได้จากเว็บไซต์ http://www.libpng.org/pub/png/src
หรือใช้คำสั่ง wget ลงในพื้นที่ที่ต้องการ อาทิเช่น cd /usr/local/src แล้วจึงดาวน์โหลด ดังต่อไปนี้
wget 
www.boutell.com/gd/http/gd-2.0.33.tar.gz
wget oss.oetiker.ch/mrtg/pub/mrtg-2.16.2.tar.gz 
wget 
www.zlib.net/zlib-1.2.3.tar.gz
ติดตั้ง zlib
$ tar zxvf zlib-1.2.3.tar.gz
$ rm zlib-1.2.3.tar.gz
$ mv zlib-1.2.3 zlib
$ cd zlib
$ ./configure
$ make
$ cd ..
ติดตั้ง libpng (Library Portable Network Graphics)
$ tar zxvf libpng-1.2.29.tar.gz
$ rm libpng-1.2.29.tar.gz
$ mv libpng-1.2.29 libpng
$ cd libpng
$ make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib
$ rm *.so.* *.so
$ cd ..
ติดตั้ง gd (GD Graphics Library)
$ tar zxvf gd-2.0.33.tar.gz
$ mv gd-2.0.33 gd
$ cd gd
$ env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng"
$ ./configure --disable-shared --without-freetype --without-jpeg
$ make
$ cp .libs/* .
$ cd ..  
ติดตั้ง MRTG (Multi Router Traffic Grapher)
$ tar zxvf mrtg-2.16.2.tar.gz
$ mv mrtg-2.16.2 mrtg
$ cd mrtg-2.16.2
$ ./configure --prefix=/usr/local/mrtg \
   --with-gd=/usr/local/src/gd \
   --with-z=/usr/local/src/zlib \
   --with-png=/usr/local/src/libpng
$ make
$ make install

สร้างไดเร็คทอรี่ที่ใช้เก็บ output ของโปรแกรม MRTG ไว้ที่ Document Root ของ Apache
mkdir /var/www/htdocs/mrtg
สร้างไดเร็คทอรี่สำหรับเก็บคอนฟิกของ MRTG ไว้ภายใต้ Home Directory ของ root เอง 
mkdir /root/mrtg
cd /usr/local/mrtg/bin/
ใช้ยูทิลิตี้ cfgmaker ช่วยสร้างไฟล์คอนฟิก มีพารามิเตอร์ดังนี้ หมายเหตุ เบอร์ ip wan ของ router เช่น xxx.xxx.xxx.xxx
$ cd /usr/local/mrtg/bin
$ cfgmaker --global 'WorkDir: /home/httpd/mrtg' \
   --global 'Options[_]: bits,growright' \
   --output /home/mrtg/cfg/mrtg.cfg community@xxx.xxx.xxx.xxx
เมื่อพิมพ์คำสั่งไปแล้วจะมีข้อความเพื่ออ่านค่าพารามิเตอร์ของพอร์ตต่างๆ บน Router ไปเก็บลงไฟล์ mrtg.cfg แต่ถ้ามี error เกิดขึ้น แสดงว่า Router ไม่ได้เปิด service snmp ต้องไป config ที่ router เพื่อเปิด service
สั่งให้ mrtg ทำงาน โดยการรันครั้งแรกนี้จะมีข้อความเกี่ยวกับ log file ฟ้องขึ้นมา ซึ่งไม่ต้องตกใจ เพราะเป็นภาวะปกติสำหรับการรัน mrtg สองครั้งแรก
$ /usr/local/mrtg/bin/mrtg /home/mrtg/cfg/mrtg.cfg
ตั้งให้ mrtg ทำงานทุกๆ 5 นาที
$ ee /home/mrtg/mrtg.cron
เพิ่มบรรทัดข่างล่างลงไป
0-59/5 * * * * /usr/local/mrtg/bin/mrtg /home/mrtg/cfg/mrtg.cfg
สั่งให้ Crontab ทำงาน โดยใช้คำสั่ง ดังต่อไปนี้
$ crontab /home/mrtg/mrtg.cron

วิธีการ config router เพื่อเปิด service snmp ใช้คำสั่ง Remote เข้าไปที่ router
telnet xxx.xxx.xxx.xxx      ; xxx.xxx.xxx.xxx คือหมายลข IP ของ router
User Access Verification
Password:
มันจะถามให้ใส่ Password ให้ใส่ Password ของ router ลงไป
Router>
ให้พิมพ์คำสั่ง ena
Router>ena
Password: 
มันจะถามให้ใส่ Password ให้ใส่ Enable Password ของ router ลงไป
Router#
ให้พิมพ์คำสั่ง conf t
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
ให้พิมพ์คำสั่ง snmp-server community public ro
Router(config)#snmp-server community public ro
Router(config)#exit
Router#wr mem
Router#exit
 
ทดสอบดูข้อมูล Traffic บนผ่านโปรแกรมเว็บบราวเซอร์ได้ ที่ http://xxx.xxxx.xxx/mrtg หรือตำแหน่งของเว็บเพจที่เรากำหนดในเว็บเซิร์ฟเวอร์

ไม่มีความคิดเห็น:

แสดงความคิดเห็น