前提
ubuntu 和centos 上安裝配置snmp 有些差異;
記錄下過程
版本信息 : Ubuntu 14.04.4 LTS
安裝
sudo apt-get install snmpd 這里安裝的還是和centos上有區(qū)別的。
安裝后執(zhí)行snmpd -v
NET-SNMP version: 5.7.2
Web: http://www./
Email: net-snmp-coders@lists.sourceforge.net
表明安裝成功。
如果要使用snmpwalk 這個命令也需要安裝一下
執(zhí)行安裝 apt-get install snmp
執(zhí)行查看snmpwalk -V
NET-SNMP version: 5.7.2
這樣就完成了安裝。
配置
首先測試下能夠使用snmpwalk
snmpwalk -v 2c -c public localhost 1.3.6.1.2.1.1.1
可能會提示如下
Timeout: No Response from localhost
請確保snmp 服務已開啟
service snmpd status
service snmpd start
如果需要更多的信息,則需要進一步配置。
vim /etc/snmp/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
#
###############################################################################
Ubuntu 上的配置如同上圖注意和centos的配置文件不同.
配置外網(wǎng)訪問
在15行左右,將agentAddress udp:127.0.0.1:161注釋掉
在17行左右,將agentAddress udp:161,udp6:[::1]:161取消注釋
這樣可以我們在別的計算機上通過命令查看,而不是只能通過本地訪問。
可以我發(fā)現(xiàn)這樣配置后查看snmpd的狀態(tài)發(fā)現(xiàn)總是snmpd is not running。
經(jīng)過一番查找發(fā)現(xiàn)是ipv6 的問題。
因為默認的該版本的ubuntu是沒有開啟ipv6的。
查看版本是否開啟了ipv6
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
如果是1則關(guān)閉,如果顯示是0則是開啟的。
我的ubuntu14則沒有開啟,為此有兩種辦法解決。
1.不配置snmp的ipv6,只是用ipv4
2.配置ubuntu使之支持ipv6
方法一:
只配置agentAddress udp:161即可。
重啟snmpd 沒有問題。
方法二:
我沒有試試 ,如果有需求的看wiki https://wiki./IPv6
配置更多的信息項目
在大約48行左右,注釋掉
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
這里原來的配置只允許讓問兩個信息,改成.1后可以看到更多的信息。
配置mib
這個mib我沒有仔細的研究,但是他是提高snmp可閱讀性的一種方法。更直觀。
此時注意修改的是snmp 客戶端配置
vim /etc/snmp/snmp.conf
把mib:這行注釋掉
執(zhí)行snmpwalk 出錯
Cannot adopt OID in NET-SNMP-AGENT-MIB
出現(xiàn)了大量的以上錯誤。原因是本地沒有映射表(我自己起的名字,就是沒有一個對照的文件)
apt-get install snmp
apt-get install snmp-mibs-downloader
在執(zhí)行命令就沒問題了。
配置“密碼”
很多教程叫做共同體,他的作用就是約定一個類似密碼的東西,如果你不知道,就不能通過snmp 獲得系統(tǒng)的數(shù)據(jù)。
上文中 -c public 中的public 就是“密碼”
rocommunity public default -V systemonly
中的public 可以改成任意的,如改成 test.
你再次通過
snmpwalk -v 2c -c public localhost 1.3.6.1.2.1.1.1
就無法獲得信息。
snmpwalk -v 2c -c test localhost 1.3.6.1.2.1.1.1
才能獲取到信息
還有一個貫穿全文的 -v 2c 指的是snmp的版本。為什么是2c,而不是2.這里也不用糾結(jié),只是一種約定。
至此,ubuntu上的安裝配置就完成了。
如果你在配置的時候遇到問題,歡迎討論。
參考資料
[1].https:///questions/440285/why-does-snmp-fail-to-use-its-own-mibs
[2].http://www./Linux/2016-03/129618.htm
|