View RSS Feed

admin

บันทึกการติดตั้ง MRTG on Debian 5 Lenny

Rate this Entry
โดย เมื่อ 31st January 2010 เวลา 13:27:52 (1513 เปิดอ่าน)
สำหรับ MRTG นั้น เป็นตัว Monitor Router เพื่อไว้ทำการดู traffic ต่าง ๆ ในเครื่อง ซึ่งสามารถ config ได้และสามารถเลือกดูได้หลาย ๆ อย่าง สำหรับการลง MRTG ได้นั้นต้องมีการลง package บางอย่างที่จำเป็นเบื้องต้นก่อนคือ
- Apache webserver with perl support
- NET-SNMP
- GD
- Libpng
- zlib

ในขั้นตอนแรกนั้นเราจะทำ การลง package ที่ใช้ในการทำ compiler ก่อนนะครับ
#apt-get install gcc make g++

ต่อไปก็จะเป็นการลงตัว Apache นะครับซึ่งจะทำหน้าที่เป็น Webserver โดยในที่นี้ผมจะลง Apache version 2 ครับ ซึ่งเป็น version ล่าสุด
#apt-get install apache2

เมื่อทำการโหลดจนเสร็จแล้วต่อไปจะเป็นการ config ครับโดยปกติแล้ว ไฟล์ config ทั้งหมดของ Apache2 นั้นจะอยู่ที่ /etc/apache2 ครับ และไฟล์พวก document ต่าง ๆ นั้นจะอยู่ที่ /var/www ครับ ซึ่งถ้าหากเราต้องการจะเปลี่ยนนั้นก็สามารถทำได้โดยการพิมพ์
#vi /etc/apache2/sites-available/default

จากนั้นหาบรรทัด DocumentRoot /var/www/ แล้วจึงแก้เป็นโฟลเดอร์ที่เราต้องการเก็บ
ส่วนการ config apache2 หลัก ๆ นั้นคือไฟล์ /etc/apache2/apche2.conf
หลังจากที่เราเตรียม package ต่าง ๆ ที่จำเป็นในการลง MRTG เสร็จเรียบร้อยแล้วนะครับ ต่อไปจะเป็นการลง MRTG ครับ โดยพิมพ์
#apt-get install mrtg snmpd snmp

หลัง จากการลง MRTG นั้น ตัวโปรแกรมจะทำการ create subdirectory ที่ /var/www/mrtg นะครับ

ต่อไปจะเป็นการ config snmpd โดยพิมพ์
#vi /etc/snmp/snmpd.conf

แล้วทำการแก้ให้เป็นแบบนี้นะครับ

# sec.name source community
#com2sec paranoid default public
com2sec readonly default public
#com2sec readwrite default private

restart snmpd ซักครั้งนะครับ
#/etc/init.d/snmpd restart

จากนั้น เซพแล้วออกมาครับ ต่อไปจะเป็นการสร้างไฟล์ config ของ MRTG ขึ้นมาครับโดยใช้คำสั่้ง
#cfgmaker -global "options[_]:bits,growright" --global "workdir:/var/www/mrtg" public@127.0.0.1 > /etc/mrtg.cfg

จาก นั้นเข้าไปทำการแก้ไข mrtg.cfg เพิ่มเติมนะครับ เืพื่อให้มีสามารถ mornitor process อื่น ๆ ได้ีอีกเช่น CPU Load, Memory Usage, Disk Usage ฯลฯ#vi /etc/mrtg.cfg

แล้วเพิ่มคำสั่งเหล่านี้เข้าไปด้านล่างครับ

### Load Average ###
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2ublic@127.0.0.1
MaxBytes[cpu]: 100
Unscaled[cpu]: dwmy
Options[cpu]: gauge, absolute, growright, noinfo, nopercent
YLegend[cpu]: CPU Load(%)
ShortLegend[cpu]: (%)
LegendI[cpu]:   CPU System
LegendO[cpu]:   CPU User
Title[cpu]: CPU Analysis
PageTop[cpu]:

CPU Analysis



### Memory Free ###
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0ublic@127.0.0.1
MaxBytes1[mem]: 1030288
MaxBytes2[mem]: 1052216
Unscaled[mem]: dwmy
Options[mem]: gauge, absolute, growright, noinfo
YLegend[mem]: Memory Free
ShortLegend[mem]: Bytes
kilo[mem]: 1024
kMG[mem]: k,M,G,T,P
LegendI[mem]: Real
LegendO[mem]: Swap
Legend1[mem]: (MBytes)
Legend2[mem]: (MBytes)
Title[mem]: Memory Analysis
PageTop[mem]:

Memory Analysis



