注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

红烧鱼

linux & windows management

 
 
 

日志

 
 
关于我
mac

专注IT基础架构设计与运维。 欢迎给我留言,或邮件沟通zjwsk@163.com

网易考拉推荐

Linux snmp.conf配置  

2008-08-05 20:27:59|  分类: Linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

有些朋友不能取到CPU和系统负载的数据,原因是snmp设置默认没有允许取这些数据。下面是我对linux和FreeBSD下的net-snmp的一些简单的配置。

一、Linux(RedHat)的配置

打开默认的/etc/snmp/snmp.conf文件,更改如下配置:


       1、查找以下字段:
# sec.name source community
com2sec notConfigUser default public

将"comunity"字段改为你要设置的密码.比如"public".
将“default”改为你想哪台机器可以看到你的snmp信息,如10.10.10.10。

 

2、查找以下字段:
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact systemview none none
改成:
access notConfigGroup "" any noauth exact mib2 none none

 

3、查找以下字段:
## -or just the mib2 tree-
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

将该行前面的"#"去掉. 保存关闭.


4、运行/etc/init.d/snmpd start命令运行snmpd. 最后运行netstat -ln查看161端口是否打开了.


二、FreeBSD
如果使用port安装net-snmp,默认的配置文件应该是在/usr/local/share/snmp/snmpd.conf(没有默认的文件)。
可以建立一个简单的配置文件,如:
syslocation YourDefineName
syscontact YourEmailAddress
sysservices 77
rocommunity public (请更改)
load 12 12 12


然后运行snmpd,netstat 看是否打开了161端口。

--------------------------------------------------------------------------------------------------------------------

On Redhat 7.1 or above, NetSnmp has become the default snmp...

But on other linux version. It is still a good guide.

In this tutorial we will

  • download and install net-snmp,
  • write and install a simple MIB,
  • write a subagent to handle to mib.

Download and install net-snmp package

This package was previously known as ucd-snmp

  1. Download the source from here, or if this link is broken try the net-snmp homepage, to your local directory which we will now refer to as $. For this tutorial we will use net-snmp-5.0-pre2.
  2. change directory to $, untar and unzip the package using:
    $gunzip net-snmp-5.0.pre2.tar.gz  $tar xvf net-snmp-5.0.pre2.tar
    This will dump all the souce into $/net-snmp-5.0.pre2
  3. To compile to package:
    $./configure --with-mib-modules="agentx"  $make  $make install  $cd local; make install; cd ..  $cd mibs; make install; cd ..
    The "configure" command configure the agent to use the AgentX protocol. This is a IETF defined protocol that allows a master/client relationship between agents and subagents. The last two command should not theoretically have to be to used ... but without them .. things do not seem to work. Now, we have to setup the snmpd configuration file, before "snmpd" can work properly.
  4. Copy the example configuration file:
    $ cp $/EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
  5. Now we need to modify /usr/local/share/snmp/snmpd.conf as follows:
    1. Replace COMMUNITY with "democommunity". This is your community string.
    2. Comment out 2nd "com2sec" line. We do not allow network access for now.
    3. On a new line at the end of the file add "master agentx". This tells the agents to behave as the master in the master/client AgentX protocol.
  6. We now need to fix some library links (this is truely awful ... is this a Redhat or a net-snmp "problem"/"feature" ?)(Note: On some machines this is not required e.g RedHat 7.1 ... use your judgement :-))
    $ln -s /usr/local/lib/libnetsnmp-0.5.0.0.2.so /lib/libnetsnmp-0.5.0.0.2.so  $ln -s /usr/local/lib/libnetsnmpagent-0.5.0.0.2.so /lib/libnetsnmpagent-0.5.0.0.2.so  $ln -s /usr/local/lib/libnetsnmphelpers-0.5.0.0.2.so /lib/libnetsnmphelpers-0.5.0.0.2.so  $ln -s /usr/local/lib/libnetsnmpmibs-0.5.0.0.2.so /lib/libnetsnmpmibs-0.5.0.0.2.so
  7. To check "snmpd" do:
    become root
    $ ps awwux | grep snmp
    if you see an earlier snmpd deamon ... kill it
    $ cd $/net-snmp-5.0.pre2/agent  $ ./snmpd -f -L
    This should start the "snmpd" agent but keep it attached to the current terminal (which is useful since we want to kill it very soon).
  8. On another window:
    $snmpget -v 1 -c democommunity localhost system.sysUpTime.0
    If snmpd was installed correctly, this gives up the timeticks the snmpd agent has been up (NOT how long your system was up !!). If you get an error .. retrace your steps from the beginning.

    You can now use "^C" to kill the snmpd deamon in the first window.

Writing and installing a MIB

