幫助中心
這里有最新的使用文檔和教程
CentOS如何安裝SNMP服務?Centos7安裝snmp,snmp安裝,centos8安裝snmp
操作系統:CentOS 7.x 8.x
一、防火墻配置
CentOS 7.x 8.x默認使用的是firewall作為防火墻,這里改為iptables防火墻。
1、關閉firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
systemctl mask firewalld
systemctl stop firewalld
yum remove firewalld
2、安裝iptables防火墻
yum install iptables-services #安裝
vi /etc/sysconfig/iptables #編輯防火墻配置文件,開放ftp服務端口
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 161 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
systemctl restart iptables.service #最后重啟防火墻使配置生效
systemctl enable iptables.service #設置防火墻開機啟動
/usr/libexec/iptables/iptables.init restart #重啟防火墻
二、關閉SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
三、安裝SNMP服務
1、安裝SNMP
yum install net-snmp net-snmp-utils net-snmp-perl
#net-snmp是服務端,net-snmp-utils是客戶端工具
#查看snmp版本號
snmpd -v
#查看安裝的軟件包
rpm -qa |grep net-snmp*
#查看net-snmp相關的軟件包
yum list all |grep net-snmp*
systemctl start snmpd.service #啟動SNMP服務
systemctl enable snmpd.service #設置開機啟動SNMP服務
#查看udp端口161是否運行
netstat -apn|grep 161
lsof -i:161
#需要安裝工具包yum install net-tools lsof
2、配置SNMP
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.confbak #備份配置文件
vi /etc/snmp/snmpd.conf #添加修改
com2sec notConfigUser default public #需要驗證的團體名
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view all included .1
access notConfigGroup "" any noauth exact all none none
:wq! #保存退出
systemctl restart snmpd.service #重啟SNMP服務
3、測試SNMP服務
#查看進程
ps aux|grep snmpd
#查看端口
netstat -nlp|grep 161
#查看日志
cat /var/log/messages
#檢查SNMP服務器是否運行
netstat -nlup |grep ":161"
#測試是否能夠獲取到數據
snmpwalk -v 2c -c public localhost if
snmpwalk -v 2c -c public 127.0.0.1 if
snmpget -v2c -c public 192.168.21.129 .1.3.6.1.4.1.2021.10.1.3.1
snmpwalk -v2c -c public 192.168.21.129 .1.3.6.1.4.1.2021.10.1.3
snmpwalk -v 2c -c public 192.168.21.129 if #本機的ip地址192.168.21.129
snmpget -v 2c -c public 192.168.21.128 sysDescr.0 #遠程連接測試,192.168.21.128其他安裝SNMP服務的主機ip地址
至此,CentOS系統下安裝SNMP服務完成。