본문 바로가기

NCS/NW운영관리

Install MRTG on CentOS 6.8

0. Network Topology

interface fa0/0

 desc Connected to internet through vmnet8

 ip address dhcp

 no sh

interface fa0/0

 desc Connected to Intranet

 ip add 192.168.99.1 255.255.255.0

 no shutdown

snmp-server contract yourid@yourdomain

access-list 5 permit host 192.168.99.2

snmp-server community kgitbank RW 5 

snmp-server community public RO 5

snmp-server host 192.168.99.2 kgitbank

int lo 0

ip add 1.1.1.1 255.255.255.0

exit

snmp-server trap-source lo 0


 

 To login root through ssh and install packages for snmp

 [root@lux01 ~]# yum -y install httpd net-snmp-libs net-snmp net-snmp-utils mrtg

 

Start httpd daemon 

 # systemctl start httpd ; systemctl enable httpd

 

 2. You should edit snmpd.conf like follow

 #  vi /etc/snmp/snmpd.conf

 

 

#  vi /etc/snmp/snmpd.conf

# line 41: 주석처리

# com2sec notConfigUser   default       public


# line 74,75: 주석 해지

74 com2sec local     localhost       kgitbank
75 com2sec mynetwork 192.168.99.0/24      kgitbank

# line 78,79: 주석 해지

78 group MyRWGroup  v2c        local
79 group MyROGroup  v2c        mynetwork

# line 85: 주석해지

85 view all    included  .1                               80

# line 93,94: 주석해지

93 access MyROGroup  ""      v2c       noauth    exact      all    none   none
94 access MyRWGroup  ""      v2c       noauth    exact      all    all    all


 

 

You should start the snmpd daemon

You should register to auto start at start the linux system

 Centos 6.X

  #  service snmpd start

  #  chkconfig snmpd on

 Centos 7.x

 [root@lux01 ~]# systemctl start snmpd
[root@lux01 ~]# systemctl enable snmpd

 

 5. Testing

 #  snmpwalk -v2c -c kgitbank localhost system

 #  snmpwalk -v2c -c kgitbank 192.168.99.1 system

 

 

6.  You should make cfg files for each monitoring systems.

# cfgmaker --global 'WorkDir: /var/www/mrtg' \

--output /etc/mrtg/mrtg.cfg \

kgitbank@192.168.99.2

OR

cfgmaker --global 'WorkDir: /var/www/mrtg' --output /etc/mrtg/mrtg.cfg kgitbank@192.168.99.2

(192.168.99.2는 mrtg를 설치 한 리눅스)


# cfgmaker --global 'WorkDir: /var/www/mrtg' \

--output /etc/mrtg/router.cfg \

kgitbank@192.168.99.1

OR

cfgmaker --global 'WorkDir: /var/www/mrtg' --output /etc/mrtg/router.cfg kgitbank@192.168.99.1

(192.168.99.1는 라우터 )


7. Create mrtg.sh for scheduling

# vi /etc/mrtg/mrtg.sh

#!/bin/bash

LOCK=/var/lock/mrtg/mrtg_1

CONFCACHE=/var/lib/mrtg/mrtg.ok

env  LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file $LOCK --confcache-file $CONFCACHE

env LANG=C /usr/bin/mrtg /etc/mrtg/router.cfg --lock-file $LOCK --confcache-file $CONFCACHE 


7. Make a executable file

# chmod 700 /etc/mrtg/mrtg.sh


8. Copy mrtg.sh to /root directory

# cp -a /etc/mrtg/mrtg.sh  /root/mrtg.sh


9. Register mrtg.sh in cron daemon

# vi /etc/cron.d/mrtg

*/5 * * * * root /root/mrtg.sh


10. Edit mrtg.cfg file 

#  vi /etc/mrtg/mrtg.cfg

# line 16: uncomment

Options[_]: growright, bits

# near line 73: make sure lines like follows are uncommented

Target[192.168.99.2_2]: 2:kgitbank@192.168.99.2:

SetEnv[192.168.99.2_2]: MRTG_INT_IP="192.168.99.2" MRTG_INT_DESCR="eth0"

MaxBytes[192.168.99.2_2]: 125000000

Title[192.168.99.2_2]: Traffic Analysis for 2 -- mrtg.kgitbank.local

PageTop[192.168.99.2_2]: <h1>Traffic Analysis for 2 -- mrtg.kgitbank.local</h1>


# vi /etc/mrtg/router.cfg

Target[192.168.99.1_1]: 1:kgitbank@192.168.99.1:

SetEnv[192.168.99.1_1]: MRTG_INT_IP="192.168.8.149" MRTG_INT_DESCR="FastEthernet0/0"

MaxBytes[192.168.99.1_1]: 1250000

Title[192.168.99.1_1]: Traffic Analysis for 1 -- R1.kgitbank.local

PageTop[192.168.99.1_1]: <h1>Traffic Analysis for 1 -- R1.kgitbank.local</h1>

 


 #  for (( i=1 ; i <= 3 ; i++ )); do env LANG=C mrtg /etc/mrtg/mrtg.cfg; done

 #  for (( i=1 ; i <= 3 ; i++ )); do env LANG=C mrtg /etc/mrtg/router.cfg; done 

 # indexmaker --columns=1 /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html

 # indexmaker --columns=1 /etc/mrtg/router.cfg >> /var/www/mrtg/index.html

또는

indexmaker --output=/var/www/mrtg/index.html mrtg.cfg  router.cfg 


# cat /etc/cron.d/mrtg 

# vi /etc/httpd/conf.d/mrtg.conf

# line 11: add IP address you allow to access

Allow from 127.0.0.1 192.168.99.0/24 


# /root/mrtg.sh

# /etc/rc.d/init.d/httpd restart ( systemctl restart httpd)

# firewall-cmd --permanent --add-service=http

Access to mrtg site