How to Install MRTG with SNMP on Linux RedHat 6.5 / CentOS 6.5

Learn | Teach Open Source Technologies

How to Install MRTG with SNMP on Linux RedHat 6.5 / CentOS 6.5

Before you Install MRTG please verify apache is installed on your machine

[root@mysql01 ~]# vi /etc/hosts
 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.49.19 mysql01
[root@mysql01 ~]# yum -y install net-snmp net-snmp-utils mrtg
 Loaded plugins: fastestmirror
 Setting up Install Process
 Determining fastest mirrors
 * base: mirrors.nayatel.com
 * extras: mirrors.nayatel.com
 * rpmforge: repoforge.xpg.com.br
 * updates: mirrors.nayatel.com
 base | 3.7 kB 00:00
 extras | 3.4 kB 00:00
 home_csbuild_centosextra | 1.2 kB 00:00
 percona-release-noarch | 951 B 00:00
 percona-release-noarch/primary | 4.3 kB 00:00
 percona-release-noarch 27/27
 percona-release-x86_64 | 951 B 00:00
 percona-release-x86_64/primary | 130 kB 00:01
 percona-release-x86_64 449/449
 http://repoforge.xpg.com.br/redhat/el6/en/x86_64/rpmforge/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 403 Forbidden"
 Trying other mirror.
 rpmforge | 1.9 kB 00:00
 Not using downloaded repomd.xml because it is older than what we have:
 Current : Fri Jul 11 06:48:57 2014
 Downloaded: Fri Jul 11 06:46:59 2014
 updates | 3.4 kB 00:00
 updates/primary_db | 2.1 MB 00:01
 Resolving Dependencies
 --> Running transaction check
 ---> Package mrtg.x86_64 0:2.16.2-7.el6 will be installed
 --> Processing Dependency: mrtg-libs = 2.16.2-7.el6 for package: mrtg-2.16.2-7.el6.x86_64
 --> Processing Dependency: perl-Socket6 for package: mrtg-2.16.2-7.el6.x86_64
 --> Processing Dependency: perl-IO-Socket-INET6 for package: mrtg-2.16.2-7.el6.x86_64
 --> Processing Dependency: perl(locales_mrtg) for package: mrtg-2.16.2-7.el6.x86_64
 --> Processing Dependency: perl(MRTG_lib) for package: mrtg-2.16.2-7.el6.x86_64
 --> Processing Dependency: gd for package: mrtg-2.16.2-7.el6.x86_64
 --> Processing Dependency: libgd.so.2()(64bit) for package: mrtg-2.16.2-7.el6.x86_64
 ---> Package net-snmp.x86_64 1:5.5-50.el6_6.1 will be installed
 --> Processing Dependency: net-snmp-libs = 1:5.5-50.el6_6.1 for package: 1:net-snmp-5.5-50.el6_6.1.x86_64
 --> Processing Dependency: libsensors.so.4()(64bit) for package: 1:net-snmp-5.5-50.el6_6.1.x86_64
 --> Processing Dependency: libnetsnmptrapd.so.20()(64bit) for package: 1:net-snmp-5.5-50.el6_6.1.x86_64
 --> Processing Dependency: libnetsnmpmibs.so.20()(64bit) for package: 1:net-snmp-5.5-50.el6_6.1.x86_64
 --> Processing Dependency: libnetsnmphelpers.so.20()(64bit) for package: 1:net-snmp-5.5-50.el6_6.1.x86_64
 --> Processing Dependency: libnetsnmpagent.so.20()(64bit) for package: 1:net-snmp-5.5-50.el6_6.1.x86_64
 --> Processing Dependency: libnetsnmp.so.20()(64bit) for package: 1:net-snmp-5.5-50.el6_6.1.x86_64
 ---> Package net-snmp-utils.x86_64 1:5.5-50.el6_6.1 will be installed
 --> Running transaction check
 ---> Package gd.x86_64 0:2.0.35-11.el6 will be installed
 --> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-11.el6.x86_64
 ---> Package lm_sensors-libs.x86_64 0:3.1.1-17.el6 will be installed
 ---> Package mrtg-libs.x86_64 0:2.16.2-7.el6 will be installed
 --> Processing Dependency: perl(SNMP_Session) for package: mrtg-libs-2.16.2-7.el6.x86_64
 --> Processing Dependency: perl(BER) for package: mrtg-libs-2.16.2-7.el6.x86_64
 ---> Package net-snmp-libs.x86_64 1:5.5-50.el6_6.1 will be installed
 ---> Package perl-IO-Socket-INET6.noarch 0:2.56-4.el6 will be installed
 ---> Package perl-Socket6.x86_64 0:0.23-4.el6 will be installed
 --> Running transaction check
 ---> Package libXpm.x86_64 0:3.5.10-2.el6 will be installed
 ---> Package perl-SNMP_Session.noarch 0:1.12-4.el6 will be installed
 --> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================================
 =============
 Package Arch Version Repository Size
 ======================================================================================================================================================================
 =============
 Installing:
 mrtg x86_64 2.16.2-7.el6 base 694 k
 net-snmp x86_64 1:5.5-50.el6_6.1 updates 306 k
 net-snmp-utils x86_64 1:5.5-50.el6_6.1 updates 174 k
 Installing for dependencies:
 gd x86_64 2.0.35-11.el6 base 142 k
 libXpm x86_64 3.5.10-2.el6 base 51 k
 lm_sensors-libs x86_64 3.1.1-17.el6 base 38 k
 mrtg-libs x86_64 2.16.2-7.el6 base 95 k
 net-snmp-libs x86_64 1:5.5-50.el6_6.1 updates 1.5 M
 perl-IO-Socket-INET6 noarch 2.56-4.el6 base 17 k
 perl-SNMP_Session noarch 1.12-4.el6 base 67 k
 perl-Socket6 x86_64 0.23-4.el6 base 27 k
