■ MRTGについて
CPU、ネットワーク、メモリ、HDD空き容量などの状態をグラフで視覚的に表すもの。■SNMPのインストール
どれくらいの負荷がかかっているかの統計を取ることが出来ます。
ここではCPU、ネットワーク、メモリの3通り。
MRTGはSNMPデーモンに依存しているので、こやつを先にインストールします。■ SNMP設定
SourceForgetからnet-snmp-5.1.2.tar.gzをDLします
RPMもあるのですが、うまく動かないときがあったので今回はソースパッケージを使います
./configureの途中でSNMPのバージョンを一番最初に問われるのでv2と入力し、
$ tar xvzf net-snmp-5.1.2.tar.gz
$ cd net-snmp-5.1.2
$ ./configure
:
:
$ make
($ su
) # make install
あとは全てEnterですっ飛ばします。
デーモンの設定を行います■SNMPの起動デフォルトの設定をコピーして、編集します。
編集すべき部分を黄色で示しますので、変更してください。
一番下に書いたsyscontactは各自、管理用のユーザ・アドレスに置き換えてください。
# 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>
面倒ですが次の文章を「/etc/rc.d/init.d/snmpd」として保存してください。■MRTGのインストール
⇒/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
ここから本体をDLします。■MRTGの設定
このまま、普段の要領でインストールする訳ですが、ちょこっと環境変数を指定してあげます
$ tar xzvf mrtg-2.10.15.tar.gz $ cd mrtg-2.10.15 $ LDFLAGS=-lVFlib2 ./configure $ make ($ su) # make install
ネット上にいろいろありましたが環境のあわないものもありますので
ネットワーク、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です。
試しに実行してみます
3回ほどWARNINGで「リネームできない」とか「過去の結果を読み込めない」とか言われますが無視してください。
# /usr/local/mrtg-2/bin/mrtg /usr/local/bin/mrtg.cfg 次に、1個1個に参照がめんどいのでindex化します
これで http://localhost/mrtgですべての情報を一括で見れるようになります。
# /usr/local/mrtg-2/bin/indexmaker mrtg.cfg >> /home/httpd/html/mrtg/index.html あとは、定期的にデータを収集するようにCronに追記して完成!
# vi /etc/crontab
0-59/5 * * * * root /usr/local/bin/mrtg-2/bin/mrtg /usr/local/bin/mrtg.cfg