Cacti 监控 ubuntu 主机的 snmp 配置 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
snopy
V2EX    Ubuntu

Cacti 监控 ubunt 主机的 snmp 配置

  •  
  •   snopy 2015-03-26 08:57:42 +08:00 3160 次点击
    这是一个创建于 3927 天前的主题,其中的信息可能已经有所发展或是发生改变。
    分为两部分(按需选择对应的设置):
    1.Cacti监控本地ubuntu主机(localhost)的snmp配置:

    Install SNMPD SNMP

    $ sudo apt-get install snmpd

    Create a backup file of snmpd.conf original file that we will edit later

    $ sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.ori

    Create the new snmpd.conf file

    $ sudo vim /etc/snmp/snmpd.conf

    Add the file with these lines

    rocommunity public
    syslocation "Your Location"
    syscontact [email protected]

    Then edit the /etc/default/snmpd file

    $ sudo vim /etc/default/snmpd

    Disable this line below by adding # in front of the line

    #SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'

    And add a new line

    SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'

    Restart the SNMPD service

    $ sudo /etc/init.d/snmpd restart
    * Restarting network management services

    经试验验证,确实可用。

    测试

    root@test:~# snmpwalk -v 2c -c public localhost


    2. Cacti监控远程ubuntu主机(限局域网内)的snmp配置:

    运行如下两个命令

    apt-get install snmp [enter]

    apt-get install snmpd [enter]

    顺利运行完毕,使用如下命令测试一下

    lsof -i:161

    如果输出了正在运行snmp协议,便说明安装OK。

    我的SNMP配置文件/etc/snmp/snmpd.conf与网上早年的一些资料不同,主要是 压根没有出现com2sec,下面附上我的snmpd.conf的前半部分:

    -----------------------------------下面是snmpd.conf---------------------------------

    ###############################################################################
    #
    # EXAMPLE.conf:
    # An example configuration file for configuring the Net-SNMP agent ('snmpd')
    # See the 'snmpd.conf(5)' man page for details
    #
    # Some entries are deliberately commented out, and will need to be explicitly activated
    #
    ###############################################################################
    #
    # AGENT BEHAVIOUR
    #

    # Listen for connections from the local system only
    #agentAddress udp:127.0.0.1:161
    # Listen for connections on all interfaces (both IPv4 *and* IPv6)
    agentAddress udp:161,udp6:[::1]:161


    ###############################################################################
    #
    # SNMPv3 AUTHENTICATION
    #
    # Note that these particular settings don't actually belong here.
    # They should be copied to the file /var/lib/snmp/snmpd.conf
    # and the passwords changed, before being uncommented in that file *only*.
    # Then restart the agent


    # createUser authOnlyUser MD5 "remember to change this password"
    # createUser authPrivUser SHA "remember to change this one too" DES
    # createUser internalUser MD5 "this is only ever used internally, but still change the password"


    # If you also change the usernames (which might be sensible),

    # then remember to update the other occurances in this example config file to match.

    ###############################################################################
    #
    # ACCESS CONTROL
    #


    # system + hrSystem groups only
    view systemonly included .1.3.6.1.2.1.1
    view systemonly included .1.3.6.1.2.1.25.1
    view systemonly included .1 80
    # Full access from the local host
    #rocommunity public localhost
    # Default access to basic system info
    rocommunity public default -V systemonly


    # Full access from an example network
    # Adjust this network address to match your local
    # settings, change the community string,
    # and check the 'agentAddress' setting above
    #rocommunity secret 10.0.0.0/16


    # Full read-only access for SNMPv3
    rouser authOnlyUser
    # Full write access for encrypted requests
    # Remember to activate the 'createUser' lines above
    #rwuser authPrivUser priv


    # It's no longer typically necessary to use the full 'com2sec/group/access' configuration
    # r[ou]user and r[ow]community, together with suitable views, should cover most requirements

    -----------------------------------上面是snmpd.conf---------------------------------


    我的目的是进行远程SNMP连接,所以需要做如下的修改:

    将下面这一行
    agentAddress udp:127.0.0.1:161
    注释掉,即
    #agentAddress udp:127.0.0.1:161

    然后将原来的这一行
    #agentAddress udp:161,udp6:[::1]:161
    去掉注释,即
    agentAddress udp:161,udp6:[::1]:161
    这样便可以实现snmp的远程监听了。

    但修改后cacti服务器还是无法监测到CPU、内存、流量的数据,所以需要再做如下修改:
    在snmpd.conf中找到下面的内容
    view systemonly included .1.3.6.1.2.1.1
    view systemonly included .1.3.6.1.2.1.25.1

    在下面加上一行
    view systemonly included .1 80
    这样就允许监听所有设备了。

    完成所有修改后,重启snmp
    service snmpd restart

    本地测试SNMP是否监测各类指标的方法:运行如下命令
    snmpwalk -v 2c -c public localhost
    如果输出结果有好多页好多页,应该是设置成功了!
    2 条回复    2015-03-26 09:49:04 +08:00
    xiaobu
        1
    xiaobu  
       2015-03-26 09:17:08 +08:00   1
    LZ这是在科普嘛
    snopy
        2
    snopy  
    OP
       2015-03-26 09:49:04 +08:00
    最近在做Cacti监控服务器,我在这只是把google到的方法汇总一下,总有需要的小伙伴
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     4152 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 46ms UTC 05:32 PVG 13:32 LAX 21:32 JFK 00:32
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86