Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS SNMP 服務部署與基礎配置實戰教程

編輯:Linux 教學

安裝前確認

rpm -qa | grep snmp
# 典型輸出:
# net-snmp-libs-5.1.2-11.EL4.7
# net-snmp-5.1.2-11.EL4.7

若未安裝,使用 YUM 一鍵部署:

完整安裝指令

yum install -y net-snmp net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils mrtg
  • net-snmp:核心守護程式
  • net-snmp-utils:snmpwalk、snmpget 等客戶端工具
  • net-snmp-devel:開發庫(編譯第三方監控外掛需用)
  • mrtg:流量圖表工具(可選)

服務啟動與狀態檢查

# 先直接執行 snmpd 建立預設配置
snmpd

# 再啟動系統服務
service snmpd start

# 檢查狀態
service snmpd status

常見坑點: 若出現 snmpd dead but pid file exists 或 snmpd dead but subsys locked,必須先手動執行 snmpd 再啟動服務,否則殘留 PID/鎖定檔導致失敗。

核心配置:/etc/snmp/snmpd.conf

# A. 修改 Community String(密碼等效,務必改複雜)
# 原:com2sec notConfigUser default public
com2sec notConfigUser default MySecretCommunityString

# B. 開放 MIB-2 樹(系統資訊、介面統計等)
# 原:#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

# C. 授權 notConfigGroup 讀取 mib2
# 原:access notConfigGroup "" any noauth exact systemview none none
access notConfigGroup "" any noauth exact mib2 none none

重啟生效與測試

/etc/rc.d/init.d/snmpd restart

# 本機測試
snmpwalk -v 2c -c MySecretCommunityString localhost system
snmpget -v 2c -c MySecretCommunityString localhost sysDescr.0

# 遠端測試(需防火牆開放 UDP 161)
snmpwalk -v 2c -c MySecretCommunityString 192.168.1.100 ifDescr

防火牆配置

# iptables 範例
iptables -A INPUT -p udp -s 192.168.1.0/24 --dport 161 -j ACCEPT
service iptables save

# 或 firewalld (CentOS 7+)
firewall-cmd --permanent --add-port=161/udp --zone=public
firewall-cmd --reload

進階:SNMPv3 安全配置(生產環境建議)

# 建立唯讀使用者
net-snmp-create-v3-user -ro -A AuthPass123 -X PrivPass456 -a SHA -x AES snmpuser

# 產生的配置片段加入 snmpd.conf
# createUser snmpuser SHA AuthPass123 AES PrivPass456
# rouser snmpuser authPriv

監控整合建議

  • Zabbix:使用 snmp.get[]、snmp.walk[] 監控介面流量、CPU、記憶體、磁碟
  • Prometheus:部署 snmp_exporter 配合 snmp.yml 產生指標
  • Grafana:匯入 SNMP 儀表板模板(如 10176)
Copyright © Windows教程網 All Rights Reserved