利用snmp和mrtg監控linux伺服器的網路流量
宋體;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: 宋體;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin">環境
snmpd、mrtg
被監控客戶端:station3.example.com:192.168.32.33
mso-fareast-font-family:宋體;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">伺服器端安裝和配置(station2)
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">
[root@station2 ~]# yum install net-snmp.i386
[root@station2 ~]#yuminstall net-snmp-devel.i386
[root@station2 ~]#yum install net-snmp-utils.i386
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">2. mso-fareast-font-family:宋體;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">配置
[root@station2 ~]# snmptranslate -On SNMPv2-MIB::system
[root@station2 ~]#cp /etc/snmp/snmpd /etc/snmp/snmpd.orig
#
[root@station2 ~]# snmpconf
The following installed configuration files were found:
2: /etc/snmp/snmpd.conf
Would you like me to read them in? Their content will be merged with the
output files created by this session.
Valid answer examples: "all", "none","3","1,2,5"
Read in which (default = all): 2
I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)
1: snmpd.conf
3: snmp.conf
Other options: quit
Select File: 1
#選擇配置文件名,默認路徑在當前目錄下
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
1: Trap Destinations
2: System Information Setup
3: Monitor Various Aspects of the Running Host
4: Extending the Agent
5: Access Control Setup
Other options: finished
Select section: 5
#選擇配置類型,5是訪問配置,要通過snmp監控系統信息,得先配置訪問控制
Section: Access Control Setup
Description:
snmp agent.
Select from:
1: a SNMPv3 read-write user
2: a SNMPv3 read-only user
3: a SNMPv1/SNMPv2c read-only access community name
Other options: finished, list
Select section: 3
#範圍許可權,選擇3通過community(訪問密碼)進行只讀訪問
Configuring: rocommunity
Description:
arguments: community [default|hostname|network/bits] [oid]
The community name to add read-only access for: example
#example是community即訪問密碼
The hostname or network address to accept this community name from [RETURN for all]: 0.0.0.0/0 #可訪問得網段
Finished Output: rocommunity example 0.0.0.0/0
Section: Access Control Setup
Description:
This section defines who is allowed to talk to your running
snmp agent.
Select from:
1: a SNMPv3 read-write user
2: a SNMPv3 read-only user
3: a SNMPv1/SNMPv2c read-only access community name
4: a SNMPv1/SNMPv2c read-write access community name
Other options: finished, list
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:
1: Trap Destinations
3: Monitor Various Aspects of the Running Host
4: Extending the Agent
5: Access Control Setup
6: Agent Operating Mode
Other options: finished
Select section: finished
I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)
1: snmpd.conf
2: snmptrapd.conf
3: snmp.conf
Other options: quit
Select File: quit
Error: An snmpd.conf file already exists in this directory.
'overwrite', 'skip', 'rename' or 'append'? : overwrite #覆蓋原配置文件
The following files were created:
snmpd.conf
want them used by everyone on the system. In the future, if you add
the -i option to the command line I'll copy them there automatically for you.
Or, if you want them for your personal use only, copy them to
/root/.snmp . In the future, if you add the -p option to the
command line I'll copy them there automatically for you.
cp:是否覆蓋“/etc/snmp/snmpd.conf”? y #將新配置文件覆蓋原配置文件
[root@station2 ~]# cat /etc/snmp/snmpd.conf |grep example
# example: pass .1.3.6.1.4.1.2021.255 /path/to/local/passtest
rocommunity example 0.0.0.0/0
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">3. Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋體;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">啟動snmpd服務
[root@station2 ~]# service snmpd start
啟動 snmpd:
[root@station2 ~]# chkconfig snmpd on
[root@station2 /]# snmpwalk -v1 -c example station2.example.com
#根據community為example查看
SNMPv2-MIB::sysDescr.0 = STRING: Linux station2.example.com 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:43 EDT 2010 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (7433) 0:01:14.33
SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: station2.example.com
SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (1) 0:00:00.01
SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for managing TCP implementations
......
End of MIB
mso-fareast-font-family:宋體;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">客戶埠配置(station3)
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">1. Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋體;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">安裝
[root@station2 ~]# yum install net-snmp.i386
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">2. Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋體;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">將stationa2的配置文件複製並覆蓋station3的原配置文件
[root@station3 ~]# scp 192.168.32.32:/etc/snmp/snmpd.conf /etc/snmp/snmpd.conf
root@192.168.32.32's password:
snmpd.conf
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">3. Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋體;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">啟動snmpd代理服務
[root@station3 snmp]# service snmpd start
啟動 snmpd:
[root@station3 snmp]# chkconfig snmpd on
宋體;mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family: 宋體;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin">伺服器端mrtg的安裝和配置(station2)
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">1. mso-fareast-font-family:宋體;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Calibri;mso-hansi-theme-font:minor-latin">安裝
[root@station2 ~]# yum install mrtg
#注在此默認httpd已經安裝並配置,安裝mrtg後會默認生成一個httpd配置文件/etc/httpd/conf.d/mrtg
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">
[root@station2 /]# cfgmaker --ifref=name --global "workdir:/var/www/mrtg" example@station2.example.com example@station3.example.com >/etc/mrtg/mrtg.cfg
#根據snmpd的community定義mrtg的報表配置文件
[root@station2 /]# cat /etc/cron.d/mrtg
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
#該文件是安裝mrtg時默認生成,表示每5分鐘做一次數據讀取
[root@station2 /]# LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
#根據/etc/cron.d/mrtg中內容讀取數據生成報表,要執行3次此命令才會不提示錯誤並成功.
[root@station2 /]# indexmaker /etc/mrtg/mrtg.cfg>/var/www/mrtg/index.html
#根據mrtg配置文件生成mrtg的默認首頁
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin">3. Calibri;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋體;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin">配置httpd並測試
[root@station2 conf.d]# vi /etc/httpd/conf.d/mrtg.conf
Alias /mrtg /var/www/mrtg
<Location /mrtg>
Order deny,allow
Deny from all
</Location>
[root@station2 conf.d]#servie httpd restart
通過IE訪問http://192.168.32.32/mrtg
本文出自 「netsword.blogchina.com」 博客,請務必保留此出處http://netsword.blog.51cto.com/13993/557957
[火星人 ] rh442-1 利用snmp和mrtg監控linux伺服器的網路流量已經有668次圍觀