MRTG generates traffic graphs in the PNG format. To be able to do this it needs several 3rd party libraries. When compiling these libraries I urge you to make sure you compile them as static libraries. There is just much less trouble ahead if you are doing it like this. See the Instructions in the next section for inspiration. Note that many free unices have all the required libraries already in place so there is no need to install another copy. To check it is best to skip all the library instructions below and go straight into the mrtg compile.
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 BEFORE you send email to me about problems compiling mrtg.
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:
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
If you do not have zlib installed:
wget http://www.gzip.org/zlib/zlib-1.1.4.tar.gz gunzip -c zlib-*.tar.gz | tar xf - rm zlib-*.tar.gz mv zlib-* zlib cd zlib ./configure make cd ..
If you don't have libpng installed
wget http://public.planetmirror.com/pub/sourceforge/l/li/libpng/libpng-1.0.15.tar.gz gunzip -c libpng-*.tar.gz |tar xf - rm libpng-*.tar.gz mv libpng-* libpng cd libpng make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib rm *.so.* *.so cd ..
And now you can compile gd
For versions up to 1.8.4, try:
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.
perl -i~ -p -e s/gd_jpeg.o//g Makefile make INCLUDEDIRS="-I. -I../zlib -I../libpng" \ LIBDIRS="-L../zlib -L. -L../libpng" \ LIBS="-lgd -lpng -lz -lm" \ CFLAGS="-O -DHAVE_LIBPNG" cd ..
For version starting around 2.0.11, try:
wget http://www.boutell.com/gd/http/gd-2.0.11.tar.gz gunzip -c gd-2.0.11.tar.gz |tar xf - mv gd-2.0.11 gd cd gd env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" ./configure --disable-shared \ --without-freetype --without-jpeg make cp .libs/* .
cd /usr/local/src gunzip -c mrtg-2.14.5.tar.gz | tar xvf - cd mrtg-2.14.5
If all the libraries have been preinstalled on your system you can configure mrtg by doing a simple:
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:
This builds the rateup binary and edits all the perl pathnames in the scripts. You can now install mrtg by typing
make install (requires gnu install)
All the software required by MRTG is now installed under the /usr/local/mrtg-2 subdirectory.
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.
cfgmaker --global 'WorkDir: /home/httpd/mrtg' \ --global 'Options[_]: bits,growright' \ --output /home/mrtg/cfg/mrtg.cfg \ firstname.lastname@example.org
This example above will create an mrtg config file in /home/mrtg/cfg assuming this is a directory visible on your webserver. You can read all about cfgmaker in cfgmaker. One area you might want to look at is the possibility of using --ifref=ip to prevent interface renumbering troubles from catching you.
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.
This will query your router and also create your first mrtg trafic 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"
*/5 * * * * <mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg \ --logging /var/log/mrtg.log
or like this if you use /etc/crontab
*/5 * * * * mrtg-user <mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg \ --logging /var/log/mrtg.log
You can also run mrtg as a daemon process by adding the line
to your mrtg configuration file and then creating a startup script in your system startup sequence. Unfortunately, adding startup scripts differs widely amongst different unix systems. The modern ones normally have a directory called /etc/init.d or /etc/rc.d/init.d where you put scripts which starts the process you want to run when the system boots. Further you must create a symbolic link in /etc/rc3.d or /etc/rc.d/rc?.d called S65mrtg (this is just a sample name ... it is just important that it starts with S followed by a two digit number). If you are not sure about this, make sure you consult the documentation of your system to make sure you get this right.
A minimal script to put into init.d might look like this:
#! /bin/sh cd /usr/local/mrtg-2.14.5/bin && ./mrtg --user=mrtg-user \ /home/httpd/mrtg/mrtg.cfg --logging /var/log/mrtg.log
Note that this will only work with RunAsDaemon: Yes in your mrtg.cfg file.