SNMP é usado como parte de monitoramento de utilização de recursos em dispositivos ligados na rede, informa utilização de CPU, tráfego de rede, status de serviços e etc.
Estou escrevendo esse artigo por que será pré-requisito na configuração e instalação do Cacti para “grafar” os recursos dos dispositivos monitorados.
Pré-requisitos
Instalação do serviço SNMPd
A instalação será feita via Yum
yum install net-snmp.i386 net-snmp-libs.i386 net-snmp-utils.i386
... Installed: net-snmp.i386 1:5.3.2.2-5.el5_3.2 net-snmp-libs.i386 1:5.3.2.2-5.el5_3.2 net-snmp-utils.i386 1:5.3.2.2-5.el5_3.2 Dependency Installed: lm_sensors.i386 0:2.10.7-4.el5 Complete!
É interessante garantir que o serviço será iniciado no boot
chkconfig --levels 35 snmpd on
Configurando o serviço SNMP
Depois de instalado, o SNMP precisa ser configurado para responder a uma comunidade e em que modo ele irá responder.
Também é interessante colocar uma descrição de quem é o responsável pelo servidor e onde está localizado o equipamento.
Para iniciar a configuração, vá ao diretório /etc/snmp e apague o arquivo original que está lá ou renomeie, caso queira futuramente consultá-lo.
cd /etc/snmp mv snmpd.conf snmpd.conf.orig
Inicie o processo de configuração com o comando snmpconf, faz parte do pacote net-snmp-utils e é uma mão na roda, diga-se de passagem
cd /etc/snmp snmpconf
Uma série de questionários será apresentada.
Na primeira fase
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: snmpd.conf 2: snmp.conf 3: snmptrapd.conf Other options: quit Select File: 1
Selecione 1 para gerar o arquivo snmpd.conf que é o responsável por colher as métricas de utilização de recursos do SO.
Aqui nessa sessão da configuração tem uma pegadinha: nem sempre a ordem apresentada é a mesma, então, preste atenção na opção escolhida.
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: Monitor Various Aspects of the Running Host 2: Access Control Setup 3: Extending the Agent 4: Trap Destinations 5: System Information Setup 6: Agent Operating Mode Other options: finished Select section: 2
A primeira configuração é informações de acesso, então é a opção 2 “Access Control Setup”
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
Permitir acesso somente leitura aos dados do servidor. Evita algumas surpresas :)
Opção escolhida: 3 “SNMPv1/SNMPv2c read-only access community name”
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: 5nMPC0mmunity
Nome da comunidade, não coloque “public” por que é muito manjada, e qualquer network scanner vai testar por isso, escolha uma mais difícil, colocando números e letras maiúsculas e minúsculas, evite colocar símbolos como $, #, % etc, vai confundir e gerar problemas futuros para scripts e para o próprio Cacti. Se utilizar o Nagios então, tá perdido ;)
O nome escolhido aqui foi 5nMPC0mmunity
The hostname or network address to accept this community name from [RETURN for all]:
Quem vai ter acesso ao serviço SNMP, se pressionar direto vai liberar pra todos que souberem o nome da comunidade, caso queira restringir a um host apenas, coloque o IP do host, se é para um rede, coloque a rede aqui no formato 192.168.0.0/24
The OID that this community should be restricted to [RETURN for no-restriction]:
Se quer permitir a visualização de apenas alguns recursos, coloque o OID do recurso aqui, no caso, vou deixar liberado para todos os recursos serem visualizados
Finalizada a configuração de controle de acesso, vai voltar para a sessão própria. Como está terminado escreva finished ou apenas f para sair e voltar ao menu principal.
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: finished
Próxima fase, informar detalhes do dispositivo, como contato e localização física.
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: Monitor Various Aspects of the Running Host 2: Access Control Setup 3: Extending the Agent 4: Trap Destinations 5: System Information Setup 6: Agent Operating Mode Other options: finished Select section: 5
Escolha a opção 5 “System Information Setup” e pressione
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
Opção escolhida 1, para informações de localização do equipamento
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: Data Center, Rack 3
Informado onde está o equipamento Data Center, Rack 3, pressione quando terminar.
Voltando para a tela de configuração com informações do equipamento, selecione a opção 2 para dizer quem é o responsável
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: Daniel Kühl Lima
Informe alguns dados que facilitem a localização do responsável. Aqui foi informado Daniel Kühl Lima. Pressione quando terminar e voltará para a tela de configuração de informações.
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
Sessão terminada, dá pra sair dessa tela e voltar ao menu principal. Escreve finished ou f para sair.
Voltando para o menu principal, e como está tudo configurado como desejamos, escreva finished ou f para salvar e terminar a tarefa.
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: Monitor Various Aspects of the Running Host 2: Access Control Setup 3: Extending the Agent 4: Trap Destinations 5: System Information Setup 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: snmpd.conf 2: snmp.conf 3: snmptrapd.conf Other options: quit Select File: quit
Escreva quit para sair de vez.
Iniciando o serviço SNMP
Com o serviço configurado é hora de iniciar.
service snmpd start
Starting snmpd: [ OK ]
Verificando o funcionamento
Pra verificar se está tudo a contento, execute o comando a seguir que irá se conectar ao serviço SNMP e retornará as métricas do sistema.
snmpwalk -c 5nMPC0mmunity -v2c localhost
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.30.5-fogonacaixadagua #7 SMP Fri Sep 11 11:32:29 BRT 2009 i686 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (13823) 0:02:18.23 SNMPv2-MIB::sysContact.0 = STRING: "Daniel Kühl Lima" SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain SNMPv2-MIB::sysLocation.0 = STRING: "Data Center, Rack 3" SNMPv2-MIB::sysORLastChange.0 = Timeticks: (9) 0:00:00.09 ...
No final do processo o arquivo /etc/snmp/snmpd.conf ficou assim:
########################################################################### # # snmpd.conf # # - created by the snmpconf configuration program # ########################################################################### # SECTION: Access Control Setup # # This section defines who is allowed to talk to your running # snmp agent. # rocommunity: a SNMPv1/SNMPv2c read-only access community name # arguments: community [default|hostname|network/bits] [oid] rocommunity 5nMPC0mmunity ########################################################################### # SECTION: System Information Setup # # This section defines some of the information reported in # the "system" mib group in the mibII tree. # syslocation: 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 syslocation "Data Center, Rack 3" # syscontact: 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 syscontact "Daniel Kühl Lima"
Pronto.

