snmpによりネットワークのトラフィック量をグラフ化し視覚化できるようにする。

net-snmpの導入(net-mgmt/net-snmp)

portsを使ってインストールした。

snmpdのインストール

http://sakura.take-labo.jp/freebsd/netmgmt_snmp.htmlによるとnet-snmpをインストールする前にmake オプションを /usr/local/etc/pkgtools.conf に指定します。

オプションは複数項目ありますが、とりあえず次の2項目を設定すれば問題ないと思います。 NET_SNMP_SYS_CONTACT には管理者のメールアドレスを、

NET_SNMP_SYS_LOCATION には設置場所、部屋の名前、ネットワーク名などをセットします。

がしかし、やらずにインストールしてもうた。

[root@freebsd]~# vi /usr/local/etc/pkgtools.conf
部分編集 (該当箇所掲載)
MAKE_ARGS = {
'net-mgmt/net-snmp' => 'NET_SNMP_SYS_CONTACT="hostmaster@example.jp" NET_SNMP_SYS_LOCATION="Kanagawa, Japan"',
}

続いて、portinstallを用いてインストール、設定ファイルをコピーする。

[root@freebsd]~# cd /usr/ports
[root@freebsd]/usr/ports# portinstall net-mgmt/net-snmp
[root@freebsd]/usr/ports# cp /usr/local/share/snmp/snmpd.conf.example /usr/local/share/snmp/snmpd.conf

snmpd.confの設定

snmpd.conf では snmp のデータを作成できるホスト、読み取れるホストを指定してアクセス制限をします。 ここでは、グループ Writer (localhost, 127.0.0.1)に snmp データを作成できる権限を、 Reader (192.168.1.0/24) に snmp データを読み取れる権限を与えています。 コミュニティ・ネームはメモリの RAM/ROM に例えて Writer は MACHINE-NAMEram、Reader は MACHINE-NAMErom とします。 MACHINE-NAME とは snmpd を動かすマシンの名前や型番とします。

[root@freebsd] vi /usr/local/share/snmp/snmpd.conf
編集 (全文掲載)
####
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):

#       sec.name   source            community
com2sec local     localhost         MACHINE-NAMEram
com2sec mylan     192.168.1.0/24  MACHINE-NAMErom

####
# Second, map the security names into group names:

#               sec.model  sec.name
group Writer    v1         local
group Writer    v2c        local
group Writer    usm        local
group Reader    v1         mylan
group Reader    v2c        mylan
group Reader    usm        mylan

####
# Third, create a view for us to let the groups have rights to:

#           incl/excl subtree                          mask
view all    included  .1                               80

####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:

#                context sec.model sec.level match  read   write  notif
access Reader    ""      any       noauth    exact  all    none   none
access Writer    ""      any       noauth    exact  all    all    none

#---------------------------------------------------------------------- --


###################################################################
# System contact information
#

# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file.  **PLEASE NOTE** that setting
# the value of these objects here makes these objects READ-ONLY
# (regardless of any access control settings).  Any attempt to set the
# value of an object whose value is given here will fail with an error
# status of notWritable.

syslocation MY Local Network
syscontact hostmaster <hostmaster@example.jp>

ブート設定

FreeBSD 起動時に自動的に snmpd を有効化するには次の 4行を /etc/rc.conf に追加します。

[root@freebsd]~# vi /etc/rc.conf
追記 (該当箇所掲載)
snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"

/etc/rc.conf 設定直後にマシンをリブートせずに snmpd を実行させるには次の 2つの起動スクリプトを実行します。

[root@freebsd]~# /usr/local/etc/rc.d/snmptrapd.sh start
[root@freebsd]~# /usr/local/etc/rc.d/snmpd.sh start

Last-modified: 2022-05-05 (木) 22:27:10