Usando Linux para muchas cosas y disfrutando de videojuegos, en dispositivos moviles, consolas y pc. Using Linux for many things and enjoying video games, mobile devices, consoles and pc

Como instalar MRTG en Linux

Como instalar MRTG en Linux

Formas para monitorear tu trafico existen muchas, comerciales y gratuitas. Es una forma de controlar en que gastamos nuestro preciado ancho de banda y entre las herramientas con mas tiempo en este medio podemos decir que esta MRTG, la cual hoy veremos como instalarla y configurarla en Linux.

Bien, Linux no es uno solo, hay varias distribuciones y en este articulo nos extenderíamos (posiblemente no acabaríamos nunca) mucho por lo que en este articulo veremos el paso a paso de como instalar y configurar para Linux Ubuntu Server y Linux Centos (Centos 6 y Centos 7). Ya estas listo/a, comencemos entonces este mrtg tutorial en español.

Requerimientos MRTG Linux Ubuntu Server y Linux Centos

Como instalar MRTG en Linux

Mi recomendación para Linux Ubuntu es que uses una versión LTS, mas estable, mas segura por nombrar algunas ventajas

Instalamos MRTG en Ubuntu server

-Instalamos dependencias
sudo apt install apache2 snmpd snmp mrtg

-Apenas estamos terminando de instalar mrtg y se nos pide confirmar que solo root pueda leer la conf. Respondemos Si y damos Enter
Restringimos permisos en MRTG

-Editamos el conf de snmpd y descomentamos una linea
sudo vi /etc/snmp/snmpd.conf
rocommunity public localhost

-Activamos y ejecutamos el demonio de snmpd
sudo systemctl enable snmpd
sudo systemctl restart snmpd
sudo systemctl status snmpd

-Activamos y ejecutamos el demonio de apache2
sudo systemctl enable apache2
sudo systemctl restart apache2
sudo systemctl status apache2

-Creamos un directorio para mrtg. En este directorio se almacenaran los archivos que se iran generando y apache debe poder acceder a el
sudo mkdir /var/www/html/mrtg

-Por seguridad, creamos una copia del cfg de mrtg (mas adelante puede que necesitemos el original)
sudo cp /etc/mrtg.cfg /etc/mrtg.cfg.bck

-Modificamos el cfg de mrtg agregando el directorio creado en pasos anteriores
sudo vi /etc/mrtg.cfg
WorkDir: /var/www/html/mrtg

-Activamos permisos
sudo chmod 777 /etc/mrtg.cfg

-Añadimos valores al cfg de nuestro monitor network leidos desde snmpd
sudo cfgmaker public@localhost >/etc/mrtg.cfg
--base: Get Device Info on public@localhost:
--base: Vendor Id: Unknown Vendor - 1.3.6.1.4.1.8072.3.2.10
--base: Populating confcache
--base: Get Interface Info
--base: Walking ifIndex
--snpd:   public@localhost: -> 1 -> ifIndex = 1
--snpd:   public@localhost: -> 2 -> ifIndex = 2
--base: Walking ifType
--snpd:   public@localhost: -> 1 -> ifType = 24
--snpd:   public@localhost: -> 2 -> ifType = 6
--base: Walking ifAdminStatus
--snpd:   public@localhost: -> 1 -> ifAdminStatus = 1
--snpd:   public@localhost: -> 2 -> ifAdminStatus = 1
--base: Walking ifOperStatus
--snpd:   public@localhost: -> 1 -> ifOperStatus = 1
--snpd:   public@localhost: -> 2 -> ifOperStatus = 1
--base: Walking ifMtu
--snpd:   public@localhost: -> 1 -> ifMtu = 65536
--snpd:   public@localhost: -> 2 -> ifMtu = 1500
--base: Walking ifSpeed
--snpd:   public@localhost: -> 1 -> ifSpeed = 10000000
--snpd:   public@localhost: -> 2 -> ifSpeed = 1000000000

-Creamos un index.html, le damos permisos y llenamos de valores sacados de snmpd
sudo touch /var/www/html/mrtg/index.html
sudo chmod 777 /var/www/html/mrtg/index.html
sudo indexmaker /etc/mrtg.cfg >/var/www/html/mrtg/index.html

-Abrimos un browser y navegamos al URL del servidor http://ip-servidor/mrtg donde ya debemos poder ver la gráfica de consumo de ancho de banda


Instalamos MRTG en Linux Centos

-Instalamos dependencias para nuestro network monitor linux
yum install mrtg net-snmp net-snmp-utils httpd

-Creamos una copia del conf de snmpd
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bck

-Aunque snmpd puede tener muchos valores, los basicos que necesitamos son los siguientes. Editamos el conf y solo dejamos los siguientes parametros
vi /etc/snmp/snmpd.conf
com2sec local     localhost           public
group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
view all    included  .1                               80
access MyRWGroup ""      any       noauth    exact  all    all    none
syslocation Bogota, Colombia
syscontact Root <mecasoft@gmail.com>

Activamos snmpd en Centos 6

-Activamos y ejecutamos el demonio snmpd
chkconfig snmpd on
service snmpd restart