12 comments
Join the conversationMatheus - 17/02/2010
Boa kra…
Me ajudou bastante
Obrigado
Josue Junior - 02/06/2010
Daniel, esse tutorial me ajudou muito, Valew.
David Costa - 13/07/2010
Daniel, parabéns pelo tutorial simples e direto. Me guiei por ele e não encontrei problema algum.
Valeu!
wellington bastos - 13/12/2010
valeu cara mto obrigado.
Vicente de Andrade - 11/02/2011
Muito obrigado pelo tutorial, foi muito útil. Consegui configurar para o FreeBSD 8.1.
Muito obrigado
MANOGAUCHO - 25/04/2011
Valeuuuu!!!
Pingback: Cacti post1 – instalação e configuração no CentOS 6 « GNU/Linux-BR.com
VitorGGA - 30/07/2012
Vlw man, bem detalhado.
Pingback: >_Cacti | >_Tutoriais GNU Linux
Pingback: >_Cacti | >_Tutoriais GNU Linux
Ygor - 06/03/2014
Parabens pela dica, está excelente e me ajudou muito :)
Alexandre - 08/04/2015
Melhor tutorial que encontrei até hoje, deu tudo certinho e como estou aprendendo linux abriu bem a minha mente. Obrigado por compartilhar.
Related Posts
Podman + MariaDB: Resolvendo “Error establishing a database connection” após reiniciar o servidor
Daniel K Lima 30/11/2025Converter espaços/tabs em um único caracter (um espaço ou vírgula etc) com sed
Daniel K Lima 02/06/2016Conveter novas (\n) linhas em vírgula ou espaço usando sed
Daniel K Lima 06/04/2016SARG 2.3.1 erro ao compilar no Fedora 14
Daniel K Lima 11/03/2011rootsh: Keylogger para CLI do Linux
Daniel K Lima 20/04/2010CLI: Converter um PDF para uma imagem
Daniel K Lima 06/04/2010