Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1150195
  • 博文数量: 188
  • 博客积分: 2267
  • 博客等级: 大尉
  • 技术积分: 1907
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-01 11:17
文章分类

全部博文(188)

文章存档

2016年(16)

2015年(16)

2014年(12)

2013年(32)

2012年(45)

2011年(67)

分类: LINUX

2011-10-09 10:24:04

系统环境RHEL6

# yum install net-snmp net-snmp-utils -y
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
Created directory: /var/lib/net-snmp/mib_indexes
Timeout: No Response from localhost
现在是提取不到数据的,我们需要对/etc/snmp/snmpd.conf 进行一些修改
# vim /etc/snmp/snmpd.conf 【以下颜色#表示注释,非#表示有效行】


#com2sec notConfigUser   default         public
com2sec local     localhost           public
com2sec mynetwork 192.168.0.0/24      public
#group   notConfigGroup v1           notConfigUser
#group   notConfigGroup v2c           notConfigUser

group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
group MyROGroup v1         mynetwork
group MyROGroup v2c        mynetwork
group MyROGroup usm        mynetwork

#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
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access MyROGroup ""      any       noauth    exact  all    none   none
access MyRWGroup ""      any       noauth    exact  all    all    none
将下边的这部分稍微改动一下,其实就是一些描述的东西
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root (configure /etc/snmp/snmp.local.conf)

syslocation Linux6.
syscontact Vivek G Gite




以上就是要修改的地方了!
# /etc/init.d/snmpd restart
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.55 = INTEGER: 2
现在就可以提取到数据了
#chkconfig snmpd on


现在装一下mrtg,我这里用到的是mrtg-2.16.2-5.el6.x86_64   
# yum install -y mrtg
# mkdir -p /var/www/html/mymrtg
# cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --output /etc/mrtg/mymrtg.cfg public@localhost   (这里是监控本机)
# cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --output /etc/mrtg/mymrtg1.cfg public@192.168.0.222  (这里是监控一台远程主机,这样做的话,需要给远程主机也安装snmp,进行配置,将本机的配置文件复制过去即可!)配置文件如下:
com2sec local     localhost           public
com2sec mynetwork 192.168.0.0/24      public
group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
group MyROGroup v1         mynetwork
group MyROGroup v2c        mynetwork
group MyROGroup usm        mynetwork
view all    included  .1                               80
access MyROGroup ""      any       noauth    exact  all    none   none
access MyRWGroup ""      any       noauth    exact  all    all    none
com2sec local     localhost           public
com2sec mynetwork 192.168.0.0/24      public
syslocation Linux6.
syscontact Vivek G Gite
dontLogTCPWrappersConnects yes

#/etc/init.d/snmpd restart
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.222 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.192.168.122.1 = INTEGER: 5
# chkconfig snmpd on
 #indexmaker --output=/var/www/html/mymrtg/index.html /etc/mrtg/mymrtg.cfg
Use of uninitialized value $first in hash element at /usr/bin/indexmaker line 353.
这里有时候会出现一个错误,是因为生成的/etc/mrtg/mymrtg.cfg 文件里接口内容被注掉了,将下边内容下的东西注释行去掉
,改成下边这样子:
### Interface 1 >> Descr: 'lo' | Name: 'lo' | Ip: '127.0.0.1' | Eth: '' ###
### The following interface is commented out because:
### * it is a Software Loopback interface

Target[localhost_1]: 1:public@localhost:
SetEnv[localhost_1]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo"
MaxBytes[localhost_1]: 1250000
Title[localhost_1]: Traffic Analysis for 1 -- server26.example.com
PageTop[localhost_1]:

Traffic Analysis for 1 -- server26.example.com


               

                       
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                       
System:server26.example.com in Linux6.
Maintainer:Vivek G Gite <vivek@nixcraft.com>
Description:lo 
ifType:softwareLoopback (24)
ifName:lo
Max Speed:1250.0 kBytes/s
Ip:127.0.0.1 (localhost.localdomain)

               


