Linux下snmptrapd配置记录

 

说明:配置文件所有指令都要顶格写,左侧不要留空格。
      允许使用空格,但不能使用Tab键。
      路径分隔符不能使用反斜杠,必须使用“/”。

一.snmptrapd.conf的配置

此文件用来指定管理进程如何处理接收到的snmp notification。

 

1. 在net-snmp安装目录下新建snmptrapd.conf文件,假设本系统使用以下路径:/ABC/soft/net-snmp/share/snmp/snmptrapd.conf

 

2. 在snmptrapd.conf中加入以下指令:
authCommunity log,execute,net public
这条指令指明以“public”为“community”请求的snmp “notification”允许的操作。
各变量意义如下:
loglog the details of the notification - either in a  specified file, to standard output (or stderr), or via syslog(or similar).

executepass the details of the trap to a specified handler program, including embedded perl.

net: forward the trap to another notification receiver.

 

3. 若想对接收到的信息进行处理,可以使用traphandle,示例如下:

traphandle SNMPv2-MIB::coldStart    /usr/nba/bin/traps cold

traphandle SNMPv2-MIB::warmStart    /usr/nba/bin/traps warm

traphandle IF-MIB::linkDown         /usr/nba/bin/traps down

traphandle IF-MIB::linkUp           /usr/nba/bin/traps up

第一个参数为从snmptrapd接收的OID,第二个参数为调用的程序。此系统未做traphandle处理。

 

4. 启动snmptrapd

使用以下指令启动snmptrapd:

snmptrapd -f -Lo

该指令将接收到的信息通过标准输出设备打印出来,各参数意义如下:

-fDo not fork() from the calling shell.

-L[efos]: Specify where logging output should be directed (standard error or output, to a file or via syslog).

更详细配置请参考net-snmp用户手册。

 

二.snmpd.conf的配置

snmpd服务器可以接收手动的snmp查询信息,如snmpget,snmpwalk等工具。也可以自动监视系统状态,并在系统出现错误或者系统不稳定情况下向管理进程发送信息。下文主要介绍使用snmp自动监视系统状态,并自动向snmptrapd发送信息(notification)。

1. 在net-snmp安装目录下新建snmpd.conf文件:

/ABC/soft/net-snmp/share/snmp/snmpd.conf

 

2. 在snmptrapd.conf中加入以下指令:

(说明:此处只是示例,具体参数需要视情况调整,也可以加入更多的监视项)

trap2sink  localhost public
authtrapenable 1
rwuser administrator
iquerySecName administrator
linkUpDownNotifications yes
defaultMonitors yes

#Process checks
proc sendmail 10 1

#disk checks

disk / 100000

#Check for loads

load 5 5 5

#CPU usage
notificationEvent userCPU ssCpuRawUser
notificationEvent sysCPU ssCpuRawSystem
monitor -r 60 -e userCPU "User CPU use percentage" ssCpuRawUser > 100
monitor -r 60 -e sysCPU "System CPU use percentage" ssCpuRawSystem > 100

#Memory usage
notificationEvent memTotalTrap memTotalReal memTotalSwap 
notificationEvent memAvailTrap memAvailReal memAvailSwap memTotalFree
monitor -r 10 -e memTotalTrap "Total memory" memTotalReal < 1000000000000
monitor -r 10 -e memAvailTrap "Available memory" memTotalFree < 1000000000000


指令简介:
·#号后为内容注释。
·trap2sink:指明信息发送的snmptrapd地址,2c版本。

·authtrapenable:决定是否发送身份验证失败信息。

·rwuser:建立读写权限用户。

·iquerySecName:指定内部查询用户名。

·linkUpDownNotifications:在建立断开链接的时候发送通知。

·defaultMonitors:打开默认监视项。其中包括进程,磁盘等的监视,必须打开此项,否则进程,磁盘等的监视信息不会被发出。

·proc:监视指定进程,当进程数不在指定的范围时将特定标志位置1,但是不会发出trap信号,需要打开defaultMonitors,由其发送trap信号。

·disk:监视磁盘剩余空间,当剩余空间小于指定值时将特定标志位置1,同proc。
·load:系统负载,指定1,5,15分钟的系统负载,超过阈值后处理方法同proc。

·notificationEvent:自定义通知事件。

·monitor:监视指定事件。

具体配置请参考用户手册。

 

3. 启动snmpd

若系统正确的配置了环境变量,那么可以使用以下指令启动snmpd:
snmpd -d
系统将自动寻找配置文件,也可以使用-c指明配置文件路径:
snmpd -c /ABC/soft/net-snmp/share/snmp/snmpd.conf

环境变量的设置请参考:

·Linux下NET-SNMP安装记录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值