Configure SNMP and MRTG on CentOS 5.2
Procedure:
1. Install rpm packages[1]yum install net-snmp net-snmp-libs net-snmp-utils mrtg
chkconfig snmpd on
chkconfig snmpd on
2. Customize /etc/snmp/snmpd.conf
comment out line 55,56, add “view all” line as below#view systemview included .1.3.6.1.2.1.1
#view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80
comment out line 63, add “MyROGroup” line as below:#view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80
#access notConfigGroup "" any noauth exact systemview none none
access notConfigGroup "" any noauth exact all none none
access notConfigGroup "" any noauth exact all none none
3. Create file /etc/snmp/snmpd.options and specify snmpd listening on localhost only[2]
echo 'OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a udp:127.0.0.1"' > /etc/snmp/snmpd.options
4. Start snmpd [4]
service snmpd start
5. Configure mrtg [3] [5]
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.original
cfgmaker --output /etc/mrtg/mrtg.cfg --global "WorkDir: /var/www/mrtg" --global "Options[_]: growright,bits" --ifref=ip public@localhost
indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
cfgmaker --output /etc/mrtg/mrtg.cfg --global "WorkDir: /var/www/mrtg" --global "Options[_]: growright,bits" --ifref=ip public@localhost
indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
That’s it!
Reference:
Notes:
[1]. snmpd can’t start successfully? (undefined symbol: smux_snmp_select_list_get_length)If your snmpd can’t start successfully later, run command:
/usr/sbin/snmpd -Le -Lf /dev/null -p /var/run/snmpd.pid -a
to watch the output.if the error is:
/usr/sbin/snmpd: symbol lookup error: /usr/sbin/snmpd: undefined symbol: smux_snmp_select_list_get_length
Then most likely it is a dependency problem. You have net-snmp-libs installed and it is not upgraded to the same version as net-snmp. For example, the combination of net-snmp-5.3.1-24.el5_2.2 and net-snmp-libs-5.3.1-19.el5 leads to the described error:
[root@localhost]$ rpm -qa | grep snmp
net-snmp-libs-5.3.1-19.el5
net-snmp-utils-5.3.1-24.el5_2.2
net-snmp-5.3.1-24.el5_2.2
To fix it, you should upgrade net-snmp-libs.net-snmp-libs-5.3.1-19.el5
net-snmp-utils-5.3.1-24.el5_2.2
net-snmp-5.3.1-24.el5_2.2
yum upgrade net-snmp-libs
Or you can use command below to do the initial installation:
yum upgrade net-snmp net-snmp-libs net-snmp-utils mrtg
[2]. why use /etc/snmp/snmpd.options?
Answer is here: /etc/init.d/snmpd
#...
if [ -e /etc/snmp/snmpd.options ]; then
. /etc/snmp/snmpd.options
else
OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a"
fi
#...
if [ -e /etc/snmp/snmpd.options ]; then
. /etc/snmp/snmpd.options
else
OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a"
fi
#...
Compare the listening address before and after the setting:
before set the listening address:[root@localhost ~]$ netstat -lnp | grep snmp
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 1603/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 1603/snmpd
after set the listening address:tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 1603/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 1603/snmpd
[root@localhost ~]# netstat -lnp | grep snmp
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 29838/snmpd
udp 0 0 127.0.0.1:161 0.0.0.0:* 29838/snmpd
[root@localhost ~]#
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 29838/snmpd
udp 0 0 127.0.0.1:161 0.0.0.0:* 29838/snmpd
[root@localhost ~]#
[3]. warning message for “env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg”?
Keep running “env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg” unless you don’t see warning message. For me, I have to run it 3 times.[root@localhost ~]$ env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup could not read the primary log file for 10.xx.xxx.xxx_10.xx.xxx.xxx
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup The backup log file for 10.xx.xxx.xxx_10.xx.xxx.xxx was invalid as well
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_10.xx.xxx.xxx.old updating log file
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't rename 10.xx.xxx.xxx_10.xx.xxx.xxx.log to 10.xx.xxx.xxx_10.xx.xxx.xxx.old updating log file
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup could not read the primary log file for 10.xx.xxx.xxx_67.xx.xxx.xxx
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup The backup log file for 10.xx.xxx.xxx_67.xx.xxx.xxx was invalid as well
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_67.xx.xxx.xxx.old updating log file
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't rename 10.xx.xxx.xxx_67.xx.xxx.xxx.log to 10.xx.xxx.xxx_67.xx.xxx.xxx.old updating log file
[root@localhost ~]$ env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
08-01-2009 12:22:43, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_10.xx.xxx.xxx.old updating log file
08-01-2009 12:22:43, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_67.xx.xxx.xxx.old updating log file
[root@localhost ~]$ env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
[root@localhost ~]$
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup could not read the primary log file for 10.xx.xxx.xxx_10.xx.xxx.xxx
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup The backup log file for 10.xx.xxx.xxx_10.xx.xxx.xxx was invalid as well
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_10.xx.xxx.xxx.old updating log file
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't rename 10.xx.xxx.xxx_10.xx.xxx.xxx.log to 10.xx.xxx.xxx_10.xx.xxx.xxx.old updating log file
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup could not read the primary log file for 10.xx.xxx.xxx_67.xx.xxx.xxx
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup The backup log file for 10.xx.xxx.xxx_67.xx.xxx.xxx was invalid as well
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_67.xx.xxx.xxx.old updating log file
08-01-2009 12:22:41, Rateup WARNING: /usr/bin/rateup Can't rename 10.xx.xxx.xxx_67.xx.xxx.xxx.log to 10.xx.xxx.xxx_67.xx.xxx.xxx.old updating log file
[root@localhost ~]$ env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
08-01-2009 12:22:43, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_10.xx.xxx.xxx.old updating log file
08-01-2009 12:22:43, Rateup WARNING: /usr/bin/rateup Can't remove 10.xx.xxx.xxx_67.xx.xxx.xxx.old updating log file
[root@localhost ~]$ env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
[root@localhost ~]$
[4]. test snmp and mrtg after starting snmpd
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.10.xx.xxx.xx4 = INTEGER: 3
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx6 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx7 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx8 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx9 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xxx = INTEGER: 4
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.10.xx.xxx.xx4 = INTEGER: 3
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx6 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx7 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx8 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xx9 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.xx.xxx.xx.xxx = INTEGER: 4
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
If you can’t see a similar output and if there’s no output, then there’s something wrong with you configure.
[5]. Configure mrtg to grab bandwidth usage from multiple snmpd hosts:cfgmaker --output /etc/mrtg/mrtg.cfg --global "WorkDir: /var/www/mrtg" --global "Options[_]: growright,bits" --ifref=ip snmpaccnt@xx.xxx.xx.x0 --ifref=ip snmpaccnt@xx.xxx.xx.x4 --ifref=ip snmpaccnt@xx.xxx.xx.x.2
You should configure detailed security policy for each snmp cummunity and set snmpd listening on a proper intranet ip address