jueves, 20 de octubre de 2011

Pasos para instalar MRTG

Hola!


EL MRTG es util para monitorear servidores, asi que vamos a ver el paso a paso para instalar un servidor MRTG en un servidor CentOS.

Lo primero que se debe hacer es descargar el ultimo paquete estable, se puede encontrar aca:

http://oss.oetiker.ch/mrtg/

En downloads.

http://oss.oetiker.ch/mrtg/download.en.html



En la guia de instalacion Linux/UNIX, se recomienda tener instaladas las sigueintes librerias:

GCC ( http://gcc.gnu.org/)

Para saber si las tienes revisas asi:

rpm -q gcc
rpm -q gcc-c++


Si no las descargas:

yum install gcc
yum install gcc-c++




PERL (http://www.perl.com/)

Revisa si lo tienes instalado con:
perl -v
Se recomienda tener por lo menos la version 5.005, para que el MRTG  trabaje bien.

Segun lap agina del perl, se dice que las ultimas verisones de los Linux, vienen con el PERL preinstalado





GD,

http://www.boutell.com/gd/

Que es una libreria para dibujar imagenes GIF, se puede descargar en el link anterior.





libpng








http://www.libpng.org/pub/png/libpng.html




zlib







 http://www.gzip.org/zlib


Y por ultimo no olvidar el MRGT

http://oss.oetiker.ch/mrtg/pub

COMPILACION DE LIBRERIAS


mkdir -p /usr/local/src
cd /usr/local/src

Si no tienes la zlib instalada:

 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 ..

Si no tienes la libpng

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 ..

Para compilar  GD

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


Lo siguiente lo debes poner en una sola linea

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 ..

Para versiones en 2.0.11,prueba:
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/* .

COMPILACION MRTG

Todo esta listo para compliar el MRTG


cd /usr/local/src
 gunzip -c mrtg-2.17.1.tar.gz | tar xvf -
 cd mrtg-2.17.1

Si todas las librerias estan instaladas, en su sistema simplemente configure mrtg haciendo:

./configure --prefix=/usr/local/mrtg-2


De otra manera sera necesario, dar alguna librerias adicionales, para compliar el 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


Si tienes el RRDTool disponible, querras, decirle al MRTG que se use el opt con rrdtool
 Check mrtg-rrd.

Configure, hara que tu sistema este listo para el MRTG, si hay algun problema,
Has
 
 
make

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.

CONFIGURATION

The next step is to configure mrtg for monitoring a network device. This is done by creating an mrtg.cfg 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 cfgmaker. 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 bin subdirectory.
cfgmaker --global 'WorkDir: /home/httpd/mrtg'  \
          --global 'Options[_]: bits,growright' \
          --output /home/mrtg/cfg/mrtg.cfg    \
           community@router.abc.xyz

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.

RUNNING MRTG

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 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
RunAsDaemon: Yes

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.17.1/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.

Listo hasta aqui vamos,  luego queda hacer la configuracion del servidor para que monitoree lo que queremos,

Hasta una proxima entrada.


No hay comentarios:

Publicar un comentario