技術(shù)文檔
CentOS如何安裝SNMP服務(wù)?Centos7安裝snmp,snmp安裝,centos8安裝snmp
操作系統(tǒng):CentOS 7.x 8.x
一、防火墻配置
CentOS 7.x 8.x默認(rèn)使用的是firewall作為防火墻,這里改為iptables防火墻。
1、關(guān)閉firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機(jī)啟動(dòng)
systemctl mask firewalld
systemctl stop firewalld
yum remove firewalld
2、安裝iptables防火墻
yum install iptables-services #安裝
vi /etc/sysconfig/iptables #編輯防火墻配置文件,開放ftp服務(wù)端口
# 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 #設(shè)置防火墻開機(jī)啟動(dòng)
/usr/libexec/iptables/iptables.init restart #重啟防火墻
二、關(guān)閉SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
三、安裝SNMP服務(wù)
1、安裝SNMP
yum install net-snmp net-snmp-utils net-snmp-perl
#net-snmp是服務(wù)端,net-snmp-utils是客戶端工具
#查看snmp版本號(hào)
snmpd -v
#查看安裝的軟件包
rpm -qa |grep net-snmp*
#查看net-snmp相關(guān)的軟件包
yum list all |grep net-snmp*
systemctl start snmpd.service #啟動(dòng)SNMP服務(wù)
systemctl enable snmpd.service #設(shè)置開機(jī)啟動(dòng)SNMP服務(wù)
#查看udp端口161是否運(yùn)行
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 #需要驗(yàn)證的團(tuán)體名
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服務(wù)
3、測(cè)試SNMP服務(wù)
#查看進(jìn)程
ps aux|grep snmpd
#查看端口
netstat -nlp|grep 161
#查看日志
cat /var/log/messages
#檢查SNMP服務(wù)器是否運(yùn)行
netstat -nlup |grep ":161"
#測(cè)試是否能夠獲取到數(shù)據(jù)
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 #本機(jī)的ip地址192.168.21.129
snmpget -v 2c -c public 192.168.21.128 sysDescr.0 #遠(yuǎn)程連接測(cè)試,192.168.21.128其他安裝SNMP服務(wù)的主機(jī)ip地址
至此,CentOS系統(tǒng)下安裝SNMP服務(wù)完成。