编译安装net-snmp
1.官网下载最新net-snmp的tar包:http://www.net-snmp.org/download.html
如果官网打不开,可从这里下载net-snmp-5.7.3.tar.gz(内附gcc的rpm包)
2.检查主机是否已安装编译工具gcc,直接输入gcc命令回车查看,如果未安装会提示“不能识别的命令”,使用yum安装即可:
yum install gcc
如果使用yum安装失败,可从这里下载net-snmp-5.7.3.tar.gz(内附gcc的rpm包)
3.解压,编译:
tar -xvf net-snmp-5.7.3.tar.gz
mv net-snmp-5.7.3 net-snmp
cd net-snmp
./configure --prefix=/usr/local/net-snmp --with-default-snmp-version="2" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp" --with-mib-modules="ucd-snmp/diskio"
4.执行:make && make install
make && make install
5.修改net-snmp目录权限:
chmod -R 755 /usr/local/net-snmp
6.进入/usr/local/net-snmp/bin目录,执行./snmpconf命令,生成snmpd.conf文件
cd /usr/local/net-snmp/bin
./snmpconf
7.选择配置文件名称: snmpd.conf --> 输入对应数字
此处有插图,可参考
8.选择配置选项section:Access Control Setup --> 输入对应数字
9.选择a SNMPv1/SNMPv2c read-only access community name --> 输入对应数字
10.输入选择处理的权限[The community name to add read-only access for]:public
11.提示输入OID及网卡地址等信息,直接回车(两次)
12.连着两次输入finished
13.输入quit
14.将生成的snmpd.conf文件移动到/usr/local/net-snmp/share/snmp目录下:
cp /usr/local/net-snmp/bin/snmpd.conf /usr/local/net-snmp/share/snmp/
15.进入到/usr/local/net-snmp/sbin目录下,启动snmpd:
cd /usr/local/net-snmp/sbin
./snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf
16.检查snmpd进程是否存在:
ps -ef|grep snmpd
17.进入/usr/local/net-snmp/bin目录,执行./snmpwalk -v 2c -c public localhost system指令,如果返回一长串主机信息,则说明安装成功:
cd /usr/local/net-snmp/bin
./snmpwalk -v 2c -c public localhost system
若报错:Timeout: No response from localhost,可将share/snmp/snmpd.conf文件的内容设替换为一下内容,然后kill掉刚才启动的进程,重新启动,再次查看试试。
com2sec notConfigUser default public
com2sec local localhost mymrtg
com2sec mynetwork 192.168.1.0/24 mymrtg
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
group MyRWGroup v1 local
group MyROGroup v1 mynetwork
group MyRWGroup v2c local
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.2
view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80
access notConfigGroup "" any noauth exact systemview none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
参考文件: