FreeBSD下SNMP协议简单配置


cd /usr/ports/net-mgmt/net-snmp
make config
make install clean

样例文件位于/usr/local/share/snmp/snmpd.conf.example

使用snmpconf命令生成配置文件snmpd.conf

$ /usr/local/bin/snmpconf -i -g basic_setup

The following installed configuration files were found:

//如果之前有过配置文件,会提示,可忽略

1:  /usr/local/share/snmp/snmpd.conf

Would you like me to read them in?  Their content will be merged with the

output files created by this session.

Valid answer examples: “all”, “none”,”3″,”1,2,5″

Read in which (default = all): //可选择none,忽略之前的配置

************************************************

*** Beginning basic system information setup ***

************************************************

Do you want to configure the information returned in the system MIB group (contact info, etc)? (default = y): y

//选择y

Configuring: syslocation

Description:

The [typically physical] location of the system.

Note that setting this value here means that when trying to

perform an snmp SET operation to the sysLocation.0 variable will make

the agent return the “notWritable” error code.  IE, including

this token in the snmpd.conf file will disable write access to

the variable.

arguments:  location_string

The location of the system: Chengdu

//syslocation,填写这台被监控机的地理位置信息,方便查阅

Finished Output: syslocation  Chengdu

Configuring: syscontact

Description:

The contact information for the administrator

Note that setting this value here means that when trying to

perform an snmp SET operation to the sysContact.0 variable will make

the agent return the “notWritable” error code.  IE, including

this token in the snmpd.conf file will disable write access to

the variable.

arguments:  contact_string

The contact information: orz(at)onono.org

//该服务器的管理员联系方式,最好填一个电子邮箱,服务器不可用的时候,可通知管理员

Finished Output: syscontact  orz(at)onono.org

Do you want to properly set the value of the sysServices.0 OID (if you don’t know, just say no)? (default = y): y

//选择y

Configuring: sysservices

Description:

The proper value for the sysServices object.

arguments:  sysservices_number

does this host offer physical services (eg, like a repeater) [answer 0 or 1]: 0

does this host offer datalink/subnetwork services (eg, like a bridge): 0

does this host offer internet services (eg, supports IP): 1

does this host offer end-to-end services (eg, supports TCP): 1

does this host offer application services (eg, supports SMTP): 1

//依次选择0、0、1、1、1,由于主机不充当网桥等角色,前两项填0

Finished Output: sysservices 76

**************************************

*** BEGINNING ACCESS CONTROL SETUP ***

**************************************

Do you want to configure the agent’s access control? (default = y): n

****************************************

*** Beginning trap destination setup ***

****************************************

Do you want to configure where and if the agent will send traps? (default = y): n

****************************************

*** Beginning monitoring setup ***

****************************************

Do you want to configure the agent’s ability to monitor various aspects of your system? (default = y): n

The following files were created:

接下来,使用net-snmp-config –create-snmpv3-user -ro命令配置权限,先确认snmpd已停止:

# /usr/local/etc/rc.d/snmpd stop

然后运行:

# net-snmp-config –create-snmpv3-user -ro

Enter a SNMPv3 user name to create:

myusername     //用户名

Enter authentication pass-phrase:

pass1234       //密码,长度大于8位

Enter encryption pass-phrase:

[press return to reuse the authentication pass-phrase]

phrase1234     //phrase,长度大于8位

adding the following line to /var/net-snmp/snmpd.conf:

createUser myusername MD5 “pass1234″ DES phrase1234

adding the following line to /usr/local/share/snmp/snmpd.conf:

rouser myusername

启动snmpd:/usr/local/etc/rc.d/snmpd start

用snmpwalk测试一下刚才的设置是否生效:

/usr/local/bin/snmpwalk -v 3 -l authPriv -u myusername -a MD5 -A 12345678 -x DES -X 87654321 localhost

SNMPv2-MIB::sysDescr.0 = STRING: FreeBSD ys-bsd.onono.org 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:48:17 UTC 2009     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::org
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (86606) 0:14:26.06
SNMPv2-MIB::sysContact.0 = STRING: Me <orz(at)onono.org>

……

……

NOTIFICATION-LOG-MIB::nlmLogDateAndTime.”default”.1 = STRING: 2010-7-19,12:49:39.0,-8:0
NOTIFICATION-LOG-MIB::nlmLogDateAndTime.”default”.2 = STRING: 2010-7-19,12:49:39.0,-8:0
NOTIFICATION-LOG-MIB::nlmLogDateAndTime.”default”.3 = STRING: 2010-7-19,12:49:39.0,-8:0
NOTIFICATION-LOG-MIB::nlmLogDateAndTime.”default”.4 = STRING: 2010-7-19,12:49:39.0,-8:0

确认snmpd已侦听UDP161端口

# sockstat -l4

USER   COMMAND  PID   FD PROTO LOCAL ADDRESS FOREIGN ADDRESS

root     snmpd      47043 9  udp4   *:161                 *:*

www      httpd      41173 3  tcp4   *:80                  *:*

www      httpd      41172 3  tcp4   *:80                  *:*

www      httpd      41171 3  tcp4   *:80                  *:*

root     httpd      92407 3  tcp4   *:80                  *:*

root     sshd       5388  4  tcp4   *:22                  *:*

mysql    mysqld     82716 5  tcp4   *:3306                *:*

root     sendmail   831   4  tcp4   127.0.0.1:25          *:*

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>