In this part of the the tutorial we will write and install a simple MIB.
  1. First write the mib that you want to implement. For our tutorial we write a simple MIB called JM-TEST-1-MIB.txt:
    JM-TEST-1-MIB DEFINITIONS ::= BEGIN    IMPORTS          MODULE-IDENTITY,           OBJECT-TYPE,           INTEGER                   FROM SNMPv2-SMI;    jmtest MODULE-IDENTITY      LAST-UPDATED "200203210000Z"      ORGANIZATION "Temple U"      CONTACT-INFO          "None yet."      DESCRIPTION          "AgentX testing MIB"      REVISION     "200203210000Z"      DESCRIPTION          "None yet."      ::= { experimental 72}    firstKey OBJECT-TYPE      SYNTAX      INTEGER (0..100)      MAX-ACCESS  read-write      STATUS      current      DESCRIPTION          "Value initialized to 0 and on each            access:           - Return current val.           - increment"        ::= { jmtest 1 }    END

    This mib represents a resource "firstKey" whose initial value is 0 and whose value gets incremented every time it is queried.

    Note that this MIB will be registered under the 1.3.6.1.3.72 heirarchy. This choice is arbitrary and should only be used for experiments. For real world implementation you should get a "real" OID. Existing OIDs and guidelines on getting new ones can be fo und here. This page is maintained by the current (March 2002) IETF/IESG chair, so he probably knows what he is talking about.

    Copy this mib into the mibs directory

    $cp JM-TEST-1-MIB.txt /usr/local/share/snmp/mibs
  2. Now we need to get the SNMP tools to recognise this MIB. So:
    $echo "mibs +JM-TEST-1-MIB" >> /usr/local/share/snmp/snmp.conf
    This adds a directive to the snmp tools configuration asking them load our mib.
  3. To verify if our MIB is loaded use the verstile snmptranslate command:
    $snmptranslate -IR -Tp experimental
    This command will draw the present tree under the experimental branch. Omit the last parameter and you will get the whole tree (as currenly understood by the snmp tools). The output should look like:
    Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  +--experimental(3)     |     +--jmtest(72)        +-- -RW- INTEGER   firstKey(1)                 Range: 0..100
    If you get the above output, then we are in good shape so far. The real work, howeve still remains. We must now write the subagent that will handle queries on under this OID branch.

Writing and installing a subagent

In this section we will write and install a subagent that serves the mib we installed in the previous section.

The subagent is an independent program that communicates with the master agent (snmpd in our case) using the AgentX protocol.

The basic steps of writing the code is as follows:

  1. Write the agent code in a C file, say example.c. This can be done using the mib2c tool.
  2. Create the subagent executable using the net-snmp-config tool.
mib2c is (supposed to) take in the MIB definition as spit out the subagent code. However (as far as I could figure out) the mib2c program distributed with this version of net-snmp does not generate code for simple scalar mibs, instead dealing with mibs th at have tables.

So for an example of subagent code for simple scalar objects look at $/agent/mibgroups/example/example.c.

We have adapted example.c for our mib (JM-TEST-1-MIB.txt) as example2.c.

    Download example2.c and example1.h
    $mkdir $/agent/mibgroup/examples/subagent  $cp example2.c $/agent/mibgroup/examples/subagent  $cp example.h $/agent/mibgroup/examples/subagent
    Now we create the executable using the net-snmp-config tools as:
    $net-snmp-config --compile-subagent example2 example2.c -I../../../mibgroup
    This produces a executable called example2. example2 is our subagent. Voila !

    To test whether things are still working.

    In first window:

    $cd $/agent  $./snmpd -f -L -D
    This will start the snmpd deamon in the debugging mode (you will see LOTS of messages).

    In the second window:

    $cd agent/mibgroup/examples/subagent  $./example2
    Finally in the third window, the command and output should look like (output is shown in bold):
    [root@x mibs]# snmpget -v 1 -c democommunity localhost firstKey.0  Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  JM-TEST-1-MIB::firstKey.0 = 1  [root@x mibs]# snmpget -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0  Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  JM-TEST-1-MIB::firstKey.0 = 2  [root@x mibs]# snmpset -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0 i 10  Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  JM-TEST-1-MIB::firstKey.0 = 10  [root@x mibs]# snmpget -v 1 -c democommunity localhost firstKey.0  Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  JM-TEST-1-MIB::firstKey.0 = 10  [root@x mibs]# snmpget -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0  Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  JM-TEST-1-MIB::firstKey.0 = 11  [root@x mibs]# snmpget -v 1 -c democommunity localhost 1.3.6.1.3.72.1.0  Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  JM-TEST-1-MIB::firstKey.0 = 12  [root@x mibs]# snmpwalk -v 1 -c democommunity localhost firstKey          Unlinked OID in JM-TEST-1-MIB: jmtest ::= { experimental 72 }  JM-TEST-1-MIB::firstKey.0 = 13
    In the output above notice that every snmpget query returns an increasing value of "firstKey" and snmpset lets us set "firstKey" to an arbitrary value (within a defined range).

    We now have a working subagent. In real applications the subagent could be embedded in the application to be managed.

    --by Jaiwant Mulik, March 2002.

  评论这张
 
阅读(3648)| 评论(2)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017