How to configure SNMP to monitor our server

Hello again! Finally after a long stop of a month and a half without publishing, we are back to work. Today we bring you a small tutorial on how to configure SNMP to monitor our server, we will focus on CentOS as it is one of the most widespread distributions for servers. Except for the installation, the rest is similar in other distributions.

If you like these articles share it and or leave us your comments in your social networks so we can keep growing and publishing more articles.

If the article seems advanced and you need more information about the first steps in linux you can see the articles of the basic series:here. On the other hand, if you like this kind of articles you can see all the related articles in this category. here.

Let’s get started!

What is SNMP?

SNMP, or Simple Network Management Protocol, is an application layer protocol of the OSI network model, is used to exchange information about the system (Hardware and Software). This allows us to know the current state of the system, information about the hardware, running processes, etc. Mainly it is usually integrated in routers, switches, servers, firmware of some servers, especially servers with ILO technology (as the iLO/OA of HP, iDraq dell, etc.), network printers, etc. That is to say, normally the network oriented devices are already prepared. But what if I have a cloud server or a newly installed server and I want to monitor the system via SNMP? As the SNMP protocol is implemented at the application layer there are multiple implementations to put it into operation in our linux system.

Installing the service

One of the reasons why we chose to teach how to install this service in CentOS was also because of its ease of installation and configuration.

To install the service in CentOS you only have to do the following from a terminal with the root user:
1- Install the SNMP service:

yum -y install net-snmp net-snmp-utils

2- We make the service start at the beginning

chkconfig snmpd on

3- Now we have to configure the SNMP service:

To do this we must move the default configuration file from /etc/snmp/snmpd.conf to /etc/snmp/snmpd.conf.orig:

mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig

Then we edit the file with

vi /etc/snmp/snmpd.conf
And enter the following configuration (paying attention to the comments):

 

# Mapeamos la comunidad 'ConfigUserComunity' a 'ConfigUser'
# Mapeamos la comunidad 'AllUserCommunity' a 'AllUser'
#
sec.name
source community
com2sec ConfigUser default ConfigUserComunity
com2sec AllUser default AllUserCommunity
# Map 'ConfigUser' to 'ConfigGroup' for SNMP Version 2c
# Map 'AllUser' to 'AllGroup' for SNMP Version 2c
#
sec.model sec.name
group ConfigGroup v2c ConfigUser
group AllGroup v2c AllUser
# Definimos 'SystemView' para todo lo que cuelgue de  .1.3.6.1.2.1.1 (or
.1.3.6.1.2.1.25.1)
# Definimos 'AllView' para todo lo que cuelgue de  .1
#
incl/excl subtree
view SystemView included .1.3.6.1.2.1.1
view SystemView included .1.3.6.1.2.1.25.1.1
view AllView included .1
#Definimos permisos para las comunidades
access  ConfigGroup  "" any noauth exact SystemView none   none
access  AllGroup  "" any noauth exact AllView none   none

4- We lift the service

service snmpd restart

The data of each community can then be queried with an SNMP client such as snmpwalk:
Syntax

snmpwalk -v 2c -c COMUNIDAD -O e 127.0.0.1

For AllUserCommunity:

snmpwalk -v 2c -c AllUserCommunity -O e 127.0.0.1

Once the SNMP service is configured we can monitor the server in multiple ways. One of them is configuring a script from another point executing a “snmpwalk” to the server and if it does not give the proper values or does not respond it will trigger an alert.
Another way is to use systems like librenms or Zabbix and thus trigger more advanced alerts.

Remember, if you like these articles, share them and leave us your comments in your social networks so we can continue to grow and publish more articles.

See you soon!

Leave a Reply