手抄筆記,尚待整理。針對FreeBSD主機上的網路卡啟動SNMP協定,再以MRTG統計這塊網卡的進出流量。
wget ftp://ftp.lab.mlc.edu.tw/UNIX/snmp/ucd-snmp-4.2.tar.gz
tar zxvf ucd-snmp-4.2.tar.gz -C /usr/local/src
cd /usr/local/src/ucd-snmp-4.2
第一個步驟時,安裝程式會要求您回答一些問題。
./configure
************** Configuration Section **************
You are about to be prompted by a series of questions. Answer
them carefully, as they determine how the snmp agent and related
applications are to function.
After the configure script finishes, you can browse the newly
created config.h file for further - less important - parameters to
modify. Be careful if you re-run configure though since config.h will
be over written.
-Press return to continue-
Describes who should be contacted about the host the agent is
running on. This information is available in the MIB-II tree. This
Can Also Be Over-Ridden Using The "syscontact" Syntax In The Agent'S
Configuration Files.
System Contact Information (root@lab.mlc.edu.tw):
setting System Contact Information to... root@lab.mlc.edu.tw
checking System Location...
*** System Location:
Describes the location of the system. This information is
available in the MIB-II tree. This Can also be over-ridden using the
"syslocation" syntax in the agent's configuration files.
System Location (Unknown): dns.lab.mlc.edu.tw ( 填入主機名稱 )
setting System Location to... dns.lab.mlc.edu.tw
checking Location to write logfile...
*** Logfile location:
Enter the default location for the snmpd agent to dump
information & errors to. If not defined (enter the keyword "none"
at the prompt below) the agent will use stdout and stderr instead.
(Note: This value can be over-ridden using command line options.)
Location to write logfile (/var/log/snmpd.log):
setting Location to write logfile to... /var/log/snmpd.log
checking Location to write persistent information...
*** snmpd persistent storage location:
Enter a directory for the snmp library to store persistent
data in the form of a configuration file.
Location to write persistent information (/var/ucd-snmp):
make
umask 022
make install
啟動snmp
/usr/local/sbin/snmpd -p 161,tcp:161,9161@localhost
加入 /etc/rc.local
每日凌晨校時。
wget ftp://ftp.lab.mlc.edu.tw/UNIX/mrtg/mrtg-2.9.10.tar.gz
tar zxvf mrtg-2.9.10.tar.gz -C /usr/local/src
cd /usr/local/src/mrtg-2.9.10
./configure \
--prefix=/usr/local/mrtg-2 \
--with-gd=/usr/local/include/gd \
--with-gd-lib=/usr/local/lib \
--with-gd-inc=/usr/local/include/gd \
--with-png=/usr/local/include \
--with-zlib=/usr/local/include
make
make install
新增使用者:
aduser mrtg
su - mrtg
mkdir public_html
cp /usr/local/src/mrtg-2.9.10/images/* /home/mrtg/public_html
利用 cfgmaker 製造出 mrtg.cfg ,這個 mrtg.cfg 建議與 mrtg 程式放在一起。
/usr/local/mrtg-2/bin/cfgmaker \
--global 'WorkDir: /home/mrtg/public_html' \
--global 'Options[_]: bits,growright' \
--global 'Language: big5' \
--output /usr/local/mrtg-2/bin/mrtg.cfg \
public@www.lab.mlc.edu.tw
/usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/bin/mrtg.cfg
用完整的檔案路徑連續執行三次,第一次一定會有錯誤訊息,繼續做,直至沒有錯誤訊息為止。
chown mrtg /home/public_html/*
修改或確認 /usr/local/mrtg-2/bin/mrtg.cfg 檔案設定內容:
WorkDir: /usr/local/apache/htdocs/mrtg
Options[_]: bits,growright
Language: big5
製做首頁:
/usr/local/mrtg-2/bin/indexmaker \
--output='/home/mrtg/public_html/index.html' \
--title='www.lab.MLC.edu.tw 主機的流量統計' \
--rrdviewer='.' \
/usr/local/mrtg-2/bin/mrtg.cfg
加入 /etc/crontab ,每五分鐘統計乙次流量。
*/5 * * * * root /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/bin/mrtg.cfg > /dev/null 2>&1
參考文件:http://net-snmp.sourceforge.net/tutorial/mrtg/
http://net-snmp.sourceforge.net/tutorial-5/