### New TCP Connection Monitoring (per minute) ###
Target[server.newconns]: tcpPassiveOpens.0&tcpActiveOpens.0ublic@127.0.0.1
Title[server.newconns]: Newly Created TCP Connections
PageTop[server.newconns]:

New TCP Connections


MaxBytes[server.newconns]: 10000000000
ShortLegend[server.newconns]: c/s
YLegend[server.newconns]: Conns / Min
LegendI[server.newconns]: In
LegendO[server.newconns]: Out
Legend1[server.newconns]: New inbound connections
Legend2[server.newconns]: New outbound connections
Options[server.newconns]: growright,nopercent,perminute

### Established TCP Connections ###
Target[server.estabcons]: tcpCurrEstab.0&tcpCurrEstab.0ublic@127.0.0.1
Title[server.estabcons]: Currently Established TCP Connections
PageTop[server.estabcons]:

Established TCP Connections


MaxBytes[server.estabcons]: 10000000000
ShortLegend[server.estabcons]:
YLegend[server.estabcons]: Connections
LegendI[server.estabcons]: In
LegendO[server.estabcons]:
Legend1[server.estabcons]: Established connections
Legend2[server.estabcons]:
Options[server.estabcons]: growright,nopercent,gauge

# Disk usage monitoring
Target[disk_cafe5]: `etc/mrtg/df-mrtg`
Title[disk_cafe5]: Disk Usage -- suse10
Unscaled[disk_cafe5]: dwym
MaxBytes[disk_cafe5]: 24931728
PageTop[disk_cafe5]:

Disk Usage -- suse10


kmg[disk_cafe5]: KB,MB,GB
LegendI[disk_cafe5]: Used Disk Space
LegendO[disk_cafe5]: Total Disk Space
Legend1[disk_cafe5]: Used Disk Space
Legend2[disk_cafe5]: Total Disk Space
YLegend[disk_cafe5]: Megabytes
ShortLegend[disk_cafe5]:
Options[disk_cafe5]: gauge, growright, noinfo

จากนั้น MRTG ของเราก็จะ config เกือบจะสมบูรณ์แล้วครับ แต่ติดอยู่ตรงที่แสดง Disk Usage ภายในเครื่องของเราครับ จะต้องมีการ config อีกเล็กน้อยจึงจะใช้งานได้ครับโดยการ
#mkdir /etc/mrtg
#vi /etc/mrtg/df-mrtg

แล้วนำคำสั่งเหล่านี้ใส่ลงไปครับ

Code:
#!/bin/sh

PATH=/bin:/usr/bin

part=$1

# The external mrtg  probe returns up to 4 lines of output:
#       1. Line: current  state of the 'incoming bytes counter'
#       2. Line: current state of the 'outgoing bytes counter'
#       3. Line: string,  telling the uptime of the target.
#        4. Line: telling the name of the target.

# df=`df  --block-size=1 $part | tail -1` # mrtg can't cope with bignums
df=`df $part | tail -1`

# we'll list the  available blocks as "incoming" as that's the solid green bar

echo $df | awk '{print  $4}' # available
echo $df |  awk '{print $3}' # used
uptime | cut  -d, -f 1 | awk '{print $3, $4}'
echo  $df | awk '{print $1}'


ต่อไปจะเป็นการสร้าง index ไฟล์นะครับเพื่อให้อ้างอิงถึงรูปโดยการพิมพ์
#indexmaker --columns=1 --output=/var/www/mrtg/index.html /etc/mrtg.cfg

จากนั้นสั่ง
#env LANG=C /usr/bin/mrtg /etc/mrtg.cfg
#env LANG=C /usr/bin/mrtg /etc/mrtg.cfg
#env LANG=C /usr/bin/mrtg /etc/mrtg.cfg
3 ครั้งครับ

จากนั้น เป็นการแก้ไฟล์ crontab เพื่อสั่งให้มีการทำงานทุก ๆ 5 นาทีนะครับ
#vi crontab -e

แล้ว ใส่คำสั่งเหล่านี้ลงไป
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg.cfg
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/df.cfg

จากนั้นทำการ add alias ให้กับ apache นะครับ
#vi /etc/apache/conf.d/mrtg.conf

โดยการใส่คำสั่งเหล่านี้ลง ไปครับ
Alias /mrtg /var/www/mrtg

Order deny,allow
Deny from all
Allow from localhost
Allow from all
# Allow from .example.com


สุดท้าย ก็ restart Apache กับ cron นะครับ
#/etc/init.d/apache2 restart
#/etc/init.d/cron restart


เท่านี้ก็ได้ MRTG ไว้ monitor ดู traffic ในเครื่องแล้วนะครับ
ป้ายกำกับ: mrtg, การติดตั้ง MRTG เพิ่ม / แก้ไข ป้ายกำกับ
หัวข้อ
How To , Linux

ความคิดเห็น

 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31