" Real coders don't blog, or at least not very often! " A.R.

CentOS Virtual Machine : monitoring with MRTG


Notes sur le configuration d'une Virtual Machine sous CentOS utilisant un data disk externe séparé du disque systeme, et contenant les parties configuration et data des applications.
Dans le cas présent, il s'agit de MRTG qui permet de monitorer le serveur.
(l'objectif d'une telle configuration et de pouvoir backuper / restaurer seulement le disque externe et de pouvoir reconstruire un nouveau serveur fonctionnel à partir d'une nouvelle machine virtuelle et d'un backup)


setup Server Monitoring


  • setup SNMPD

    install and configure SNMPD
    yum install net-snmp net-snmp-utils
    cd /etc/snmp
    cp snmpd.conf snmpd.conf.orig

    update snmpd configuration (!!!!! SECURITY WARNING !!!!!)
    vi snmpd.conf
        # remove original configuration for public by commenting out the following line
        #com2sec notConfigUser default public
        #
        # then add your own definitions (replace the network "10.1.1.0/24" by yours)
        com2sec local 127.0.0.1 pubalr1
        com2sec mynetwork 10.1.1.0/24 pubalr1
        group MyROGroup v1 local
        view all included .1 80
        access MyROGroup "" any noauth exact all none none
        # disk /
        # disk /datadisk

    update start script to log into /var/log/snmpd.log instead of syslog messages
    vim /etc/rc.d/init.d/snmpd
        OPTIONS="-Lf /var/log/snmpd.log -p /var/run/snmpd.pid -a"

    update start script to reduce logs to level 5 and below in syslog messages
    vim /etc/rc.d/init.d/snmpd
        OPTIONS="-LS0-5d -Lf /dev/null -p /var/run/snmpd.pid"

    restart snmpd
    service snmpd restart
    chkconfig --levels 2345 snmpd on
    chkconfig --list snmpd

    test connection to snmpd (should return a list of oid and values)
    snmpwalk -v 1 -c pubalr1 localhost interface


  • setup MRTG

    install the mrtg package
    yum install mrtg

    generate mrtg configuration file (we don't want snmp to be available from outside)
    cfgmaker --global 'WorkDir: /var/www/mrtg' --global 'Options[_]: bits,growright' --output /etc/mrtg/mrtg.cfg -ifref=ip pubalr1@127.0.0.1

    add disk monitoring
    vim /etc/snmp/snmpd.conf
        disk /
        disk /boot
        

    test retrieving the usage percentage (if nothing show up, restart snmpd)
    service snmpd restart
    snmpwalk -v 1 localhost -c pubalr1 dskPercent.1

    and compare with real values
    df -k

    retrieve and install server-info-num.cfg
    cd /etc/mrtg
    cp /XXXXX/server-info-num.cfg .

    or
    cd /etc/mrtg
    scp root@XXXXX.com:/etc/mrtg/server-info-num.cfg .

    update server-info-num.cfg with correct values for ip address, number of procs...
    (don't forget to update ip address if config file come from existing installation !!!!!)

    if not already installed, install apache (check "httpd on DATADISK" in previous article if needed)
    yum install httpd
    chkconfig --levels 2345 httpd on
    chkconfig --list httpd

    as root, add firewall entry to let http traffic go through
    system-config-securitylevel-tui

    update Apache configuration to allow access from outside (if really needed... but less secure!!!)
    vim /etc/httpd/conf.d/mrtg.conf
        # Deny from all
        # Allow from 127.0.0.1
        # Allow from ::1
        Allow from all

    restart apache
    service httpd restart


  • install RRD for MRTG

    install rrdtool
    yum install rrdtool perl-rrdtool perl-CGI

    install mrtg-rrd
    cd /goinfre
    wget ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz
    cd /usr/local/src
    cp /goinfre/mrtg-rrd-0.7.tar.gz .
    tar xvfz mrtg-rrd-0.7.tar.gz
        
    cd mrtg-rrd*
    mkdir -p /var/www/cgi-bin/mrtg
    cp mrtg-rrd.cgi /var/www/cgi-bin/mrtg

    update configuration of the CGI
    cd /var/www/cgi-bin/mrtg
    vim mrtg-rrd.cgi
        # update following line to add all mrtg cfg files
        ## BEGIN { @config_files = qw(/etc/mrtg/mrtg.cfg); }
        BEGIN { @config_files = qw(/etc/mrtg/mrtg.cfg /etc/mrtg/server-info-num.cfg); }

    update MRTG config files: add the following at the top
    vim /etc/mrtg/mrtg.cfg
        LogFormat: rrdtool
        PathAdd: /usr/bin
        #### already defined lower WorkDir: /var/mrtg
        IconDir: /mrtg
    vim /etc/mrtg/server-info-num.cfg
        LogFormat: rrdtool
        PathAdd: /usr/bin
        #### already defined lower WorkDir: /var/mrtg
        IconDir: /mrtg

    setup apache permission on /var/www/mrtg
    chown apache /var/www/mrtg

    run mrtg scripts to update data
    LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
    LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/server-info-num.cfg --lock-file /var/lock/mrtg/mrtg_2 --confcache-file /var/lib/mrtg/server-info-num.ok --logging /var/log/mrtg.log

    add job in existing crond file, by adding this line
    vim /etc/cron.d/mrtg
        */5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/server-info-num.cfg --lock-file /var/lock/mrtg/mrtg_2 --confcache-file /var/lib/mrtg/server-info-num.ok --logging /var/log/mrtg.log

    check that cron is running
    service crond status
    service crond restart

    test it by browsing
        http://127.0.0.1/cgi-bin/mrtg/mrtg-rrd.cgi/

    if no graphic show up it may be a permissions issue inside /var/www/mrtg
    ==> delete all png from the folder and rerun the update

    if no logo at the bottom
    ==> check /etc/httpd/conf.d/mrtg

    OK
  • February 11, 2012
    631 words


    Categories
    Tags
    centos virtual machine mrtg

    Connect. Socialize.