2017年5月25日 星期四

在 CentOS 7 / RHEL 7上,安裝 SNMP 服務

學習目標:
  • 安裝 SNMP 服務,以利系統監控!
操作流程:
  1. 系統安裝相關套件:
    # yum install net-snmp net-snmp-utils
    
  2. 修改設定檔內容:
    # mv /etc/snmp/snmp.conf /etc/snmp/snmp.org
    # vim /etc/snmp/snmp.conf
    com2sec local            localhost       public
    com2sec localnet         192.168.0.0/16  public  (public建議修改為其他的帳號)
    
    group   MyRWGroup v1            local
    group   MyROGroup v1            localnet
    
    group   MyROSystem v1           local
    group   MyROSystem v2c          local
    group   MyROSystem usm          local
    
    group   MyROGroup v1            localnet
    group   MyROGroup v2c           localnet
    group   MyROGroup usm           localnet
    
    group   MyRWGroup v1            local
    group   MyRWGroup v2c           local
    group   MyRWGroup usm           local
    
    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  MyROGroup ""      any       noauth    prefix  all none none
    access  MyRWGroup ""      any       noauth    prefix  all all  all
    
    # 位置及裝置資訊
    sysName monitor_server1  (主機裝置名稱)
    syslocation Taiwan_Taipei_IDC   (所在位置資訊)
    syscontact lubida@hiname.net (聯絡人資訊)
    
  3. 處理一下 SELinux 的限制:
    # chcon --reference=snmpd.org snmpd.conf
    
  4. 開啟防火牆設定:
    # firewall-cmd --permanent --add-port=161/udp
    # firewall-cmd --reload
    
  5. 啟動 SNMP 服務:
    # systemctl start snmpd.service
    # systemctl enable snmpd.service
    # systemctl status snmpd.service
    
  6. 利用指令,查詢一下 snmp 是否有正常輸出資料:
    # netstat -auntp | grep snmp
    # snmpwalk -c public -v 2c 192.168.0.1 
    

參考文獻:
  • http://blog.jangmt.com/2015/09/centos-7-snmpd-centos-7-snmp-install.html
  • http://blog.ilc.edu.tw/blog/index.php?op=printView&articleId=650585&blogId=25793
  • https://www.svennd.be/how-to-install-snmp-service-on-centos-7-2/