1.基础环境配置
为了防止防火墙及selinux等的影响,需关闭防火墙及selinux等,具体参考:
2.安装snmp
yum源配置,具体参考:
snmp安装命令:
yum install -y net-snmp net-snmp-utils
[root@logstash ~]# yum install -y net-snmp net-snmp-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package matching 1:net-snmp-5.7.2-49.el7.x86_64 already installed. Checking for update.
Package matching 1:net-snmp-utils-5.7.2-49.el7.x86_64 already installed. Checking for update.
Nothing to do
[root@logstash ~]# snmpd -v
NET-SNMP version: 5.7.2
Web: http://www.net-snmp.org/
Email: net-snmp-coders@lists.sourceforge.net
[root@logstash ~]#
3.配置snmp
1.进入/etc/snmp目录
2.编辑snmpd.conf文件,并保存
#启用社区信息,允许所有主机访问该节点
com2sec notConfigUser default public
#把用户加入安全组
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
#可以查看.1下所有OID的对象信息
view all included .1 80
#允许可读权限
access notConfigGroup "" any noauth exact all none none
3.启动snmpd
命令:
systemctl start snmpd
[root@logstash snmp]# systemctl start snmpd
[root@logstash snmp]# systemctl status snmpd
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
Loaded: loaded (/usr/lib/systemd/system/snmpd.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2024-08-23 15:07:17 CST; 8min ago
Main PID: 12381 (snmpd)
Tasks: 1
Memory: 4.3M
CGroup: /system.slice/snmpd.service
└─12381 /usr/sbin/snmpd -LS0-6d -f
Aug 23 15:07:16 logstash systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
Aug 23 15:07:17 logstash systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..
[root@logstash snmp]# netstat -antulp |grep 161
udp 0 0 0.0.0.0:161 0.0.0.0:* 12381/snmpd
[root@logstash snmp]# netstat -antulp |grep snmpd
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 12381/snmpd
udp 0 0 0.0.0.0:30043 0.0.0.0:* 12381/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 12381/snmpd
[root@logstash snmp]#
4.测试
snmpwalk测试
命令:
snmpwalk -v 2c -c public 192.168.10.131
SNMPv2-MIB::sysDescr.0 = STRING: Linux logstash 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (126396) 0:21:03.96
SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
SNMPv2-MIB::sysName.0 = STRING: logstash
......
......
IPV6-MIB::ipv6DefaultHopLimit.0 = INTEGER: 64
IPV6-MIB::ipv6Interfaces.0 = Gauge32: 6
IPV6-MIB::ipv6IfDescr.1 = STRING: lo
IPV6-MIB::ipv6IfDescr.2 = STRING: ens32
IPV6-MIB::ipv6IfDescr.3 = STRING: docker_gwbridge
IPV6-MIB::ipv6IfDescr.5 = STRING: ens32.100
IPV6-MIB::ipv6IfDescr.6 = STRING: ens32.200
IPV6-MIB::ipv6IfDescr.11 = STRING: veth61eb9ac
IPV6-MIB::ipv6IfLowerLayer.1 = OID: SNMPv2-SMI::zeroDotZero
IPV6-MIB::ipv6IfLowerLayer.2 = OID: SNMPv2-SMI::zeroDotZero
IPV6-MIB::ipv6IfLowerLayer.3 = OID: SNMPv2-SMI::zeroDotZero
IPV6-MIB::ipv6IfLowerLa