阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

在RedHat Linux系统中安装和配置snmp服务

156次阅读
没有评论

共计 6652 个字符,预计需要花费 17 分钟才能阅读完成。

在 RedHat Linux 系统中安装和配置 snmp 服务

检查系统是否安装 snmp 服务

# rpm -qa|grep snmp
net-snmp-5.3.2.2-17.el5
net-snmp-perl-5.3.2.2-17.el5
net-snmp-devel-5.3.2.2-17.el5
net-snmp-libs-5.3.2.2-17.el5
net-snmp-utils-5.3.2.2-17.el5
net-snmp-libs-5.3.2.2-17.el5
net-snmp-devel-5.3.2.2-17.el5

SNMP 服务安装后会有以上安装包

安装 SNMP 服务

1. 配置好本地 yum 服务,使用 yum 安装

yum install -y net-snmp*

2. 配置 SNMP 服务开机启动

#chkconfig snmpd on
#chkconfig –list | grep snmpd 查看开机启动设置是否成功
snmpd 0: 关闭 1: 关闭 2: 启用 3: 启用 4: 启用 5: 启用 6: 关闭

Zabbix 之 SNMP 配置 http://www.linuxidc.com/Linux/2013-09/90263.htm

SNMP 实现网络动态分析 http://www.linuxidc.com/Linux/2013-04/83514.htm

SNMP 实现网络状态监控 http://www.linuxidc.com/Linux/2013-04/83187.htm

CentOS 6.3 下搭建 SNMP 测试环境 http://www.linuxidc.com/Linux/2013-02/79233.htm

Linux (Ubuntu/CentOS) SNMP 配置 http://www.linuxidc.com/Linux/2012-12/76837.htm

开启并配置 Citrix Xenserver 的 SNMP 服务 http://www.linuxidc.com/Linux/2013-01/78487.htm

验证 SNMP 服务

1. 使用 snmpwalk 获取主机名

# snmpwalk -v 2c -c public localhost sysName.0
SNMPv2-MIB::sysName.0 = STRING: wh69
snmpwalk 用法
snmpwalk -v 1|2c|3(代表 SNMP 版本) -c <community string> IP 地址 OID(对象标示符)

2. 使用 snmptranslate 命令,检查 snmp 工具是否可以使用

# snmptranslate -To | head
.1.3
.1.3.6
.1.3.6.1
.1.3.6.1.1
.1.3.6.1.2
.1.3.6.1.2.1
.1.3.6.1.2.1.1
.1.3.6.1.2.1.1.1
.1.3.6.1.2.1.1.2
.1.3.6.1.2.1.1.3
查出了部分 oid,则表示 snmp 工具可以正常使用

配置 SNMP 服务

1. 配置 SNMP 连接字符串 community string

#vi /etc/snmp/snmpd.conf
修改下面字段

#      sec.name  source          community
com2sec notConfigUser  default    public

修改 public 为自己定义的 community string

2. 修改查看设备节点权限

在配置文件 /etc/snmp/snmpd.conf 中找到如下位置

####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#      name          incl/excl    subtree        mask(optional)
view    systemview    included  .1.3.6.1.2.1.1
view    systemview    included  .1.3.6.1.2.1.25.1.1

view:定义了可以查看哪些节点设备的信息。
snmp 默认配置只能查看.1.3.6.1.2.1.1 和.1.3.6.1.2.1.25.1.1 节点下的设备信息,
而主机 CPU 和内存等设备都不在这些节点下,所以无法获取这些数据。
因此,可以修改这个配置,如下:

####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#      name          incl/excl    subtree        mask(optional)
view    systemview    included  .1
view    systemview    included  .1.3.6.1.2.1.1
view    systemview    included  .1.3.6.1.2.1.25.1.1

在此处添加了一行:
view systemview included .1
表示可以查看.1 节点下的所有设备信息。

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-07/104074p2.htm

3. 修改 Process checks 的配置

在配置文件 /etc/snmp/snmpd.conf 中找到如下位置

###############################################################################
# Process checks.
#
# The following are examples of how to use the agent to check for
# processes running on the host. The syntax looks something like:
#
# proc NAME [MAX=0] [MIN=0]
#
# NAME: the name of the process to check for. It must match
# exactly (ie, http will not find httpd processes).
# MAX: the maximum number allowed to be running. Defaults to 0.
# MIN: the minimum number to be running. Defaults to 0.

#
# Examples (commented out by default):
#

# Make sure mountd is running
#proc mountd

# Make sure there are no more than 4 ntalkds running, but 0 is ok too.
#proc ntalkd 4

# Make sure at least one sendmail, but less than or equal to 10 are running.
#proc sendmail 10 1

去除
#proc mountd
#proc ntalkd 4
#proc sendmail 10 1

这三行前面的 #号,取消注释

4. 修改 Executables/scripts 配置

在配置文件 /etc/snmp/snmpd.conf 中找到如下位置

###############################################################################
# Executables/scripts
#

#
# You can also have programs run by the agent that return a single
# line of output and an exit code. Here are two examples.
#
# exec NAME PROGRAM [ARGS …]
#
# NAME: A generic name.
# PROGRAM: The program to run. Include the path!
# ARGS: optional arguments to be passed to the program

# a simple hello world

#exec echotest /bin/echo hello world

# Run a shell script containing:


#exec echotest /bin/echo hello world
前面的 #去掉,取消注释

