环境介绍
1.使用CentOs7的系统,内核版本为3.10.0-123.el7.x86_64
2.ip地址为192.168.56.12
安装snmp
1.yum安装:
[root@linux-node2 ~]#yum -y install net-snmp-utils net-snmp-agent-libs
2.配置SNMP
[root@linux-node2 ~]# grep "^[a-Z]" /etc/snmp/snmpd.conf
com2sec admin default admin # 定义用户
group admin v2c admin # 定义用户组
view admin included .1 80 # 定义用户组对那些OID有权限访问
access admin "" any noauth exact admin admin none # 授权一个只读组去访问这个systemview的视图
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
dontLogTCPWrappersConnects yes
3.启动snmp
[root@linux-node2 ~]# systemctl start snmpd
4.检测snmp端口状态
[root@linux-node2 ~]# netstat -lnpu |grep snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 3633/snmpd
5.使用OID探测
5.1. 针对一个OID探测: snmpget
[root@linux-node2 ~]# snmpget -v2c -c admin 192.168.56.12 .1.3.6.1.4.1.2021.10.1.3.1
UCD-SNMP-MIB::laLoad.1 = STRING: 0.03 # 获取到1分钟的系统负载
5.2 针对一组OID探测:snmpwalk
[root@linux-node2 ~]# snmpwalk -v2c -c admin 192.168.56.12 .1.3.6.1.4.1.2021.10.1.3 # 获取到1,5,15分钟的系统负载 UCD-SNMP-MIB::laLoad.1 = STRING: 0.00 UCD-SNMP-MIB::laLoad.2 = STRING: 0.01 UCD-SNMP-MIB::laLoad.3 = STRING: 0.05
参考:https://www.cnblogs.com/liaojiafa/p/6550962.html