2011-01-13
Net-Snmpv3とMRTG導入(作業メモ)
作業メモです。いつかまとめます。
SNMPv3を導入してみることにした。
v1、v2との違いは
・認証に暗号化がされている
っていうことみたい。
わりとパブリックな使い方を想定しているのでやっぱセキュリティにはこだわりたいたいなーということでv3を使いたい
でもWebを調べてみるけど、どれもv1,v2の物ばかり。
いろいろ試行錯誤しながら記録していきます。
インストールは一緒なので省略
なんか最新の5.6.1はmakeでエラーがでたので、5.5を導入した
cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
で設定ファイルをコピー
設定で大きく違うのはユーザの設定のところらしい
http://www.itmedia.co.jp/enterprise/articles/0705/16/news011_3.html
ここに設定例があるんだけど、せっかくだしEXAMPLEを見ながら考えてみることにする
ユーザーの種類は
・rwuser
・rouser
の2種類がある。
rwuserは読み書き可能
rouserは読みのみ
EXAMPLE.confは
# Full read-only access for SNMPv3
rouser authOnlyUser
# Full write access for encrypted requests
# Remember to activate the 'createUser' lines above
#rwuser authPrivUser priv
# It's no longer typically necessary to use the full 'com2sec/group/access' configuration
# r[ou]user and r[ow]community, together with suitable views, should cover most requirements
こんな感じになってる
Remember to activate 'createUser' lines above
って書いてあるのでそこもみてみる
###############################################################################
#
# SNMPv3 AUTHENTICATION
#
# Note that these particular settings don't actually belong here.
# They should be copied to the file /var/net-snmp/snmpd.conf
# and the passwords changed, before being uncommented in that file *only*.
# Then restart the agent
# createUser authOnlyUser MD5 "remember to change this password"
# createUser authPrivUser SHA "remember to change this one too" DES
# createUser internalUser MD5 "this is only ever used internally, but still change the password"
# If you also change the usernames (which might be sensible),
# then remember to update the other occurances in this example config file to match.
調べてみるとrwuserやrouserを書いただけでは接続できなくて、このcreateUserってのを設定しないといけないぽい
ただいろんなところにみられるのは
createUserの記述は
「/var/net-snmp/snmpd.conf」に書けっていう話。
locateで調べてみたけどnet-snmpなんてフォルダは存在しない。
net-snmpが自動生成するファイルってことなんで、とりあえずv2でいいからsnmpを起動してみることに
confはとりあえず
sysLocation *
syscontact *@*
rwuser snmproot priv
rouser guest priv
として末尾に
# for v2,v1
# readable and writable from only local host
rwcommunity hogeprivate localhost
#read only user
rocommunity hogepublic
こんな感じで追記。
v1,v2についてはあとで消すつもりなので、制限は特に付けなかった
んで起動してみる
/usr/local/sbin/snmpd start
しかしps aux|grep snmpでみてみると起動していないっぽい
http://www.marronkun.net/linux/other/snmpmrtg_000042.html
にあった
/usr/local/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd -a
で実行してみると起動できた
[*]$ snmpget -c hogeprivate -v 1 localhost .1.3.6.1.2.1.1.4.0
SNMPv2-MIB::sysContact.0 = STRING: *@*
と取れていることがわかる
起動スクリプトを
http://www.marronkun.net/linux/other/snmpmrtg_000042.html
からコピペしてつくっておく
このときchmod 744を忘れない
起動してsnmpwalkとか試してしばらくしていると
[*]$ sudo updatedb
[*]$ sudo locate snmpd.conf
(略)
/var/net-snmp/snmpd.conf
できてた!のでこれを編集してv3のアカウントをつくることにする
まずはsnmpdをstopする
/var/net-snmp/snmpd.confの中身は
#
# net-snmp (or ucd-snmp) persistent data file.
#
############################################################################
# STOP STOP STOP STOP STOP STOP STOP STOP STOP
#
# **** DO NOT EDIT THIS FILE ****
#
# STOP STOP STOP STOP STOP STOP STOP STOP STOP
############################################################################
#
# DO NOT STORE CONFIGURATION ENTRIES HERE.
# Please save normal configuration tokens for snmpd in SNMPCONFPATH/snmpd.conf.
# Only "createUser" tokens should be placed here by snmpd administrators.
# (Did I mention: do not edit this file?)
#
まーつまり管理者のcreateUserだけここに書けよ?
他のユーザはコマンドで作れよってことみたい
そのあたりは
http://codezine.jp/article/detail/3028
に書いてありますね
/etc/net-snmp/snmpd.conf に
createUser snmproot MD5 h0geh0ge DES predicti0n |
を追記し
/usr/local/share/snmp/snmpd.confに
rwuser snmproot priv
を書く
(rouserはコメントアウトしました)
んでsnmpdをstart
/etc/net-snmp/snmpd.confのcreateUserが消えて
usmUser 1 3 0x80001f8880d25a525fceaa234d00000000 0x736e6d70726f6f7400 0x736e6d70726f6f7400 NULL .1.3.6.1.6.3.10.1.1.2 0x785f381af364dcef4e05a108ab37c756 .1.\
3.6.1.6.3.10.1.2.2 0x35f4e7f55eb7cdd43e664ab96839933c 0x
と暗号化されている!
[seki@bosho4-ohma ~]$ snmpget -c hogeprivate -v 3 -l authPriv -u snmproot -a MD5 -A h0geh0ge -X predicti0n localhost .1.3.6.1.2.1.1.4.0
SNMPv2-MIB::sysContact.0 = STRING: ohma@ohma.ohma
と暗号化されたユーザでsnmpgetができた!
ユーザ一覧をチェックしてみる
[seki@bosho4-ohma ~]$ snmpwalk -v 2c -c hogeprivate localhost SNMP-USER-BASED-SM-MIB::usmUserStatus
SNMP-USER-BASED-SM-MIB::usmUserStatus."......ZR_..#M...."."snmproot" = INTEGER: active(1)
SNMP-USER-BASED-SM-MIB::usmUserStatus."......ZR_..#M...."."internalUser" = INTEGER: active(1)
したのはなんだろう・・・?
とりあえずおいといてモニタリングの設定に入る
MRTGの導入
とりあえずインストール
wget http://oss.oetiker.ch/mrtg/pub/mrtg.tar.gz
wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
cd gd-2.0.35
インストールミスる
env CPPFLAGS="-I../zlib-1.2.3 -I../libpng-1.2.8" LDFLAGS="-L../zlib-1.2.3 -L../libpng-1.2.8" ./configure --disable-shared \
で環境を整えてやってやる必要があるみたい
参照:http://www.ksknet.net/cat13/zlib_libpng_gd.html
make
sudo make install
./configure --prefix==/usr/local/mrtg-2
make
sudo make install
インストール完了!
MRTGとv3の連携はできなかった><ので普通の設定をば