Python 开发环境搭建(5):SNMP

使用的系统为Redhat 7.6 的64位,使用Net-SNMP 5.7版本

  1. 安装mysql包
    rpm -ivh mysql-community-libs-compat*
    不安装这个包会出现如下报错
    在这里插入图片描述
  2. 安装
    cd /mnt/Packages
    rpm -ivh net-snmp
    yum install -y net-snmp-perl
    yum install -y net-snmp-utils
    yum install -y net-snmp-devel
    yum install -y net-snmp-lib
    
  3. 验证
    可以使用下面的命令去验证你是否成功安装了Net-SNMP,如果你可以获取到正确的版本号,说明你已经成功安装了Net-SNMP
    snmpget --version
    在这里插入图片描述
  4. 配置snmpd.conf
    vi /etc/snmp/snmpd.conf
    ###############################################################################
    # Access Control
    ###############################################################################
    # First, map the community name "public" into a "security name"
    #       sec.name  source          community
    com2sec notConfigUser  default       public
    # Second, map the security name into a group name:
    #       groupName      securityModel securityName
    group   notConfigGroup v1           notConfigUser
    group   notConfigGroup v2c           notConfigUser
    # Third, create a view for us to let the group have rights to:
    # Make at least  snmpwalk -v 1 localhost -c public system fast again.
    #       name           incl/excl     subtree         mask(optional)
    #view    systemview    included   .1.3.6.1.2.1.1
    #view    systemview    included   .1.3.6.1.2.1.25.1.1
    # Finally, grant the group read-only access to the systemview view.
    #       group          context sec.model sec.level prefix read   write  notif
    access  notConfigGroup ""      any       noauth    exact  all none none
    # -----------------------------------------------------------------------------
    # YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
    # KNOWN AT YOUR SITE.  YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
    # SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.
    ##           incl/excl subtree                          mask
    view all    included  .1                               80
    ###############################################################################
    # System contact information
    #
    # It is also possible to set the sysContact and sysLocation system
    # variables through the snmpd.conf file:
    syslocation Unknown (edit /etc/snmp/snmpd.conf)
    syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
    ###############################################################################
    # Logging
    #
    # We do not want annoying "Connection from UDP: " messages in syslog.
    # If the following option is commented out, snmpd will print each incoming
    # connection, which can be useful for debugging.
    dontLogTCPWrappersConnects yes
    ###############################################################################
    com2sec notConfigUser  localhost Server_pu
    
  5. 运行snmpd 且开机自启动
    chkconfig snmpd on
    systemctl start snmp
    
  6. 可通过如下命令检查snmpd是否启动
    netstat -na | grep 161
    在这里插入图片描述

    ps aux | grep snmp
    在这里插入图片描述
  7. 测试snmpd
    可以用如下的几个命令获取系统开机时间,如果有正确的返回则说明snmp运行正常
    snmpwalk -v 2c -c public localhost sysUpTime.0
    在这里插入图片描述

配置python获取netsnmp

pip install client
pip install python3-netsnmp

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值