Multiple Agents

From Net-SNMP Wiki
Revision as of 16:55, 15 October 2007 by Rstory (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

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

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