preface
snmp 不多說
環境介紹
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
更多OID請參考他人的博客:http://www.haiyun.me/archives/linux-snmp-oid.html