### Interface 2 >> Descr: 'eth0' | Name: 'eth0' | Ip: '192.168.0.55' | Eth: '52-54-00-00-00-1a' ###
### The following interface is commented out because:
### * has a speed of 0 which makes no sense

Target[localhost_2]: 2:public@localhost:
SetEnv[localhost_2]: MRTG_INT_IP="192.168.0.55" MRTG_INT_DESCR="eth0"
MaxBytes[localhost_2]: 1250000    (将此处的0 该掉,好像不是0就不会报错)
Title[localhost_2]: Traffic Analysis for 2 -- server26.example.com
PageTop[localhost_2]:

Traffic Analysis for 2 -- server26.example.com


               

                       
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                               
                                       
                                       
                               
                       
System:server26.example.com in Linux6.
Maintainer:Vivek G Gite <vivek@nixcraft.com>
Description:eth0 
ifType:ethernetCsmacd (6)
ifName:eth0
Max Speed:0.0 Bytes/s
Ip:192.168.0.55 (server26.example.com)

               



                                                                                                                                                                                             71,0-1        30%
# indexmaker --output=/var/www/html/mymrtg/index.html /etc/mrtg/mymrtg.cfg
然后运行这个就不会报错了
#  cp -av /var/www/mrtg/*.png /var/www/html/mymrtg/
# mrtg /etc/mrtg/mymrtg.cfg
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
       variable LANG is set to UTF-8. Please run mrtg in an environment
       where this is not the case. Try the following command to start:

       env LANG=C /usr/bin/mrtg /etc/mrtg/mymrtg.cfg
-----------------------------------------------------------------------
#  env LANG=C /usr/bin/mrtg /etc/mrtg/mymrtg.cfg
2011-10-09 10:08:53, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_1
2011-10-09 10:08:53, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_1 was invalid as well
2011-10-09 10:08:53, Rateup WARNING: /usr/bin/rateup Can't remove localhost_1.old updating log file
2011-10-09 10:08:53, Rateup WARNING: /usr/bin/rateup Can't rename localhost_1.log to localhost_1.old updating log file
2011-10-09 10:08:54, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_2
2011-10-09 10:08:54, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_2 was invalid as well
2011-10-09 10:08:54, Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file
2011-10-09 10:08:54, Rateup WARNING: /usr/bin/rateup Can't rename localhost_2.log to localhost_2.old updating log file
这条命令前两次运行会出错,运行三次就ok了
为了方便,我们可以写一个crontab
# crontab -e
*/5 * * * * /usr/bin/mrtg /etc/mrtg/mymrtg.cfg --logging /var/log/mrtg.log
由于页面访问是基于httpd的,记得开启httpd服务哦!
做到这里我们就已经可以访问了



我们再来看一下监控远程的应该怎么做,还记得刚才我们加的远程主机吗:
# cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --output /etc/mrtg/mymrtg1.cfg public@192.168.0.222
同样的,我们需要修改
/etc/mrtg/mymrtg1.cfg 里的配置:
1.#开头的注释行取消掉,将MaxBytes 后边的数字改成不为0
2.mkdir /var/www/html/mymrtg1 && cp /var/www/mrtg/*.png /var/www/html/mymrtg1/
3. indexmaker --output=/var/www/html/mymrtg1/index.html /etc/mrtg/mymrtg1.cfg
4. mrtg /etc/mrtg/mymrtg1.cfg
5.env LANG=C /usr/bin/mrtg /etc/mrtg/mymrtg1.cfg (同样运行3次)
6.crontab -e  加下边一行
   */5  * * * * /usr/bin/mrtg /etc/mrtg/mymrtg1.cfg --logging /var/log/mrtg1.log







详情请参考
阅读(2826) | 评论(0) | 转发(1) |
0

上一篇:Mrtg 监控服务器搭建

下一篇:Cacti 监控

给主人留下些什么吧!~~