安装SNMP软件

检查是否安装SNMP

[root@localhost ~]# snmpwalk --help
-bash: snmpwalk: command not found
[root@localhost ~]#

1.安装SNMP服务

yum install -y net-snmp*  #安装snmp服务

2.修改配置文件

# 查看配置文件
grep "^[a-Z]" /etc/snmp/snmpd.conf

image.png

# 修改配置文件
vim /etc/snmp/snmpd.conf
#       sec.name  source          community
com2sec notConfigUser  default       public

# public 可以修改,修改成自己的团体号


#       group          context sec.model sec.level prefix read   write  notif
access  notConfigGroup ""      any       noauth    exact  systemview none none

# 修改访问权限  systemview ===> all

access  notConfigGroup ""      any       noauth    exact  all none none
# 添加这一行
view    all           included   .1


# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
view    all           included   .1
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1

image.png

3.启动snmp

[root@localhost ~]# systemctl start snmpd
[root@localhost ~]# systemctl status snmpd

image.png

4.检测snmp端口状态

[root@localhost ~]# netstat -lnpu |grep snmpd
udp        0      0 0.0.0.0:161             0.0.0.0:*                           16269/snmpd         
[root@localhost ~]#

5.使用OID探测 snmpwalk

snmpwalk -v2c -c public@123 192.168.168.133 .1.3.6.1.4.1.2021.10.1.3

image.png

6.Linux主机的对象标识符

.1.3.6.1表示权限,以此开头的都能访问,比如.1.3.6.1.4.1.2021.10.1.3和.1.3.6.1.2.1.2

Linux主机的对象标识符

# CPU负载
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

# CPU信息
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

# 内存使用
Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0

故障排查:权限不够,访问失败

[root@localhost ~]# snmpget -v2c -c public@123 192.168.168.133 .1.3.6.1.4.1.2021.10.1.3.1
UCD-SNMP-MIB::laLoad.1 = No Such Object available on this agent at this OID
[root@localhost ~]# 
[root@localhost ~]# snmpwalk -v2c -c public@123 192.168.168.133 .1.3.6.1.4.1.2021.10.1.3
UCD-SNMP-MIB::laLoad = No more variables left in this MIB View (It is past the end of the MIB tree)

image.png

SNMP服务测试

snmpwalk -v 2c -c public@123 192.168.168.133

image.png

如果权限没有开启,获取的参数就会比较少;通过SNMP监控主机是不够准确的。