30 มิ.ย. 2557

ติดตั้ง mrtg บน Ubuntu 12.04

ติดตั้ง snmpd
# apt-get install snmp snmpd
# apt-get install snmp-mibs-downloader
เก็บไฟล์ config ของแท้ไว้
# cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.ori
# nano /etc/snmp/snmpd.conf
ใส่ # ไว้หน้า agentAddress  udp:127.0.0.1:161
ลบ # หน้า agentAddress udp:161,udp6:[::1]:161 ออก
ใส่ # ไว้หน้า rocommunity public  default    -V systemonly
เพิ่ม rocommunity public ลงไป


กรณ๊ให้เรียกข้อมูลจากเครื่องอื่นๆ ได้แก้ดังนี้
#  Listen for connections from the local system only
#agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161

สั่ง snmpd restart
# /etc/init.d/snmpd rstart
ทดสอบ
# snmpwalk -O s -v 1 -c public localhost

จากนั้น ทำการติดตั้ง mrtg
# apt-get install mrtg
ระหว่างติดตั้งจะมีหน้าต่างขึ้นมาถาม ให้ตอบ Yes
เมื่อติดตั้งเสร็จ ให้ทำการสร้างไฟล์คอนฟิกไปที่ /etc/mrtg.cfg
# cfgmaker --output=/etc/mrtg.cfg public@localhost
จากนั้นไปแก้ไขไฟล์ /etc/mrtg.cfg โดยให้ WorkDir เป็น /var/www/mrtg
(ให้ไปสร้างรอไว้ด้วยเลย)

เพิ่มบรรทัดต่อไปนี้หลัง Global Defaults section:

RunAsDaemon: Yes
Interval: 5
Logdir: /var/log/
EnableIPv6: no

กรณีดึง snmp จากเครื่องอื่น
Target[111.111.111.1_eth0]: #eth0:public@111.111.111.1:
SetEnv[111.111.111.1_eth0]: MRTG_INT_IP="111.111.111.1" MRTG_INT_DESCR="eth0"
MaxBytes[111.111.111.1_eth0]: 0
Title[111.111.111.1_eth0]: Traffic Analysis for eth0 -- xxx1
PageTop[111.111.111.1_eth0]: <h1>Traffic Analysis for eth0 -- xxx1</h1>

Target[111.111.111.1_lo]: #lo:public@111.111.111.1:
SetEnv[111.111.111.1_lo]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo"
MaxBytes[111.111.111.1_lo]: 1250000
Title[111.111.111.1_lo]: Traffic Analysis for lo -- xxx1
PageTop[111.111.111.1_lo]: <h1>Traffic Analysis for lo -- xxx1</h1>

กรณีดึง snmp จากเครื่องนั้นเอง
Target[127.0.0.1_1]: 1:public@127.0.0.1:
SetEnv[127.0.0.1_1]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo"
MaxBytes[127.0.0.1_1]: 1250000
Title[127.0.0.1_1]: Traffic Analysis for local loopback
PageTop[127.0.0.1_1]: <h1>Traffic Analysis for local loopback</h1>

Target[127.0.0.1_eth0]: #eth0:public@127.0.0.1:
SetEnv[127.0.0.1_eth0]: MRTG_INT_IP="000.000.000.0" MRTG_INT_DESCR="eth0"
maxBytes[127.0.0.1_eth0]: 1250000
Title[127.0.0.1_eth0]: Traffic Analysis for eth0 -- xxx1.go.th
PageTop[127.0.0.1_eth0]: <h1>Traffic Analysis for eth0 -- xxx1.go.th</h1>

จากนั้นสร้าง index ไฟล์ขึ้นมา

# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg.cfg

แล้วเริ่มเรียกให้ mrtg ทำงานได้เลยตามนี้

# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

หมายเหตุ : อย่าลืมเปิด port UDP 161 ด้วย

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

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