[ubuntu]安裝MRTG

參考網址:在Linux上安裝MRTG流量監控套件

indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html 時發生錯誤

https://stackoverflow.com/questions/16372969/mrtg-error-did-not-find-any-matching-data-in-cfg-file

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>

 

 

https://bigair.pixnet.net/blog/post/22969043

 

這篇比較新,安裝在/var/www/mrtg 用Alias /mrtg "/var/www/mrtg/" 的方式改成/mrtg
https://hackmd.io/@nikerdy/rkCs0m7Qr

執行env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 出現錯誤
Received SNMP response with error code error status: noSuchName index 2 (OID: 1.3.6.1.2.1.2.2.1.16.1) SNMPv1_Session
解決方法參考https://www.linuxquestions.org/questions/linux-networking-3/snmp-response-error-nosuchname-79138/
The default settings of the SNMP were too restrictive for MTRG to access what it needed. Here is the revised section of the snmpd.conf file:
 

Code:

####
# First, map the community name "public" into a "security name"

#       sec.name  source          community
com2sec linuxbox  default       public

####
# Second, map the security name into a group name:

#       groupName      securityModel securityName
group   mrtggrp v1           linuxbox
group   mrtggrp v2c          linuxbox

####
# Third, create a view for us to let the group have rights to:

#       name           incl/excl     subtree         mask(optional)
view    mrtgview        included        .1          80

####
# Finally, grant the group read-only access to the systemview view.

#       group          context sec.model sec.level prefix read   write  notif
access  mrtggrp ""      any       noauth    exact  mrtgview none none

# -----------------------------------------------------------------------------

 

lubuntu 22.04 安裝過程記錄
 

apt-get install snmpd snmp
vi /etc/snmp/snmpd.conf
新增一行 rocommunity public localhost

重啟 snmpd
systemctl restart snmpd

測試snmpd
snmpwalk -v 2c -c public localhost

安裝 MRTG
apt-get install mrtg

重建 /etc/mrtg.cfg 檔案
cfgmaker public@localhost > /etc/mrtg.cfg

建立給 MRTG 的首頁
indexmaker /etc/mrtg.cfg > /var/www/html/mrtg/index.html
如果有出現ERROR: did not find any matching data in cfg file 才需要做

再做一次indexmaker /etc/mrtg.cfg > /var/www/html/mrtg/index.html

env LANG=C /usr/bin/mrtg /etc/mrtg.cfg
有錯誤找上面的文章解決

service snmpd restart

五分鐘執行一次
crontab -e
*/5 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg.cfg


 

本篇發表於 Linux系統。將永久鏈結加入書籤。