Transaction Summary
 ======================================================================================================================================================================
 =============
 Install 11 Package(s)
Total download size: 3.1 M
 Installed size: 10 M
 Downloading Packages:
 (1/11): gd-2.0.35-11.el6.x86_64.rpm | 142 kB 00:00
 (2/11): libXpm-3.5.10-2.el6.x86_64.rpm | 51 kB 00:00
 (3/11): lm_sensors-libs-3.1.1-17.el6.x86_64.rpm | 38 kB 00:00
 (4/11): mrtg-2.16.2-7.el6.x86_64.rpm | 694 kB 00:00
 (5/11): mrtg-libs-2.16.2-7.el6.x86_64.rpm | 95 kB 00:00
 (6/11): net-snmp-5.5-50.el6_6.1.x86_64.rpm | 306 kB 00:00
 (7/11): net-snmp-libs-5.5-50.el6_6.1.x86_64.rpm | 1.5 MB 00:01
 (8/11): net-snmp-utils-5.5-50.el6_6.1.x86_64.rpm | 174 kB 00:00
 (9/11): perl-IO-Socket-INET6-2.56-4.el6.noarch.rpm | 17 kB 00:00
 (10/11): perl-SNMP_Session-1.12-4.el6.noarch.rpm | 67 kB 00:00
 (11/11): perl-Socket6-0.23-4.el6.x86_64.rpm | 27 kB 00:00
 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Total 484 kB/s | 3.1 MB 00:06
 Running rpm_check_debug
 Running Transaction Test
 Transaction Test Succeeded
 Running Transaction
 Installing : lm_sensors-libs-3.1.1-17.el6.x86_64 1/11
 Installing : 1:net-snmp-libs-5.5-50.el6_6.1.x86_64 2/11
 Installing : perl-Socket6-0.23-4.el6.x86_64 3/11
 Installing : perl-IO-Socket-INET6-2.56-4.el6.noarch 4/11
 Installing : libXpm-3.5.10-2.el6.x86_64 5/11
 Installing : gd-2.0.35-11.el6.x86_64 6/11
 Installing : perl-SNMP_Session-1.12-4.el6.noarch 7/11
 Installing : mrtg-libs-2.16.2-7.el6.x86_64 8/11
 Installing : mrtg-2.16.2-7.el6.x86_64 9/11
 Installing : 1:net-snmp-5.5-50.el6_6.1.x86_64 10/11
 Installing : 1:net-snmp-utils-5.5-50.el6_6.1.x86_64 11/11
 Verifying : perl-Socket6-0.23-4.el6.x86_64 1/11
 Verifying : lm_sensors-libs-3.1.1-17.el6.x86_64 2/11
 Verifying : perl-SNMP_Session-1.12-4.el6.noarch 3/11
 Verifying : 1:net-snmp-5.5-50.el6_6.1.x86_64 4/11
 Verifying : libXpm-3.5.10-2.el6.x86_64 5/11
 Verifying : 1:net-snmp-libs-5.5-50.el6_6.1.x86_64 6/11
 Verifying : mrtg-2.16.2-7.el6.x86_64 7/11
 Verifying : mrtg-libs-2.16.2-7.el6.x86_64 8/11
 Verifying : perl-IO-Socket-INET6-2.56-4.el6.noarch 9/11
 Verifying : gd-2.0.35-11.el6.x86_64 10/11
 Verifying : 1:net-snmp-utils-5.5-50.el6_6.1.x86_64 11/11
