---
title: "net-snmp 在ubuntu下开发"
author: "steeven"
date: "2010-09-02T18:40:47Z"
tags: []
categories: ["编程语言"]
slug: "net-snmp-ubuntu"
draft: false
lastmod: "2010-09-02T18:40:47Z"
id: 753868
url: "https://steeven.iteye.com/blog/753868"
---

环境：Net-snmp 5.5 ubuntu9.04 amd64
./configure –with-mib-modules=”xxx yyy zzz”
Xxx yyy zzz是agent/mibgroups/目录下的对应模块名，可参考testhandler/examples
如果模块没有被加载，请检查agent/mibgroup/mib_moudle_*.h

make
sudo make install

sudo vi /etc/ld.so.conf.d/snmp.conf
/usr/local/lib
sudo ldconfig

cd /usr/lib
sudo ln –s libperl.so libper.so.5.10

snmpconf 记得加入读写community: public
sduo cp snmpd.conf /usr/local/share/snmp


调试：
snmpd -Vf -Loe
snmpd -Vf -Loe -I!aaa,bbb -Dmib_init 不加载aaa,bbb
snmpd -Vf -Loe -Iaaa,bbb -Dmib_init,aaa,bbb 仅加载aaa,bbb

注意：
1.	Snmpd.conf加入： agentaddress 11161, 不用缺省的161, 普通用户即可调试, 在eclipse cdt中也能玩
2.	Snmpget –v2c –cpublic localhost:11161 .1.2.3.4.5
3.	oid oid = {1,2,3,4,5} 是错误的，OID_LENGTH会返回1, 因为sizeof(oid)/sizeof(oid)…变量不要用类型名,虽然gcc不报错
4.	x64下面Netsnmp_register_int_instance()的snmpset报错Reason: wrongLength (The set value has an illegal length from what the agent expects)
参见：http://web.archiveorange.com/archive/v/LLXmLVvuYbdKrGsGDbB8
用最新的netsnmp 5.6 rc1 编译还是有wrong length问题。 Register ulong gauge等不会出错
5.	常用的调试开关：
a)	mib_init: mib模块加载记录
b)	helper:watcher: request注册处理