Difference between revisions of "Net-Snmp on Ubuntu"

From Net-SNMP Wiki
Jump to: navigation, search
Line 67: Line 67:
 
> ./configure
 
> ./configure
 
</pre>
 
</pre>
The configure script will scan your system and prepare the "Makefile" from which we will perform our actual install. configure will ask you a few questions - I just press "enter" and go with the defaults. After a while you should see something like this,
+
The configure script will scan your system and prepare the "Makefile" from which we will perform our actual install. configure will ask you a few questions - I just press "enter" and go with the defaults. Now there IS a way to avoid those questions - simple include those options when you call configure. That means running it like this,
 +
<pre>
 +
> ./configure --with-default-snmp-version="3" --with-sys-contact="@@no.where" --with-sys-location="Unknown" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp"
 +
</pre>
 +
Feel free to change those options if you want. I'm just showing what the default settings are. In fact, if you have an embedded build environment and want to automate the whole procedure, passing in those settings is the best way to avoid the user-prompt messages.
 +
After a while you should see something like this,
 
<pre>
 
<pre>
 
---------------------------------------------------------
 
---------------------------------------------------------

Revision as of 03:41, 17 January 2011

Some rambling from the author

I originally wanted to write a tutorial on configuring and optimizing the net-snmp agent to run on an embedded MIPS platform. The more I thought about the idea, the more I realized - it would have a VERY limited audience. Going over my notes, I discovered something - with the exception of the compiler settings, all my instructions could very well be used to install the agent on a regular x86 ubuntu system. Eureka! And thus this tutorial was born. My idea is that if you understand how to customize the net-snmp agent to run on an ubuntu system following these instructions, you should be in a very good position to modify the instructions to your own platform (and I get a bigger reading audience!).

Getting the sources

You can download the latest sources of net-snmp from here,

Main net-snmp Download Page

Setting the Environment

I advise you to start off with a fresh install of the Ubuntu Desktop edition. Don't worry - we won't really need the GUI, but if you are a beginner, it will be useful. Now, open up a terminal window and create a projects directory,

>pwd
/home/abru/
>mkdir projects
>cd projects
>pwd
/home/abru/projects

The purpose of the "projects" directory is an organizational measure. I like keeping all the code I work with separate from my "Download" or "Document" or "Home" folders (just messy, doing that). And "abru" is my username (short for Abraham).

Now we need to move the source tarball into the projects folder. If you haven't downloaded it yet, you can download the sources with the "wget" command (At the time of this writing, 5.6.1 is the latest),

>pwd
/home/abru/projects
>wget http://sourceforge.net/projects/net-snmp/files/net-snmp/5.6.1/net-snmp-5.6.1.tar.gz
...
...
>ls
net-snmp-5.6.1.tar.gz
>

Now lets get about extracting the sources,

>tar -xvzf net-snmp-5.6.1.tar.gz
...
...
...
>ls
net-snmp-5.6.1  net-snmp-5.6.1.tar.gz
> mv net-snmp-5.6.1 net-snmp
> ls
net-snmp  net-snmp-5.6.1.tar.gz
> 

It's not really a must, to the "mv" step above. But doing it here will help keep this tutorial updated (fewer changes with future releases).

Ubuntu Dependencies

If you've installed the desktop version of Ubuntu, then there's only 1 package missing from your install. Get it from the Ubuntu repositories with this,

> sudo apt-get install libperl-dev

If instead, you went and installed the server version of ubuntu, then you'll probably need to get gcc and build-essentails as well - I don't remember if there were more.


Configuring & Installing

Anyway, with all that out of the way, lets configure the package! Follow these steps,

> cd net-snmp
> ./configure

The configure script will scan your system and prepare the "Makefile" from which we will perform our actual install. configure will ask you a few questions - I just press "enter" and go with the defaults. Now there IS a way to avoid those questions - simple include those options when you call configure. That means running it like this,

> ./configure --with-default-snmp-version="3" --with-sys-contact="@@no.where" --with-sys-location="Unknown" --with-logfile="/var/log/snmpd.log" --with-persistent-directory="/var/net-snmp"

Feel free to change those options if you want. I'm just showing what the default settings are. In fact, if you have an embedded build environment and want to automate the whole procedure, passing in those settings is the best way to avoid the user-prompt messages. After a while you should see something like this,

---------------------------------------------------------
            Net-SNMP configuration summary:
---------------------------------------------------------

  SNMP Versions Supported:    1 2c 3
  Building for:               linux
  Net-SNMP Version:           5.6.1
  Network transport support:  Callback Unix Alias TCP UDP IPv4Base SocketBase TCPBase UDPIPv4Base UDPBase
  SNMPv3 Security Modules:     usm
  Agent MIB code:             default_modules =>  snmpv3mibs mibII ucd_snmp notification notification-log-mib target 
agent_mibs agentx disman/event disman/schedule utilities host
  MYSQL Trap Logging:         unavailable
  Embedded Perl support:      enabled
  SNMP Perl modules:          building -- embeddable
  SNMP Python modules:        disabled
  Crypto support from:        internal
  Authentication support:     MD5 SHA1
  Encryption support:         DES AES

---------------------------------------------------------

> 

The above means that "configure" has finished running and we can start compiling!

The compiling step is easy, just run "make". Like this,

> make

Depending on how powerful your system is, it can take anywhere between 2 - 4 mins for it to finish. After your done, you can install the net-snmp package to your ubuntu system by running this,

> sudo make install

You'll need to use the "sudo" command as the install will copy over the needed executables to system directories and obviously, you'll need root permission for that. From a user-perspective, we're done, but if you want to develop stuff with the snmp agent I'd advise you to install the net-snmp Perl libraries too. For that do the following,

> cd /home/abru/projects/net-snmp/perl
> perl Makefile.PL 
Writing Makefile for NetSNMP::default_store
Writing Makefile for NetSNMP::ASN
Writing Makefile for NetSNMP::OID
Writing Makefile for NetSNMP::agent::Support
Writing Makefile for NetSNMP::agent::default_store
Writing Makefile for NetSNMP::agent
Writing Makefile for SNMP
Writing Makefile for NetSNMP::TrapReceiver
Writing Makefile for Bundle::NetSNMP
>

What we've done is create the Makefiles. Now to compile and install them,

> make
> make test  <<OPTIONAL>>
> sudo make install

The idea behind the "make test" line is to run checks to see if the installation would work (I think). Unfortunately, its a bit buggy and will return a few failed tests. In spite of it, you can install the perl-dependencies and it will work just fine.