Installed:
 mrtg.x86_64 0:2.16.2-7.el6 net-snmp.x86_64 1:5.5-50.el6_6.1 net-snmp-utils.x86_64 1:5.5-50.el6_6.1
Dependency Installed:
 gd.x86_64 0:2.0.35-11.el6 libXpm.x86_64 0:3.5.10-2.el6 lm_sensors-libs.x86_64 0:3.1.1-17.el6 mrtg-libs.x86_64 0:2.16.2-7.el6
 net-snmp-libs.x86_64 1:5.5-50.el6_6.1 perl-IO-Socket-INET6.noarch 0:2.56-4.el6 perl-SNMP_Session.noarch 0:1.12-4.el6 perl-Socket6.x86_64 0:0.23-4.el6
Complete!

[root@mysql01 ~]# vi /etc/snmp/snmpd.conf (Line number configuraion)
41 #com2sec notConfigUser default public
74 com2sec local localhost mysql01
 75 com2sec mynetwork 192.168.49.0/24 mysql01
78 group MyRWGroup any local
 79 group MyROGroup any mynetwork
85 view all included .1 80
93 access MyROGroup "" any noauth 0 all none none
 94 access MyRWGroup "" any noauth 0 all all all
:wq!

[root@mysql01 ~]# /etc/rc.d/init.d/snmpd start
 Starting snmpd: [ OK ]
 [root@mysql01 ~]# chkconfig snmpd on

[root@mysql01 ~]# snmpwalk -v2c -c mysql01 localhost system
 SNMPv2-MIB::sysDescr.0 = STRING: Linux mysql01 2.6.32-504.1.3.el6.x86_64 #1 SMP Tue Nov 11 17:57:25 UTC 2014 x86_64
 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (6340) 0:01:03.40
 SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
 SNMPv2-MIB::sysName.0 = STRING: mysql01
 SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
 SNMPv2-MIB::sysORLastChange.0 = Timeticks: (4) 0:00:00.04
 SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDMIBObjects.3.1.1
 SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
 SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
 SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB
 SNMPv2-MIB::sysORID.5 = OID: TCP-MIB::tcpMIB
 SNMPv2-MIB::sysORID.6 = OID: IP-MIB::ip
 SNMPv2-MIB::sysORID.7 = OID: UDP-MIB::udpMIB
 SNMPv2-MIB::sysORID.8 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
 SNMPv2-MIB::sysORDescr.1 = STRING: The MIB for Message Processing and Dispatching.
 SNMPv2-MIB::sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.
 SNMPv2-MIB::sysORDescr.3 = STRING: The SNMP Management Architecture MIB.
 SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities
 SNMPv2-MIB::sysORDescr.5 = STRING: The MIB module for managing TCP implementations
 SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing IP and ICMP implementations
 SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing UDP implementations
 SNMPv2-MIB::sysORDescr.8 = STRING: View-based Access Control Model for SNMP.
 SNMPv2-MIB::sysORUpTime.1 = Timeticks: (3) 0:00:00.03
 SNMPv2-MIB::sysORUpTime.2 = Timeticks: (3) 0:00:00.03
 SNMPv2-MIB::sysORUpTime.3 = Timeticks: (3) 0:00:00.03
 SNMPv2-MIB::sysORUpTime.4 = Timeticks: (3) 0:00:00.03
 SNMPv2-MIB::sysORUpTime.5 = Timeticks: (3) 0:00:00.03
 SNMPv2-MIB::sysORUpTime.6 = Timeticks: (3) 0:00:00.03
 SNMPv2-MIB::sysORUpTime.7 = Timeticks: (3) 0:00:00.03
 SNMPv2-MIB::sysORUpTime.8 = Timeticks: (4) 0:00:00.04
