CentOS 上安装snmp
Centos 上安装snmp
一、yum 安装
1.安装snmp
yum clean all
yum makecache
yum -y install net-snmp net-snmp-utils
2.配置snmp
vi /etc/snmp/snmpd.conf
# 根据需求指定ip段可以访问,也可以不指定ip
rocommunity public 10.28.0.0/16
3.启动并启用 SNMP 服务
systemctl start snmpd
systemctl enable snmpd
4.防火墙设置
如果服务器启用了防火墙,需要开放 UDP 161 端口以便外部设备能够查询 SNMP 数据
对于 firewalld:
firewall-cmd --zone=public --add-port=161/udp --permanent
firewall-cmd --reload
对于 iptables:
iptables -A INPUT -p udp --dport 161 -j ACCEPT
service iptables save
5.测试snmp 配置
snmpwalk -v1 -c public 10.28.168.232 1.3.6.1.4.1.34672
二、源码包安装
下载net-snmp-5.9.4.zip并安装
cd /soft
chmod 755 net-snmp-5.9.4.zip
unzip net-snmp-5.9.4.zipcd net-snmp-5.9.4#预编译./configure --prefix=/usr/local/net-snmp --with-default-snmp-version="2" --with-logfile=/usr/local/net-snmp/log/snmplog.log --with-persistent-directory=/var/net-snmp# 编译安装
make && make install# 编辑配置文件
cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.confcd /usr/local/net-snmp/sbin
#查看版本
./snmpd -vNET-SNMP version: 5.9.4.pre2
Web: http://www.net-snmp.org/
Email: net-snmp-coders@lists.sourceforge.net#编辑配置文件
cd /usr/local/net-snmp/share/snmp/vi snmpd.confcom2sec notConfigUser default public
# groupName securityModel securityNamegroup notConfigGroup v1 notConfigUsergroup notConfigGroup v2c notConfigUser
# name incl/excl subtree mask(optional)view all included .1# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact all none none