ubuntu下SNMP服务的配置

来源:互联网 发布:ff14龙女捏脸数据 编辑:程序博客网 时间:2024/05/07 06:49

背景:机房新增了几台ubuntu服务器,需要用已有的cacti来监测它们,所以要在新服务器上安装和配置SNMP协议。

动机:我参考网上很多资料安装和配置SNMP,没搞定,于是自己研究了一下如何配置,最终顺利完成,所以分享一下。


1. SNMP安装

运行如下两个命令

apt-get install snmp [enter]

apt-get install snmpd [enter]

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

lsof -i:161

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


2. SNMP配置(重点)

我的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
如果输出结果有好多页好多页,应该是设置成功了!






原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 电脑打不开flv格式的视频怎么办 电脑打不开pdf格式的文件怎么办 pdf格式在电脑上打不开怎么办 zip压缩的时候空间不足怎么办 电子发票填抬头错了怎么办 发票写错一个字怎么办 普票税率开错了怎么办 税率开错为17了怎么办 电子发票抬头错了怎么办 发票抬头错了一个字怎么办 5月税率开错了怎么办 如果发票是假的怎么办 发票收款人名字写错了怎么办 医院发票名字写错了怎么办 购买方发票联丢失怎么办 市中区超市办理发票怎么办 发票购买薄丢了怎么办 发票领用簿丢了怎么办 摩托车证扣12分怎么办 初中孩孑想扩展单词量怎么办 恒安保险倒闭了怎么办 小麦收割机卸粮筒总是转怎么办 非牛顿体结块了怎么办 非牛顿流体硬了怎么办 玩具枪子弹打到眼睛怎么办 杭州磨床7130噪音大怎么办 步兵太苦还有一年怎么办 检法事业编怎么办最新 河北省事业单位改企编制怎么办 梦飞去虎牙锐雯怎么办 蚂蚁借呗还款钱没到账怎么办 蚂蚁借呗没有按时还款怎么办 新装的win7没有网卡驱动怎么办 3d电影没眼睛怎么办 看vr手机发烫变卡怎么办 vr眼镜头晕想吐怎么办 程序员年龄大了失业怎么办 事业人员编制在机关任职改革怎么办 老公出轨死不承认怎么办 2017年军自考毕业证怎么办 大腿酸痛肌肉萎缩怎么办一