CentOS7.9 安装开启snmp监控
SNMP安装包
net-snmp-libs-5.7.2-49.el7.x86_64.rpm
net-snmp-agent-libs-5.7.2-49.el7.x86_64.rpm
net-snmp-5.7.2-49.el7.x86_64.rpm
net-snmp-utils-5.7.2-49.el7.x86_64.rpm
网络配置
SNMP使用161端口,在防火墙添加端口开放规则,并重新加载规则
firewall-cmd --zone=public --add-port=161/udp --permanent
firewall-cmd --reload
安装
进入rpm包文件目录,按顺序执行。各rpm要统一版本。
rpm -ivh net-snmp-libs-5.7.2-49.el7.x86_64.rpm
rpm -ivh net-snmp-agent-libs-5.7.2-49.el7.x86_64.rpm
rpm -ivh net-snmp-5.7.2-49.el7.x86_64.rpm
rpm -ivh net-snmp-utils-5.7.2-49.el7.x86_64.rpm
配置
编辑SNMP配置文件 /etc/snmp/snmpd.conf
按需求配置可获取内容,如需要获取所有的可找到view配置地方加入
view systemview included .1
SNMP启停
SNMP安装完成后会自动注册为服务,可以通过命令控制启动、停止、重启和查看状态。
systemctl start snmpd
systemctl stop snmpd
systemctl restart snmpd
systemctl status snmpd
其它问题
net-snmp包安装失败
报错信息:
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by net-snmp-1:5.7.2-49.el7_9.2.x86_64
libnetsnmpagent.so.31()(64bit) is needed by net-snmp-1:5.7.2-49.el7_9.2.x86_64
libnetsnmpmibs.so.31()(64bit) is needed by net-snmp-1:5.7.2-49.el7_9.2.x86_64
libnetsnmptrapd.so.31()(64bit) is needed by net-snmp-1:5.7.2-49.el7_9.2.x86_64
net-snmp-agent-libs = 1:5.7.2-49.el7_9.2 is needed by net-snmp-1:5.7.2-49.el7_9.2.x86_64
net-snmp-libs = 1:5.7.2-49.el7_9.2 is needed by net-snmp-1:5.7.2-49.el7_9.2.x86_64
网上查找是由于卸载了服务器自带的mariadb,导致没有驱动。所以需要安装mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm。
上传rpm包,执行安装命令:
rpm -ivh mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
再重新执行4个SNMP包安装命令。
net-snmp-libs包版本不一致问题
CentOS会默认安装net-snmp-libs-1:5.7.2-49.el7.x86_64,如果需要想安装net-snmp-libs-5.7.2-49.el7_9.2.x86_64.rpm,会无法覆盖。需要先下载原有的net-snmp-libs版本,可以从安装新的rpm包报错中找到原有的版本名称。
#卸载原有版本
rpm -e --allmatches --nodeps net-snmp-libs-1:5.7.2-49.el7.x86_64
#重新安装新的版本
rpm -ivh net-snmp-libs-5.7.2-49.el7_9.2.x86_64.rpm