本文参考了互联网和CU论坛中MRTG相关的精华贴。
安装SNMP
先卸载系统自带的snmp,然后安装net-snmp
#cd /etc/rc3.d
#./S76snmpdx stop
#./S77dmi stop
从下载net-snmp-5.3.1.tar.gz
#gunzip -c net-snmp-5.3.1.tar.gz |tar xvf -
#cd net-snmp-5.3.1
#./configure
#make
#make install
安装完后,进行下面配置
#/usr/local/bin/snmpconf ;配置命令
The following installed configuration files were found:
1: /usr/local/etc/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): all
I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)
1: snmp.conf
2: snmptrapd.conf
3: snmpd.conf
Other options: quit
Select File: 3
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:
1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating Mode
Other options: finished
Select section: 1
Section: System Information Setup
Description:
This section defines some of the information reported in
the "system" mib group in the mibII tree.
Select from:
1: The [typically physical] location of the system.
2: The contact information for the administrator
3: The proper value for the sysServices object.
Other options: finished, list
Select section: 1
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: test office
Finished Output: syslocation "test office"
Section: System Information Setup
Description:
This section defines some of the information reported in
the "system" mib group in the mibII tree.
Select from:
1: The [typically physical] location of the system.
2: The contact information for the administrator
3: The proper value for the sysServices object.
Other options: finished, list
Select section: 2
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:
Finished Output: syscontact ""
Section: System Information Setup
Description:
This section defines some of the information reported in
the "system" mib group in the mibII tree.
Select from:
1: The [typically physical] location of the system.
2: The contact information for the administrator
3: The proper value for the sysServices object.
Other options: finished, list
Select section: finished
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:
1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating Mode
Other options: finished
Select section: 2
Section: Access Control Setup
Description:
This section defines who is allowed to talk to your running
snmp agent.
Select from:
1: a SNMPv3 read-write user
2: a SNMPv3 read-only user
3: a SNMPv1/SNMPv2c read-only access community name
4: a SNMPv1/SNMPv2c read-write access community name
Other options: finished, list
Select section: 3
Configuring: rocommunity
Description:
a SNMPv1/SNMPv2c read-only access community name
arguments: community [default|hostname|network/bits] [oid]
The community name to add read-only access for: public
The hostname or network address to accept this community name from [RETURN for all]:
The OID that this community should be restricted to [RETURN for no-restriction]:
Finished Output: rocommunity public
Section: Access Control Setup
Description:
This section defines who is allowed to talk to your running
snmp agent.
Select from:
1: a SNMPv3 read-write user
2: a SNMPv3 read-only user
3: a SNMPv1/SNMPv2c read-only access community name
4: a SNMPv1/SNMPv2c read-write access community name
Other options: finished, list
Select section:
Select section: finished
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:
1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating Mode
Other options: finished
Select section: 6
Section: Agent Operating Mode
Description:
This section defines how the agent will operate when it
is running.
Select from:
1: Should the agent operate as a master agent or not.
2: The system user that the agent runs as.
3: The system group that the agent runs as.
4: The IP address and port number that the agent will listen on.
Other options: finished, list
Select section: 4
Configuring: agentaddress
Description:
The IP address and port number that the agent will listen on.
By default the agent listens to any and all traffic from any
interface on the default SNMP port (161). This allows you to
specify which address, interface, transport type and port(s) that you
want the agent to listen on. Multiple definitions of this token
are concatenated together (using ':'s).
arguments: [transport:]port[@interface/address],...
Enter the port numbers, etc that you want the agent to listen to: 161
Finished Output: agentaddress 161
Section: Agent Operating Mode
Description:
This section defines how the agent will operate when it
is running.
Select from:
1: Should the agent operate as a master agent or not.
2: The system user that the agent runs as.
3: The system group that the agent runs as.
4: The IP address and port number that the agent will listen on.
Other options: finished, list
Select section: finished
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:
1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating Mode
Other options: finished
Select section: finished
I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)
1: snmp.conf
2: snmptrapd.conf
3: snmpd.conf
Other options: quit
Select File: quit
The following files were created:
snmpd.conf
These files should be moved to /usr/local/share/snmp if you
want them used by everyone on the system. In the future, if you add
the -i option to the command line I'll copy them there automatically for you.
Or, if you want them for your personal use only, copy them to
//.snmp . In the future, if you add the -p option to the
command line I'll copy them there automatically for you.
编写并启动net-snmp进程
//////////////////////////////////////////////////////////////////
#!/sbin/sh /
# /
# /etc/rc3.d/S91net-snmp /
# /
# pkill has moved over the years so we need to find it /
#
X=`which pkill` /
case "$1" in /
'start')
/usr/local/sbin/snmpd /
;;
'stop') /
$X -TERM -x -u 0 snmpd /
;; /
*)
echo "Usage: { start | stop }" /
exit 1
;; /
esac
exit 0 /
//////////////////////////////////////////////////////////////////
#chmod 744 S78net-snmp
#/etc/rc3.d/S78net-snmp start
# sec.name source community
编辑修改snmpd.conf
/usr/local/etc/snmp/snmpd.conf
com2sec local localhost public
com2sec mynetwork 192.168.10.0/24 public #可以自己定义community,
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyRWGroup usm initial
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80 #可以访问的snmp资源
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
重新启动snmp和apache
#/usr/local/sbin/snmpd restart
#/usr/local/httpd/bin/apachectl restart
阅读(7122) | 评论(1) | 转发(0) |