Mrtg的安装
服务器配置:
至强3.0GHZ *2
4G ECC DDR内存
300G SCSI Utrl 320 15K 硬盘 *2
操作系统:freebsd 7.0
一、apache 安装
1. cd /usr/ports/www/apache2
make install clean
2. apache安装目录结构:
Installing configuration files
/usr/local/etc/apache2
/usr/local/share/examples/apache2
/usr/local/www/data-dist
/usr/local/www/error-dist
/usr/local/www/icons-dist
/usr/local/www/cgi-bin-dist
/usr/local/share/doc/apache2
3. 手动启动apache2
/usr/local/sbin/httpd $
4. 自动启动文件:
/usr/local/etc/rc.d/apache2
5. apache配置:
ee /etc/rc.conf
apache2_enable="YES"
cd /usr/local/etc/apache2/
cp /usr/local/etc/apache2/httpd.conf /usr/local/etc/apache2/httpd.conf.new
mv /usr/local/etc/apache2/httpd.conf /usr/local/etc/apache2/httpd.conf.bak
grep -v "#" ./httpd.conf.new > ./httpd.conf
ee /usr/local/etc/apache2/httpd.conf
加入:
Alias /mrtg "/usr/local/www/data/mrtg"
AuthType Basic
AuthName "This is a private directory. Please Login:"
AuthUserFile /usr/local/www/data/passwd
Require user tigerjxh
htpasswd -c /usr/local/www/data/passwd tigerjxh
New password:
Re-type new password:
apachectl restart
二、安装net-snmp/ucd-snmp/p5-SNMP
1. cd /usr/ports/net-mgmt/net-snmp
make install clean #出现相关提示
2. 配置snmp
mkdir -p /usr/local/etc/snmp
cp /usr/local/share/snmp/snmpd.conf.example /usr/local/etc/snmp/snmpd.conf.new
cd /usr/local/etc/snmp/
grep -v "#" ./snmpd.conf.new >./snmpd.conf
ee snmpd.conf
#vim /usr/local/etc/snmp/snmpd.conf
下面是我的配置文件内容
com2sec local localhost private
com2sec mynet 192.168.0.0/24 public
com2sec public default public
group mygroup v1 mynet
group mygroup v2c mynet
group mygroup usm mynet
group local v1 local
group local v2c local
group local usm local
group public v1 public
group public v2c public
group public usm public
view all included .1 80
access mygroup "" any noauth exact mib2 none none
access public "" any noauth exact all none none
access local "" any noauth exact all all all
syslocation Right here, right now.
syscontact Me
proc mountd
proc ntalkd 4
proc sendmail 10 1
exec echotest /bin/echo hello world
disk / 10000
load 12 14 14
3. 手动启动snmpd
/usr/local/sbin/snmpd &
4. 自动启动snmpd监听服务:
ee /etc/rc.conf进行配置,在该文件种添加下面内容:
#snmpd#
snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
#snmpd_conffile="/usr/local/share/snmpd.conf /etc/snmpd.conf"
snmpd_conffile="/usr/local/etc/snmp/snmpd.conf /etc/snmpd.conf"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"
下面参数可选
"
#NET_SNMP_SYS_LOCATION=”Beijing,China"
#DEFAULT_SNMP_VERSION=3
#NET_SNMP_MIB_MODULES="host smux mibII/mta_sendmail ucd-snmp/disk"
#NET_SNMP_LOGFILE=/var/log/snmpd.log
#NET_SNMP_PERSISTENTDIR=/var/net-snmp
5. 测试snmpd
a.端口测试:
netstat -na |grep 161
udp4 0 0 *.161 *.*
存在161端口,则正常
b.命令测试:
snmpwalk -v 1 -c public localhost system
SNMPv2-MIB::sysDescr.0 = STRING: FreeBSD safe.tiancity.com 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52 UTC 2008
i386
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.8
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (798) 0:00:07.98
SNMPv2-MIB::sysContact.0 = STRING: Me
SNMPv2-MIB::sysName.0 = STRING: safe.tiancity.com
SNMPv2-MIB::sysLocation.0 = STRING: Right here, right now.
SNMPv2-MIB::sysServices.0 = INTEGER: 72
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (3) 0:00:00.03
SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
。。。。。。。。。
您可以去掉后面的system参数得到所有的snmp返回数据,通过分析这些数据就可以实现对系统的各种监控,这是mrtg通过snmp实现监控的途径。
6. snmp代理启动:
/usr/local/etc/rc.d/snmpd
/usr/local/etc/rc.d/snmptrapd
三、安装mrtg-2.13.2
1. cd /usr/ports/net-mgmt/mrtg/
make install clean
2. 配置mrtg
#ee /etc/rc.conf
mrtg_daemon_enable="YES"
:wq!
方式一:
cd /usr/local/etc/mrtg/
cp /usr/local/etc/mrtg/mrtg.cfg.sample /usr/local/etc/mrtg/mrtg.cfg.new
grep -v "#" ./mrtg.cfg.new >./mrtg.cfg
cp /usr/local/etc/mrtg/mrtg.cfg /usr/local/www/data/mrtg/
#vim /usr/local/etc/mrtg/mrtg.cfg
方式二:
cd /usr/local/www/data/
mkdir mrtg
cd mrtg
/usr/local/bin/cfgmaker --output=/usr/local/www/data/mrtg/index.cfg //snmp v1
/usr/local/bin/cfgmaker --snmp-options=:::::2 --output=/usr/local/www/data/mrtg/index.cfg //snmp v2
然后修改index.cfg文件,主要修改以下内容,以符合你的实际情况,此处的192.168.1.254是你要监控的网卡的ip地址。
ee index.cfg
修改
WorkDir: /usr/local/www/data/mrtg #根据实际情况修改
Options[_]: growright, bits
Language: gb2312
让MRTG每5分钟去获取一次流量信息
ee /etc/crontab
在最后增加:
*/5 * * * * /usr/local/bin/mrtg /usr/local/www/data/mrtg/index.cfg
按着:
/usr/local/bin/mrtg /usr/local/www/data/mrtg/index.cfg
这个需要运行3次,前两次都会报错,不用去理会他,第3次就应该没有错误了,不过,若是有问题的话,就需要改index.cfg,再执行直到没有错误发生为止。
3、制作首页index.html
/usr/local/bin/indexmaker --output=/usr/local/www/data/mrtg/index.html /usr/local/www/data/mrtg/index.cfg
附Cisco交换机&路由器SNMP配置:
snmp-server community tigerjxh RO
snmp-server location tigerjxh
snmp-server enable traps tty
snmp-server host 192.168.5.119 version 2c tigerjxh
阅读(2007) | 评论(1) | 转发(0) |