net-snmp(5.6.1) 编译 安装 运行调试全记录
2013-09-13 10:24
453 查看
net-snmp 5.6.1 代码下载编译安装的过程相对比较简单,而且有官方的Guide,在此不再重复叙述,ubuntu 12.04 32bits/64bits 按照下面这个Guide 都测试成功了。
http://www.net-snmp.org/wiki/index.php/Net-Snmp_on_Ubuntu
安装 $ sudo make install > install.log 可以查看一下snmpd mibs 文件的安装位置,不然还真不好找,这里一般都是安装到 /usr/local/ 下面了。
要想执行 snmpwalk/snmpget 等命令,首先需要在本机上启动 snmpd 服务,snmpd 这个服务启动的难点和关键就在于 snmpd.conf 配置文件,这里直接贴上我的可以运行的配置文件:
运行的时候注意需要sudo 权限,因为snmpd 需要用到161 UDP port, 需要root权限,否则会有如下提示:
$ snmpd -f -Lo -C -c ~/snmpd.conf
Turning on AgentX master support.
Error opening specified endpoint "udp:161"
Server Exiting with code 1
加上sudo 之后,正常启动,
$ sudo snmpd -f -Lo -C -c ~/snmpd.conf
Turning on AgentX master support.
NET-SNMP version 5.6.1
使用sockstat 查看端口状态:
或是
$ netstat -an | grep 161
udp 0 0 0.0.0.0:161 0.0.0.0:*
这时,在另外一个Terminal 或是另外一台主机上执行:
$ snmpwalk -v 1 -c public -Cp localhost
就会输出正确的结果了。
参考文章:
http://blog.sina.com.cn/s/blog_8ea085de01012tdo.html
http://web.archiveorange.com/archive/v/WnPpSNSsl7HujziSGyP4
$ snmptranslate -On -Tp .1.3.6.1.2.1.1
+--system(1)
|
+-- -R-- String sysDescr(1)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- ObjID sysObjectID(2)
+-- -R-- TimeTicks sysUpTime(3)
| |
| +--sysUpTimeInstance(0)
|
+-- -RW- String sysContact(4)
| Textual Convention: DisplayString
| Size: 0..255
+-- -RW- String sysName(5)
| Textual Convention: DisplayString
| Size: 0..255
+-- -RW- String sysLocation(6)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- INTEGER sysServices(7)
| Range: 0..127
+-- -R-- TimeTicks sysORLastChange(8)
| Textual Convention: TimeStamp
|
+--sysORTable(9)
|
+--sysOREntry(1)
| Index: sysORIndex
|
+-- ---- INTEGER sysORIndex(1)
| Range: 1..2147483647
+-- -R-- ObjID sysORID(2)
+-- -R-- String sysORDescr(3)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- TimeTicks sysORUpTime(4)
Textual Convention: TimeStamp
$ snmptranslate -IR -Tp |less
这个命令看整个 MIBs 树更直观
SNMP agent :
http://blog.chinaunix.net/uid-790245-id-2037497.html
SNMP trap:
http://blog.chinaunix.net/uid-677314-id-83386.html
http://blog.chinaunix.net/uid-790245-id-2037495.html
SNMP v3
http://blog.chinaunix.net/uid-451-id-3337094.html
http://www.net-snmp.org/wiki/index.php/Net-Snmp_on_Ubuntu
安装 $ sudo make install > install.log 可以查看一下snmpd mibs 文件的安装位置,不然还真不好找,这里一般都是安装到 /usr/local/ 下面了。
要想执行 snmpwalk/snmpget 等命令,首先需要在本机上启动 snmpd 服务,snmpd 这个服务启动的难点和关键就在于 snmpd.conf 配置文件,这里直接贴上我的可以运行的配置文件:
############################################################################### # # EXAMPLE.conf: # An example configuration file for configuring the Net-SNMP agent ('snmpd') # See the 'snmpd.conf(5)' man page for details # # Some entries are deliberately commented out, and will need to be explicitly activated # ############################################################################### # # AGENT BEHAVIOUR # # 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 # qiang added listen for connections on all interfaces, only for IPv4 agentAddress udp:161 ############################################################################### # # SNMPv3 AUTHENTICATION # # Note that these particular settings don't actually belong here. # They should be copied to the file /var/lib/snmp/snmpd.conf # and the passwords changed, before being uncommented in that file *only*. # Then restart the agent # createUser authOnlyUser MD5 "remember to change this password" # createUser authPrivUser SHA "remember to change this one too" DES # createUser internalUser MD5 "this is only ever used internally, but still change the password" # If you also change the usernames (which might be sensible), # then remember to update the other occurances in this example config file to match. ############################################################################### # # ACCESS CONTROL # # system + hrSystem groups only #view systemonly included .1.3.6.1.2.1.1 #view systemonly included .1.3.6.1.2.1.25.1 # added by qiang view all included .1 # Full access from the local host #rocommunity public localhost # Default access to basic system info # rocommunity public default -V systemonly rocommunity public default -V all # Full access from an example network # Adjust this network address to match your local # settings, change the community string, # and check the 'agentAddress' setting above #rocommunity secret 10.0.0.0/16 # Full read-only access for SNMPv3 rouser authOnlyUser # Full write access for encrypted requests # Remember to activate the 'createUser' lines above #rwuser authPrivUser priv # It's no longer typically necessary to use the full 'com2sec/group/access' configuration # r[ou]user and r[ow]community, together with suitable views, should cover most requirements ############################################################################### # # SYSTEM INFORMATION # # Note that setting these values here, results in the corresponding MIB objects being 'read-only' # See snmpd.conf(5) for more details sysLocation Sitting on the Dock of the Bay sysContact Me <me@example.org> # Application + End-to-End layers sysServices 72 # # Process Monitoring # # At least one 'mountd' process proc mountd # No more than 4 'ntalkd' processes - 0 is OK proc ntalkd 4 # At least one 'sendmail' process, but no more than 10 proc sendmail 10 1 # Walk the UCD-SNMP-MIB::prTable to see the resulting output # Note that this table will be empty if there are no "proc" entries in the snmpd.conf file # # Disk Monitoring # # 10MBs required on root disk, 5% free on /var, 10% free on all other disks disk / 10000 disk /var 5% includeAllDisks 10% # Walk the UCD-SNMP-MIB::dskTable to see the resulting output # Note that this table will be empty if there are no "disk" entries in the snmpd.conf file # # System Load # # Unacceptable 1-, 5-, and 15-minute load averages load 12 10 5 # Walk the UCD-SNMP-MIB::laTable to see the resulting output # Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file ############################################################################### # # ACTIVE MONITORING # # send SNMPv1 traps trapsink localhost public # send SNMPv2c traps #trap2sink localhost public # send SNMPv2c INFORMs #informsink localhost public # Note that you typically only want *one* of these three lines # Uncommenting two (or all three) will result in multiple copies of each notification. # # Event MIB - automatically generate alerts # # Remember to activate the 'createUser' lines above iquerySecName internalUser rouser internalUser # generate traps on UCD error conditions defaultMonitors yes # generate traps on linkUp/Down linkUpDownNotifications yes ############################################################################### # # EXTENDING THE AGENT # # # Arbitrary extension commands # extend test1 /bin/echo Hello, world! extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35 #extend-sh test3 /bin/sh /tmp/shtest # Note that this last entry requires the script '/tmp/shtest' to be created first, # containing the same three shell commands, before the line is uncommented # Walk the NET-SNMP-EXTEND-MIB tables (nsExtendConfigTable, nsExtendOutput1Table # and nsExtendOutput2Table) to see the resulting output # Note that the "extend" directive supercedes the previous "exec" and "sh" directives # However, walking the UCD-SNMP-MIB::extTable should still returns the same output, # as well as the fuller results in the above tables. # # "Pass-through" MIB extension command # #pass .1.3.6.1.4.1.8072.2.255 /bin/sh PREFIX/local/passtest #pass .1.3.6.1.4.1.8072.2.255 /usr/bin/perl PREFIX/local/passtest.pl # Note that this requires one of the two 'passtest' scripts to be installed first, # before the appropriate line is uncommented. # These scripts can be found in the 'local' directory of the source distribution, # and are not installed automatically. # Walk the NET-SNMP-PASS-MIB::netSnmpPassExamples subtree to see the resulting output # # AgentX Sub-agents # # Run as an AgentX master agent master agentx # Listen for network connections (from localhost) # rather than the default named socket /var/agentx/master #agentXSocket tcp:localhost:705
运行的时候注意需要sudo 权限,因为snmpd 需要用到161 UDP port, 需要root权限,否则会有如下提示:
$ snmpd -f -Lo -C -c ~/snmpd.conf
Turning on AgentX master support.
Error opening specified endpoint "udp:161"
Server Exiting with code 1
加上sudo 之后,正常启动,
$ sudo snmpd -f -Lo -C -c ~/snmpd.conf
Turning on AgentX master support.
NET-SNMP version 5.6.1
使用sockstat 查看端口状态:
$ sudo sockstat USER PROCESS PID PROTO SOURCE ADDRESS FOREIGN ADDRESS STATE root rpcbind 749 udp4 *:111 *:* CLOSED root rpcbind 749 udp4 *:903 *:* CLOSED root rpcbind 749 tcp4 *:111 *:* LISTEN root sshd 856 tcp4 *:22 *:* LISTEN root rpc.statd 875 udp4 127.0.0.1:627 *:* CLOSED statd rpc.statd 875 udp4 *:35824 *:* CLOSED statd rpc.statd 875 tcp4 *:49187 *:* LISTEN root xinetd 1043 udp4 *:69 *:* CLOSED root cupsd 1053 tcp4 127.0.0.1:631 *:* LISTEN avahi avahi-daemon 1143 udp4 *:5353 *:* CLOSED avahi avahi-daemon 1143 udp4 *:48954 *:* CLOSED root rpc.mountd 1191 udp4 *:55068 *:* CLOSED root rpc.mountd 1191 tcp4 *:60662 *:* LISTEN root rpc.mountd 1191 udp4 *:56931 *:* CLOSED root rpc.mountd 1191 tcp4 *:54234 *:* LISTEN root rpc.mountd 1191 udp4 *:50313 *:* CLOSED root rpc.mountd 1191 tcp4 *:36634 *:* LISTEN root dhclient 1259 udp4 *:68 *:* CLOSED root dnsmasq 1313 udp4 127.0.0.1:53 *:* CLOSED root dnsmasq 1313 tcp4 127.0.0.1:53 *:* LISTEN miredo miredo 1649 udp4 *:36362 *:* CLOSED qiang dropbox 2128 udp4 *:17500 *:* CLOSED qiang dropbox 2128 tcp4 *:17500 *:* LISTEN qiang ubuntu-geoip-pr 2279 tcp4 128.224.162.198:37615 91.189.89.144:80 CLOSE_WAIT qiang chromium-browse 2451 tcp4 128.224.162.198:56295 74.125.31.125:5222 ESTABLISHED qiang chromium-browse 2451 tcp4 128.224.162.198:37246 173.194.34.67:443 ESTABLISHED qiang chromium-browse 2451 tcp4 128.224.162.198:44171 117.79.157.251:80 ESTABLISHED qiang chromium-browse 2451 tcp4 128.224.162.198:44165 117.79.157.251:80 ESTABLISHED qiang thunderbird 3982 tcp4 128.224.162.198:43863 147.11.189.50:993 ESTABLISHED qiang thunderbird 3982 tcp4 128.224.162.198:43875 147.11.189.50:993 ESTABLISHED qiang thunderbird 3982 tcp4 128.224.162.198:43876 147.11.189.50:993 ESTABLISHED qiang thunderbird 3982 tcp4 128.224.162.198:43877 147.11.189.50:993 ESTABLISHED root snmpd 10529 udp4 *:161 *:* CLOSED root snmpd 10529 udp4 *:46939 *:* CLOSED
或是
$ netstat -an | grep 161
udp 0 0 0.0.0.0:161 0.0.0.0:*
这时,在另外一个Terminal 或是另外一台主机上执行:
$ snmpwalk -v 1 -c public -Cp localhost
就会输出正确的结果了。
参考文章:
http://blog.sina.com.cn/s/blog_8ea085de01012tdo.html
http://web.archiveorange.com/archive/v/WnPpSNSsl7HujziSGyP4
$ snmptranslate -On -Tp .1.3.6.1.2.1.1
+--system(1)
|
+-- -R-- String sysDescr(1)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- ObjID sysObjectID(2)
+-- -R-- TimeTicks sysUpTime(3)
| |
| +--sysUpTimeInstance(0)
|
+-- -RW- String sysContact(4)
| Textual Convention: DisplayString
| Size: 0..255
+-- -RW- String sysName(5)
| Textual Convention: DisplayString
| Size: 0..255
+-- -RW- String sysLocation(6)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- INTEGER sysServices(7)
| Range: 0..127
+-- -R-- TimeTicks sysORLastChange(8)
| Textual Convention: TimeStamp
|
+--sysORTable(9)
|
+--sysOREntry(1)
| Index: sysORIndex
|
+-- ---- INTEGER sysORIndex(1)
| Range: 1..2147483647
+-- -R-- ObjID sysORID(2)
+-- -R-- String sysORDescr(3)
| Textual Convention: DisplayString
| Size: 0..255
+-- -R-- TimeTicks sysORUpTime(4)
Textual Convention: TimeStamp
$ snmptranslate -IR -Tp |less
这个命令看整个 MIBs 树更直观
SNMP agent :
http://blog.chinaunix.net/uid-790245-id-2037497.html
SNMP trap:
http://blog.chinaunix.net/uid-677314-id-83386.html
http://blog.chinaunix.net/uid-790245-id-2037495.html
SNMP v3
http://blog.chinaunix.net/uid-451-id-3337094.html
相关文章推荐
- net-snmp-5.4.4 编译,安装,运行。
- net-snmp编译安装报错问题处理
- 开源路由软件Quagga 源代码 编译/安装/运行/调试(Eclipse环境)
- Linux下用Eclipse编译、安装、运行、调试PostgreSQL源码
- 在ubuntu14.04 64位 virtualbox虚拟机上编译net-snmp5.7.2.1记录
- net-snmp 安装与trap调试
- windows 系统 安装 net-snmp 并成功运行命令的步骤
- 记录一下Linux下安装Qt5.6到命令行编译方式顺利运行第一个helloworld全过程
- VS2005下编译、安装Net-snmp 5.4.1.2手记(原创)
- net-snmp-5.7.1 编译安装 (ubuntu)
- 在linux4.7上安装net-snmp编译遇到的问题
- 记录编译安装Tengine+PHP-FPM运行 WordPress 的过程.
- linux下net-snmp的源码编译安装与配置
- net-snmp-5.7.3配置编译安装
- [转]VS2005下编译、安装Net-snmp 5.4.1.2
- net-snmp 编译安装
- net-snmp-5.7.3配置编译安装
- Net-snmp总结(二)-net-snmp配置编译安装
- net-snmp 编译安装
- Linux下NET-SNMP安装配置记录