网上虽然有很多这方面的资料,不过都很乱,感觉说的也不太好,所以我总结了一下,我在windows 7上可以成功配置好
1. 下载安装
net-snmp安装程序:net-snmp-5.4.2.1-1.win32.exe
Perl安装程序:ActivePerl-5.10.0.1004-MSWin32-x86-287188.msi
安装过程默认就好
2.配置snmpd.conf文件
在路径(软件安装路径)\etc\snmp\下,添加文件snmpd.conf,注意去掉.txt后缀,另外此路径下已经有了一个snmp.conf文件,不要混乱两者,
然后一下两种方式二选一:
a.简单配置:在snmpd.conf加入:rocommunity public
b.详细配置:在snmpd.conf加入:
####
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):
# sec.name source community
com2sec local localhost root
com2sec local 192.168.1.110 root
com2sec mynetwork 192.168.1.0/24 public
####
# Second, map the security names into group names:
# sec.model sec.name
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
####
# Third, create a view for us to let the groups have rights to:
# incl/excl subtree mask
view all included .1 80
####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:
# context sec.model sec.level match read write notif
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
####
(注意每次改动snmpd.conf文件后都要重启snmp服务)
3.注册snmp agent服务,在(软件安装路径)\路径下,打开文件registeragent.bat就行,自动注册服务
4.然后重新启动snmp
>net stop "net-snmp agent"
>net start "net-snmp agent"
5.OK,可以使用了,测试一下吧:
>snmpwalk -v 2c -c root localhost if
>snmpwalk -v 2c -c root 192.168.1.110 if
>snmpget -v 2c -c root localhost 1.3.6.1.2.1.1.1.0
Linux下安装和配置net-snmp
0.开始之前先转到root权限,不然下面的工作会有问题
#sudo -i
1.#tar –zxvf net-snmp-5.4.2.1.tar.gz //解压
2.#cd net-snmp-5.4.2.1 //进入源文件目录
3./configure --prefix=/usr/local/snmp //配置 在过程中需要选择
配置中会出这样的提示:
default version of-snmp-version: 2
Systemcontact information(配置该设备的联系人): VRS
System location (该设备的位置): China
下面两个默认就行
Location to write logfile (日志文件位置): /var/log/snmpd.log
Location to Write persistent(数据存储目录): /var/net-snmp
4.#make && make install //编译并且安装
1).找不到libbeecrypt.la
下载beecrypt-4.1.2.tar.gz
http://sourceforge.net/projects/beecrypt
./configure -prefix=/usr
默认是安装在/usr/local的偶们要装在/usr下
$make
$make install
2)./usr/bin/ld: cannot find -lelf
$ln -s libelf.so.1 /usr/lib/libelf.so
3).echo /usr/local/lib >/etc/ld.so.conf.d/libnetsnmp.conf
$/sbin/ldconfig -v
$make install
5.#cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf //拷贝EXAMPLE.conf 注意大写
6.#gedit /usr/local/share/snmp/snmpd.conf //编辑snmpd.conf
把这句
com2sec local localhost COMMUNITY
com2sec mynetwork NETWORK/24 COMMUNITY
改为
com2sec local localhost public
com2sec local 192.168.1.110 public
com2sec mynetwork 192.168.1.0/24 public
7.#gedit /etc/rc.local \\设置netsnmp自启动 即在末尾加上
/usr/local/snmp/sbin/snmpd -c /etc/snmp/snmpd.conf &
8.#gedit /etc/profile \\设置环境变量即在export命令前加上PATH=/usr/local/bin:/usr/local/sbin:$PATH
9.# /usr/local/sbin/snmpd –d \\启动snmpd这个服务,查看服务是否启动
#netstat –an | grep 161
如果已经启动了服务,又修改了snmpd.conf 那么必须停止snmpd 这个服务重新
snmpd -d才能生效
停止的办法 1).ps –ef |grep snmpd //查看snmpd的进程id
2).Kill -9 snmpd的进程号 //结束snmpd的进程
注意:每次重新登录Linux都要重新启动服务,要用root权限去启动,否则失败,这个折磨了我n久
10.测试命令:
#snmpwalk -v 2c -c public localhost if
#snmpwalk -v 2c -c public 192.168.1.110 if
#snmpget -v 2c -c public localhost 1.3.6.1.2.1.1.1.0