Professional Documents
Culture Documents
Mrtg Unix Guide
Mrtg Unix Guide
Mrtg Unix Guide
N#NA#AM#ME#E
mrtg-unix-guide - The MRTG 2.17.10 Linux/Unix Installation Guide
D#DE#ES#SC#CR#RI#IP#PT#TI#IO#ON#N
MRTG comes to you in Source Code. This means that you have to compile
parts of it before you can use it on a Unix machine. These instructions
help you to do so.
P#PR#RE#EP#PA#AR#RA#AT#TI#IO#ON#N
In order to compile and use mrtg you need a C compiler and a copy of
perl installed on your machine. In most cases this will already be
available. In case it is not, here are some starting points. Below
I'll give you a detailed run through the whole compilation process.
GCC The GNU C compiler comes preinstalled on most of the free Unices
out there. For commercial derivatives you may have to download and
compile it first. If you have no compiler at all there is a chicken
and egg problem, but there are also precompiled versions of gcc
available for most operating systems.
http://gcc.gnu.org/
Perl
Large parts of the MRTG system are written in the Perl scripting
language. Make sure there is a recent copy of perl on your machine
(try perl -v). At least version 5.005 is required for mrtg to work
well. If you use SNMPV3 and other new features you should use at
least 5.8.
http://www.perl.com/
If the first attempt fails and you do not get a working version of
mrtg, try compiling new copies of all libraries as explained below. Do
this B#BE#EF#FO#OR#RE#E you send email to me about problems compiling mrtg.
libpng
Is required by gd in order to produce PNG graphics files. Get it
from:
http://www.libpng.org/pub/png/libpng.html
zlib
Is needed by libpng to compress the graphics files you create. Get
a copy from
http://www.gzip.org/zlib
And last but not least you also need mrtg itself. In case you have not
yet downloaded it, you can find a copy on my website:
http://oss.oetiker.ch/mrtg/pub
L#LI#IB#BR#RA#AR#RY#Y C#CO#OM#MP#PI#IL#LA#AT#TI#IO#ON#N
In this section I will give you step by step instructions on how to
compile the various libraries required for the compilation of mrtg.
Note that these libraries may already be installed if you have a
_#*_#B_#S_#D
or _#L_#i_#n_#u_#x system so you can skip recompiling them. The w#wg#ge#et#t
program used
below is a simple web downloader. You can also enter the address into
your n#ne#et#ts#sc#ca#ap#pe#e if you don't have w#wg#ge#et#t available.
First let's create a directory for the compilation. Note that this may
already exist on your system. No problem, just use it.
mkdir -p /usr/local/src
cd /usr/local/src
wget http://www.zlib.net/zlib-1.2.3.tar.gz
gunzip -c zlib-*.tar.gz | tar xf -
rm zlib-*.tar.gz
mv zlib-* zlib
cd zlib
./configure
make
cd ..
wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.40.tar.gz
gunzip -c libpng-1.2.34.tar.gz | tar xf -
mv libpng-* libpng
cd libpng
env CFLAGS="-O3 -fPIC" ./configure --prefix=$INSTALL_DIR
make
rm *.so.* *.so
cd ..
wget http://www.boutell.com/gd/http/gd-1.8.4.tar.gz
gunzip -c gd-*.tar.gz |tar xf -
rm gd-*.tar.gz
mv gd-* gd
cd gd
The \ characters at the end of the following lines mean that all the
following material should actually be written on a single line.
wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz
gunzip -c gd-2.0.33.tar.gz |tar xf -
mv gd-2.0.33 gd
cd gd
env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" \
./configure --disable-shared --without-freetype --without-jpeg
make
cp .libs/* .
M#MR#RT#TG#G C#CO#OM#MP#PI#IL#LA#AT#TI#IO#ON#N
Ok, now everything is ready for the mrtg compilation.
cd /usr/local/src
gunzip -c mrtg-2.17.10.tar.gz | tar xvf -
cd mrtg-2.17.10
If all the libraries have been preinstalled on your system you can
configure mrtg by doing a simple:
./configure --prefix=/usr/local/mrtg-2
Otherwise you may have to give some hints on where to find the various
libraries required to compile mrtg:
./configure --prefix=/usr/local/mrtg-2 \
--with-gd=/usr/local/src/gd \
--with-z=/usr/local/src/zlib \
--with-png=/usr/local/src/libpng
If you have RRDtool available you might want to tell mrtg about it so
that you can opt to use rrdtool with mrtg. Check mrtg-rrd.
Configure will make sure your environment is fit for building mrtg. If
it finds a problem, it will tell you so and it will also tell you what
to do about it. If everything is OK, you will end up with a custom
Makefile for your system. Now type:
make
This builds the rateup binary and edits all the perl pathnames in the
scripts. You can now install mrtg by typing
You can now safely delete the libraries we compiled above. Then again,
you might want to keep them around so that you have them available when
compiling the next version of mrtg.
C#CO#ON#NF#FI#IG#GU#UR#RA#AT#TI#IO#ON#N
The next step is to configure mrtg for monitoring a network device.
This is done by creating an _#m_#r_#t_#g_#._#c_#f_#g file which defines what
you want
to monitor. Luckily, you don't have to dive straight in and start
writing your own configuration file all by yourself. Together with mrtg
you also got a copy of c#cf#fg#gm#ma#ak#ke#er#r. This is a script you can
point at a
router of your choice; it will create a mrtg configuration file for
you. You can find the script in the _#b_#i_#n subdirectory.
If you want to start rolling your own mrtg configuration files, make
sure you read mrtg-reference to learn all about the possible
configuration options.
R#RU#UN#NN#NI#IN#NG#G M#MR#RT#TG#G
Once you have created a configuration file, try the following:
/usr/local/mrtg-2/bin/mrtg /home/mrtg/cfg/mrtg.cfg
This will query your router and also create your first mrtg traffic
graphs and webpages. When you run mrtg for the first time there will be
a lot of complaints about missing log files. Don't worry, this is
normal for the first 2 times you start mrtg. If it keeps complaining
after this time you might want to look into the problem.
Starting mrtg by hand is not ideal in the long run. So when you are
satisfied with the results you can automate the process of running mrtg
in regular intervals (this means every 5 minutes by default).
You can either add mrtg to your crontab with a line like this:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * \
<mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg \
--logging /var/log/mrtg.log
or if you live in Linux Land the line may look like this if you are
using "crontab -e"
You can also run mrtg as a daemon process by adding the line
RunAsDaemon: Yes
#! /bin/sh
cd /usr/local/mrtg-2.17.10/bin && ./mrtg --user=mrtg-user \
/home/httpd/mrtg/mrtg.cfg --logging /var/log/mrtg.log
A#AU#UT#TH#HO#OR#R
Tobias Oetiker <tobi@oetiker.ch>