〜MRTGで状態把握〜

MRTGについて

CPU、ネットワーク、メモリ、HDD空き容量などの状態をグラフで視覚的に表すもの。
どれくらいの負荷がかかっているかの統計を取ることが出来ます。
ここではCPU、ネットワーク、メモリの3通り。

SNMPのインストール
MRTGはSNMPデーモンに依存しているので、こやつを先にインストールします。
SourceForgetからnet-snmp-5.1.2.tar.gzをDLします
RPMもあるのですが、うまく動かないときがあったので今回はソースパッケージを使います
$ tar xvzf net-snmp-5.1.2.tar.gz
$ cd net-snmp-5.1.2
$ ./configure
  :
  :
$ make
($ su
) # make install
./configureの途中でSNMPのバージョンを一番最初に問われるのでv2と入力し、
あとは全てEnterですっ飛ばします。

SNMP設定
デーモンの設定を行います

デフォルトの設定をコピーして、編集します。
編集すべき部分を黄色で示しますので、変更してください。
# cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf # 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 private
#com2sec mynetwork NETWORK/24 COMMUNITY

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

# sec.model sec.name
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local

group MyROGroup v1 local
group MyROGroup v2c local
group MyROGroup usm local

####
# 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 MyROGroup "" any noauth exact all none none
access MyRWGroup "" 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 Right here, right now.
syscontact admin <admin@server.jp>
一番下に書いたsyscontactは各自、管理用のユーザ・アドレスに置き換えてください。

SNMPの起動
面倒ですが次の文章を「/etc/rc.d/init.d/snmpd」として保存してください。
/etc/rc.d/init.d/snmpd

権限とサーバの起動と同時にロードするためのコマンド
# cd /etc/rc.d/init.d
# chmod 755 snmpd
# chkconfig --add snmpd
# chkconfig --level 2345 snmpd on
# /etc/rc.d/init.d/snmpd start

MRTGのインストール
ここから本体をDLします。
このまま、普段の要領でインストールする訳ですが、ちょこっと環境変数を指定してあげます
$ tar xzvf mrtg-2.10.15.tar.gz $ cd mrtg-2.10.15 $ LDFLAGS=-lVFlib2 ./configure $ make ($ su) # make install

MRTGの設定
ネット上にいろいろありましたが環境のあわないものもありますので
ネットワーク、CPU、メモリを表示する設定ファイルのサンプルを書きます。
また、表示に使う画像類を出すために以下のコマンドを。
# mkdir /home/httpd/html/mrtg
# cp images /home/httpd/html/mrtg

基本的にそのままコピーして使えます。
主な変更箇所は
 ・「SetEnv」の192.168.0.2をサーバのIPに
 ・MaxBytes1[memory]: 45808
  MaxBytes2[memory]: 196552
  実メモリとSWAPは「free」とコマンドをうつと出てくるので当てはめてください

   ページタイトルなどは自由に変更してOKです。

試しに実行してみます
# /usr/local/mrtg-2/bin/mrtg /usr/local/bin/mrtg.cfg
3回ほどWARNINGで「リネームできない」とか「過去の結果を読み込めない」とか言われますが無視してください。

次に、1個1個に参照がめんどいのでindex化します
# /usr/local/mrtg-2/bin/indexmaker mrtg.cfg >> /home/httpd/html/mrtg/index.html
これで http://localhost/mrtgですべての情報を一括で見れるようになります。

あとは、定期的にデータを収集するようにCronに追記して完成!
# vi /etc/crontab
0-59/5 * * * * root /usr/local/bin/mrtg-2/bin/mrtg /usr/local/bin/mrtg.cfg


Linuxサーバへ戻る


Copyright(C)2002-06.Suzuaki All Rights Reserved.
情報の無断転載・直リンクはご遠慮下さい
(リンクする場合はTOPページにお願いします。)