Activamos snmpd en Centos 7

-Activamos y ejecutamos el demonio snmpd
systemctl enable snmpd
systemctl restart snmpd
systemctl status snmpd
● snmpd.service - Simple Network Management Protocol (SNMP) Daemon.
   Loaded: loaded (/usr/lib/systemd/system/snmpd.service; enabled; vendor preset: disabled)
   Active: active (running) since sáb 2017-02-04 10:44:01 COT; 15s ago
 Main PID: 10011 (snmpd)
   CGroup: /system.slice/snmpd.service
           └─10011 /usr/sbin/snmpd -LS0-6d -f

feb 04 10:44:01 cen.drivemeca.com systemd[1]: Starting Simple Network Management Protocol (SNMP) Daemon....
feb 04 10:44:01 cen.drivemeca.com snmpd[10011]: NET-SNMP version 5.7.2
feb 04 10:44:01 cen.drivemeca.com systemd[1]: Started Simple Network Management Protocol (SNMP) Daemon..

-Verificamos funcionamiento de snmpd leyendo los valores de nuestras tarjetas de red activas
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.5.135 = INTEGER: 2

-Creamos el cfg de mrtg
cfgmaker --global 'WorkDir: /var/www/mrtg' --output /etc/mrtg/mrtg.cfg public@localhost

-Creamos la pagina web de mrtg
indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

-Modificamos el conf de mrtg en apache dando permisos para visualizar la pagina web
vi /etc/httpd/conf.d/mrtg.conf
Alias /mrtg /var/www/mrtg

<Location /mrtg>
   Options Indexes
   AllowOverride None
   Order allow,deny
   Allow from all
</Location>

-Creamos una tarea cron para que se autogeneren las graficas
vi /etc/cron.d/mrtg
*/5 * * * * root 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

Activamos crond en Centos 6

-Activamos y ejecutamos el demonio crond
chkconfig crond on
service crond restart

Activamos crond en Centos 7

-Activamos y ejecutamos el demonio crond
systemctl enable crond
systemctl restart crond
systemctl status crond
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since sáb 2017-02-04 10:53:07 COT; 14s ago
 Main PID: 10104 (crond)
   CGroup: /system.slice/crond.service
           └─10104 /usr/sbin/crond -n

feb 04 10:53:07 cen.drivemeca.com crond[10104]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 93% if used.)
feb 04 10:53:07 cen.drivemeca.com systemd[1]: Started Command Scheduler.
feb 04 10:53:07 cen.drivemeca.com crond[10104]: (CRON) INFO (running with inotify support)
feb 04 10:53:07 cen.drivemeca.com systemd[1]: Starting Command Scheduler...
feb 04 10:53:07 cen.drivemeca.com crond[10104]: (CRON) INFO (@reboot jobs will be run at computer's startup.)

Activamos apache en Centos 6

-Activamos y ejecutamos el demonio httpd
chkconfig httpd on
service httpd restart

Activamos apache en Centos 7

-Activamos y ejecutamos el demonio httpd
systemctl enable httpd
systemctl restart httpd
systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since sáb 2017-02-04 10:55:35 COT; 13s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 10156 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 10161 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─10161 /usr/sbin/httpd -DFOREGROUND
           ├─10162 /usr/sbin/httpd -DFOREGROUND
           ├─10163 /usr/sbin/httpd -DFOREGROUND
           ├─10164 /usr/sbin/httpd -DFOREGROUND
           ├─10165 /usr/sbin/httpd -DFOREGROUND
           └─10166 /usr/sbin/httpd -DFOREGROUND

feb 04 10:55:34 cen.drivemeca.com systemd[1]: Starting The Apache HTTP Server...
feb 04 10:55:35 cen.drivemeca.com systemd[1]: Started The Apache HTTP Server.

-Ya podemos abrir un browser y navegar al url http;//ip-servidor/mrtg donde veremos la gráfica de mrtg
En nuestra pagina web ya debe aparecer el trafico graficado con MRTG


Artículos recomendadosComo instalar Nagios en Linux Centos paso a paso
                                            Como instalar PNP4Nagios en Linux
                                            Como instalar NRPE en Nagios paso a paso
                                            Como instalar snmp trap en Nagios
                                            Como crear un usuario de solo lectura en Nagios
                                            Como instalar ntopng en Linux Centos DETALLADO ✍️


Puede que no sea la herramienta mas sofisticada pero mrtg es algo a tener en tu linux network tools.

Quiero vivir de mi blog, de enseñar opensource, pero esto no sera posible sin tu apoyo, me ayudas?


Satisfech@ con el articulo? Bien, hazme un favor, compártelo en tus redes sociales (compartir es sexy). Escríbeme en los comentarios aquí debajo y pasa la voz compartiendo el tweet.

Sígueme en twittergoogle+facebook, email, YouTube o Patreon y podrás estar enterado de todas mis publicaciones.
Disfrútenlo.

Share/Bookmark

No hay comentarios:

Publicar un comentario

Dejame un comentario, aprecio la retroalimentacion. Leave me a comment, I appreciate the feedback.