Multiple Agents

From Net-SNMP Wiki
Jump to: navigation, search
Good Answer

This is a Good Answer article. It was likely created as a response to a question on a Net-SNMP Mailing List and written up here for others to see. It likely covers material not yet in the FAQ or in the Tutorial but may someday be moved there

Question

How can I run multiple copies of the agent on a single machine?

Answer

First determine if this is something you should do

There are many many arguments against doing just this in general. Other solutions, like using AgentX, etc are more advisable if you just need a different process.

XXX: document

If you are going to do it...

To run the same executable multiple times, on different ports, and ensure that the persistent directories don't conflict, use these steps:

Determine your current configuration path:

snmpd -f -Lo -Dread_config -H 2>&1 | grep "config path" | head -1

This will probably be something like:

/usr/etc/snmp:/usr/share/snmp:/usr/lib/snmp:/root/.snmp:/var/net-snmp


Set the environment variable SNMPCONFPATH

Set the environment variable SNMPCONFPATH to the string from step 1, replacing /var/net-snmp with a unique directory and starting with a unique directory. You can also remove any directories that are empty, if you want.

NOTE: any conf files in the non-unique part of this path will be shared by ALL agents.

export SNMPCONFPATH=/usr/share/snmp/agent1:/usr/share/snmp:/var/net-snmp/agent1


Configure a unique snmpd.conf

  • Set the unique persistent directory
 echo "[snmp] persistentDir /var/net-snmp/agent1" >> /usr/share/snmp/agent1/snmpd.conf
  • Set the unique address or port
 echo "agentAddress udp:1161" >> /usr/share/snmp/agent1/snmpd.conf

SNMPv3 Note: If you do this using the default SNMPv3 engineID creation mechanism, everything will work fine. If you use the others, you may run into SNMPv3 engineID conflicts. Thus, make use of the default Net-SNMP engineID to be safe (which is based on time and a random number).

Repeat

repeat for each agent, using a unique directory and address/port each time.


Be careful

NOTE: if you are using the same shell to start all the agents, if you forget to change one of the environment variables before starting the next agent, things will get messy. I would recommend creating a script to start each agent, and have the script set the environment variables for you.

The other option is to specify the environment variable on the command line when starting snmpd, instead of exporting it. For example:

env SNMPCONFPATH=/opt/snmp/agent1:/opt/snmp:/var/net-snmp/agent1 snmpd