5. 修改 disk checks 配置

在配置文件 /etc/snmp/snmpd.conf 中找到如下位置

###############################################################################
# disk checks
#

# The agent can check the amount of available disk space, and make
# sure it is above a set limit.

# disk PATH [MIN=100000]
#
# PATH: mount path to the disk in question.
# MIN: Disks with space below this value will have the Mib’s errorFlag set.
# Default value = 100000.

# Check the / partition and make sure it contains at least 10 megs.

#disk / 10000


#disk / 10000
前的 #号去掉,取消注释

 

6. 修改 load average checks 配置

在配置文件 /etc/snmp/snmpd.conf 中找到如下位置

###############################################################################
# load average checks
#

# load [1MAX=12.0] [5MAX=12.0] [15MAX=12.0]
#
# 1MAX: If the 1 minute load average is above this limit at query
# time, the errorFlag will be set.
# 5MAX: Similar, but for 5 min average.
# 15MAX: Similar, but for 15 min average.

# Check for loads:
#load 12 14 14


#load 12 14 14
前的 #去掉,取消注释

7. 保存修改,重启 snmp 服务

#service snmpd restart

8. 验证修改配置后的 snmp 服务

# snmpwalk -v 2c -c xindixindi localhost 1.3.6.1.4.1.2021.11.11.0
UCD-SNMP-MIB::ssCpuIdle.0 = INTEGER: 99
如上,通过本机 localhost 获取到 CPU 的空闲率为 99%

完成配置

现在可以在 solarwinds 和 Cacti 等监控系统中,通过 SNMP 服务监控该 Linux 服务器了。

更多 RedHat 相关信息见RedHat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10

在 RedHat Linux 系统中安装和配置 snmp 服务

检查系统是否安装 snmp 服务

# rpm -qa|grep snmp
net-snmp-5.3.2.2-17.el5
net-snmp-perl-5.3.2.2-17.el5
net-snmp-devel-5.3.2.2-17.el5
net-snmp-libs-5.3.2.2-17.el5
net-snmp-utils-5.3.2.2-17.el5
net-snmp-libs-5.3.2.2-17.el5
net-snmp-devel-5.3.2.2-17.el5

SNMP 服务安装后会有以上安装包

安装 SNMP 服务

1. 配置好本地 yum 服务,使用 yum 安装

yum install -y net-snmp*

2. 配置 SNMP 服务开机启动

#chkconfig snmpd on
#chkconfig –list | grep snmpd 查看开机启动设置是否成功
snmpd 0: 关闭 1: 关闭 2: 启用 3: 启用 4: 启用 5: 启用 6: 关闭

Zabbix 之 SNMP 配置 http://www.linuxidc.com/Linux/2013-09/90263.htm

SNMP 实现网络动态分析 http://www.linuxidc.com/Linux/2013-04/83514.htm

SNMP 实现网络状态监控 http://www.linuxidc.com/Linux/2013-04/83187.htm

CentOS 6.3 下搭建 SNMP 测试环境 http://www.linuxidc.com/Linux/2013-02/79233.htm

Linux (Ubuntu/CentOS) SNMP 配置 http://www.linuxidc.com/Linux/2012-12/76837.htm

开启并配置 Citrix Xenserver 的 SNMP 服务 http://www.linuxidc.com/Linux/2013-01/78487.htm

验证 SNMP 服务

1. 使用 snmpwalk 获取主机名

# snmpwalk -v 2c -c public localhost sysName.0
SNMPv2-MIB::sysName.0 = STRING: wh69
snmpwalk 用法
snmpwalk -v 1|2c|3(代表 SNMP 版本) -c <community string> IP 地址 OID(对象标示符)

2. 使用 snmptranslate 命令,检查 snmp 工具是否可以使用

# snmptranslate -To | head
.1.3
.1.3.6
.1.3.6.1
.1.3.6.1.1
.1.3.6.1.2
.1.3.6.1.2.1
.1.3.6.1.2.1.1
.1.3.6.1.2.1.1.1
.1.3.6.1.2.1.1.2
.1.3.6.1.2.1.1.3
查出了部分 oid,则表示 snmp 工具可以正常使用

配置 SNMP 服务

1. 配置 SNMP 连接字符串 community string

#vi /etc/snmp/snmpd.conf
修改下面字段

#      sec.name  source          community
com2sec notConfigUser  default    public

修改 public 为自己定义的 community string

2. 修改查看设备节点权限

在配置文件 /etc/snmp/snmpd.conf 中找到如下位置

####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#      name          incl/excl    subtree        mask(optional)
view    systemview    included  .1.3.6.1.2.1.1
view    systemview    included  .1.3.6.1.2.1.25.1.1

view:定义了可以查看哪些节点设备的信息。
snmp 默认配置只能查看.1.3.6.1.2.1.1 和.1.3.6.1.2.1.25.1.1 节点下的设备信息,
而主机 CPU 和内存等设备都不在这些节点下,所以无法获取这些数据。
因此,可以修改这个配置,如下:

####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#      name          incl/excl    subtree        mask(optional)
view    systemview    included  .1
view    systemview    included  .1.3.6.1.2.1.1
view    systemview    included  .1.3.6.1.2.1.25.1.1

在此处添加了一行:
view systemview included .1
表示可以查看.1 节点下的所有设备信息。

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-07/104074p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计6652字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中