Check whether the system has installed the snmp service # 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
The above installation packages will be available after the SNMP service is installed.
Install the SNMP service 1. Configure the local yum service and use yum to install yum install-y net-snmp * 2. Configure the start of the SNMP service # chkconfig snmpd on
# Chkconfig -- list | grep snmpd check whether startup setting is successful
Snmpd 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable authentication SNMP Service 1. use snmpwalk to obtain the host name # snmpwalk-v 2c-c public localhost sysName.0
SNMPv2-MIB: sysName.0 = STRING: wh69
Snmpwalk usage
Snmpwalk-v 1 | 2c | 3 (SNMP Version)-c <community string> ip address OID (object identifier)
2. Run the snmptranslate command To check whether the snmp tool can use # 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
If some oid is found, the snmp tool can be used normally to configure the SNMP service 1. Configure the SNMP connection string community string # vi/etc/snmp/snmpd. conf
Modify the following fields
# sec.name source communitycom2sec notConfigUser default public
Modify
PublicModify the permission of the device node for your own defined community string2. in the configuration file/etc/snmp/snmpd. conf, find the following location:
##### 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.1view systemview included .1.3.6.1.2.1.25.1.1
View: defines which node devices can be viewed.
By default, snmp can only view device information under nodes 1.3.6.1.2.1.1 and 1.3.6.1.2.1.25.1.1,
The host's CPU, memory, and other devices are not under these nodes, so the data cannot be obtained.
Therefore, you can modify the configuration as follows:
##### 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 .1view systemview included .1.3.6.1.2.1.1view systemview included .1.3.6.1.2.1.25.1.1
A line is added here:
View systemview supported ded. 1
Displays information about all devices on the. 1 node. 3. Modify the Process checks configuration and find the following position in the configuration file/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
Remove
# Proc mountd
# Proc ntalkd 4
# Proc sendmail 10 1
Remove the # sign before the three rows. 4. Modify the Executables/scripts configuration and find the following position in the configuration file/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:
Set
# Exec echotest/bin/echo hello world
Remove the previous #, uncomment 5. Modify disk checks Configuration
Find the following location in the configuration file/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
Set
# Disk/10000
Remove the # Before and uncomment. 6. Modify the load average checks configuration and find the following position in the configuration file/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
Set
# Load 12 14 14
Remove the preceding #, uncomment 7. Save the modification, and restart the snmp service # service snmpd restart8. verify the snmp service after the configuration modification # snmpwalk-v 2c-c xindixindi localhost 1.3.6.1.4.1.2021.11.11.0
UCD-SNMP-MIB: ssCpuIdle.0 = INTEGER: 99
As shown above, the CPU idle rate obtained through the local localhost is 99%. Now, you can monitor the linux server through the SNMP service in monitoring systems such as solarwinds and Cacti.