[root@mysql01 ~]# cfgmaker --ifref=descr --ifdesc=descr [email protected] > /etc/mrtg/mrtg.cfg
vi /etc/mrtg/mrtg.cfg
 9 WorkDir: /var/www/mrtg
 16 Options[_]: growright, bits
make sure below lines are uncomment.
 ### Interface 2 >> Descr: 'eth0' | Name: 'eth0' | Ip: '192.168.49.19' | Eth: '00-0c-29-23-c6-8c' ###
 72
 73 Target[192.168.49.19_eth0]: \eth0:[email protected]:
 74 SetEnv[192.168.49.19_eth0]: MRTG_INT_IP="192.168.49.19" MRTG_INT_DESCR="eth0"
 75 MaxBytes[192.168.49.19_eth0]: 125000000
 76 Title[192.168.49.19_eth0]: eth0 -- mysql01
 77 PageTop[192.168.49.19_eth0]: <h1>eth0 -- mysql01</h1>
:wq!

Execute 3 times the below  script line

[root@mysql01 ~]# for (( i=1 ; i <= 3 ; i++ )); do env LANG=C mrtg /etc/mrtg/mrtg.cfg; done
 2015-02-04 11:47:47, Rateup WARNING: /usr/bin/rateup could not read the primary log file for 192.168.49.19_eth0
 2015-02-04 11:47:47, Rateup WARNING: /usr/bin/rateup The backup log file for 192.168.49.19_eth0 was invalid as well
 2015-02-04 11:47:47, Rateup WARNING: /usr/bin/rateup Can't remove 192.168.49.19_eth0.old updating log file
 2015-02-04 11:47:47, Rateup WARNING: /usr/bin/rateup Can't rename 192.168.49.19_eth0.log to 192.168.49.19_eth0.old updating log file
 2015-02-04 11:47:48, Rateup WARNING: /usr/bin/rateup Can't remove 192.168.49.19_eth0.old updating log file
 [root@mysql01 ~]# for (( i=1 ; i <= 3 ; i++ )); do env LANG=C mrtg /etc/mrtg/mrtg.cfg; done
 [root@mysql01 ~]# for (( i=1 ; i <= 3 ; i++ )); do env LANG=C mrtg /etc/mrtg/mrtg.cfg; done

Generate index file

[root@mysql01 ~]# indexmaker --columns=1 /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html
 [root@mysql01 ~]# cat /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
[root@mysql01 ~]# vi /etc/httpd/conf.d/mrtg.conf
 Allow from 192.168.49.0/24
:wq!
[root@mysql01 ~]# /etc/rc.d/init.d/httpd restart
 Stopping httpd: [ OK ]
 Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.49.19 for ServerName
 [ OK ]
For verification
[root@mysql01 ~]# ab -n 1000 -c 5 http://localhost/mrtg
 This is ApacheBench, Version 2.3 <$Revision: 655654 $>
 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
 Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
 Completed 100 requests
 Completed 200 requests
 Completed 300 requests
 Completed 400 requests
 Completed 500 requests
 Completed 600 requests
 Completed 700 requests
 Completed 800 requests
 Completed 900 requests
 Completed 1000 requests
 Finished 1000 requests
 Server Software: Apache/2.2.15
 Server Hostname: localhost
 Server Port: 80
Document Path: /mrtg
 Document Length: 305 bytes
Concurrency Level: 5
 Time taken for tests: 0.295 seconds
 Complete requests: 1000
 Failed requests: 0
 Write errors: 0
 Non-2xx responses: 1000
 Total transferred: 527000 bytes
 HTML transferred: 305000 bytes
 Requests per second: 3388.44 [#/sec] (mean)
 Time per request: 1.476 [ms] (mean)
 Time per request: 0.295 [ms] (mean, across all concurrent requests)
 Transfer rate: 1743.86 [Kbytes/sec] received
Connection Times (ms)
 min mean[+/-sd] median max
 Connect: 0 1 0.2 1 2
 Processing: 0 1 0.2 1 2
 Waiting: 0 0 0.3 0 2
 Total: 1 1 0.2 1 3
Percentage of the requests served within a certain time (ms)
 50% 1
 66% 1
 75% 1
 80% 2
 90% 2
 95% 2
 98% 2
 99% 2
 100% 3 (longest request)

mrtgmrtg1mrtg2