今天做了snmp的测试,现把安装配置方法分享如下:
首先准备安装的源码包:net-snmp-5.4.2.1.tar.gz
1.解压源码包
tar xvf net-snmp****
2.创建安装目录
mkdir /usr/local/net-snmp
3.安装
./configure --prefix=/usr/local/net-snmp
make
make install
4.安装成功cp配置文件到/usr/local/net-snmp/share/snmp/目录下
cp ./EXZAPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf
5.修改配置文件
# sec.name source community
#com2sec local localhost COMMUNITY
#com2sec mynetwork NETWORK/24 COMMUNITY
com2sec local localhost COMMUNITY
com2sec mynetwork 192.168.1.186 public //为允许的源地址
com2sec mynetwork 192.168.1.254 public
com2sec mynetwork 192.168.1.0/24 public //为允许的源网络
6.编辑/etc/rc.local添加为自启动
添加下面一行:
/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf &
7.设置环境变量,编辑/etc/profile
在export前添加下面一行
PATH=/usr/local/net-snmp/bin:/usr/local/net-snmp/sbin:$PATH
8.测试命令
snmpget -v 1 -c "public" 192.168.1.236 .1.3.6.1.4.1.2021.10.1.3.1
注:要在同样安装过net-snmp的机器上测或在安装过第3方软件(solarwinds等)的机器测试
该命令的最后一个字段为cpu的OID
#########################################################################
问题补充:
上次装好netsnmp并观察了一段时间后发现获取内存,cpu信息等等都很正常,唯独磁盘信息与预期有点出入,我们预期获取磁盘所有分区的使用情况结果只获取了/根分区的使用情况:
经查证是配置文件snmpd.conf里的配置有关:
# disk checks
#
# The agent can check the amount of available disk space, and make
# sure it is above a set limit.
# disk PATH [MIN=DEFDISKMINIMUMSPACE]
#
# PATH: mount path to the disk in question.
# MIN: Disks with space below this value will have the Mib's errorFlag set.
# Default value = DEFDISKMINIMUMSPACE.
# Check the / partition and make sure it contains at least 10 megs.
disk / 10000
disk /home 10000
# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.9
# enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskPath.1 = "/" Hex: 2F
# enterprises.ucdavis.diskTable.dskEntry.diskDevice.1 = "/dev/dsk/c201d6s0"
# enterprises.ucdavis.diskTable.dskEntry.diskMinimum.1 = 10000
# enterprises.ucdavis.diskTable.dskEntry.diskTotal.1 = 837130
# enterprises.ucdavis.diskTable.dskEntry.diskAvail.1 = 316325
# enterprises.ucdavis.diskTable.dskEntry.diskUsed.1 = 437092
# enterprises.ucdavis.diskTable.dskEntry.diskPercent.1 = 58
# enterprises.ucdavis.diskTable.dskEntry.diskErrorFlag.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskErrorMsg.1 = ""
因为配置文件默认只有disk / 10000这一行;按此格式添加你期望获取的磁盘或分区;
it‘s ok!!问题解决;
验证cmd:
snmpwalk -v 1 -c "public" 218.108.231.183 .1.3.6.1.4.1.2021.9.1
snmpwalk -v 1 -c "public" 218.108.231.183 .1.3.6.1.4.1.2021.9.1.7