技术交流QQ群:①185473046   ②190706903   ③203744115   网站地图
登录

下次自动登录
现在的位置: 首页CentOS>正文
CentOS系统下安装SNMP服务
2022年07月20日 CentOS 暂无评论 ⁄ 被围观 5,483次+

操作系统: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服务完成。

     
» 转载请注明来源:系统运维 » CentOS系统下安装SNMP服务

  系统运维技术交流QQ群:①185473046 系统运维技术交流□Ⅰ ②190706903 系统运维技术交流™Ⅱ ③203744115 系统运维技术交流™Ⅲ

给我留言

您必须 [ 登录 ] 才能发表留言!



Copyright© 2011-2024 系统运维 All rights reserved
版权声明:本站所有文章均为作者原创内容,如需转载,请注明出处及原文链接
陕ICP备11001040号-3