Personal tools
You are here: Home サーバ設定 MRTG MRTGインストール
Document Actions

MRTGインストール

by tamohiko last modified 2008-05-22 22:56

MRTGのインストール(yum編)

前提条件

net-snmpがインストールされていること!! apacheの設定が終わっていること!!

mrtg インストール(yum)

# yum install -y mrtg
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for mrtg to pack into transaction set.
mrtg-2.10.15-1.i386.rpm 100% |=========================| 914 kB 00:21
---> Package mrtg.i386 0:2.10.15-1 set to be updated
--> Running transaction check
--> Processing Dependency: libgd.so.2 for package: mrtg
--> Processing Dependency: gd for package: mrtg
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for gd to pack into transaction set.
gd-2.0.28-4.4E.1.i386.rpm 100% |=========================| 119 kB 00:05
---> Package gd.i386 0:2.0.28-4.4E.1 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mrtg i386 2.10.15-1 base 914 k
Installing for dependencies:
gd i386 2.0.28-4.4E.1 base 119 k

Transaction Summary
=============================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 1.0 M
Downloading Packages:
(1/2): gd-2.0.28-4.4E.1.i 100% |=========================| 119 kB 00:08
(2/2): mrtg-2.10.15-1.i38 100% |=========================| 914 kB 00:22
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: gd ######################### [1/2]
Installing: mrtg ######################### [2/2]

Installed: mrtg.i386 0:2.10.15-1
Dependency Installed: gd.i386 0:2.0.28-4.4E.1
Complete!

MRTG設定

yumでインストールした場合は以下の場所にMRTGの設定ファイルである /etc/mrtg/mrtg.cfg

mrtg.cfg 作成

MRTGをインストールすると、設定ファイルを作成するためのツールであるcfgmakerも 一緒にインストールされます。これを使用してmrtc.cfgを作成していきます。

# cd /etc/mrtg/
# mv mrtg.cfg mrtg.cfg.org
# cfgmaker --output /etc/mrtg/mrtg.cfg public@localhost
--base: Get Device Info on public@localhost:
--base: Vendor Id:
--base: Populating confcache
--snpo: confcache public@localhost: Descr lo --> 1
--snpo: confcache public@localhost: Descr eth0 --> 2
--snpo: confcache public@localhost: Descr sit0 --> 3
--snpo: confcache public@localhost: Type 24 --> 1
--snpo: confcache public@localhost: Type 6 --> 2
--snpo: confcache public@localhost: Type 131 --> 3
--snpo: confcache public@localhost: Ip 127.0.0.1 --> 1
--snpo: confcache public@localhost: Ip 192.168.153.128 --> 2
--snpo: confcache public@localhost: Eth --> 1
--snpo: confcache public@localhost: Eth 00-0c-29-87-92-9c --> 2
--snpo: confcache public@localhost: Eth --> 3 (duplicate)
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Walking ifSpeed
--base: Writing /etc/mrtg/mrtg.cfg
mrtg.cfg 設定
cfgmakerで作成されたmrtg.cfgを編集します。
# cd /etc/mrtg/
# vi mrtg.cfg
変更箇所
### Global Config Options

# for UNIX
# WorkDir: /home/http/mrtg
WorkDir: /var/www/mrtg ←変更

# or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

# to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits
Options[_]: growright, bits ←変更

EnableIPv6: no

Language:eucjp ←追加

WorkDirectory の作成

mrtgで収集してきたデータや、生成される画像やhtmlファイルを保存するための WorkDirectoryを作成します。
# cd /var/www/
# mkdir mrtg

mrtgの実行

mrtg.cfgの編集と、WorkDirectoryの作成が完了しましたら、いよいよmrtgの起動を行います。
システムの言語がUTF-8の場合

通常ならば/usr/bin/mrtg /etc/mrtg/mrtg.cfg で実行できるのですが、 実行してみると以下のようなエラーが表示されてしまうので、ログに表示されているように env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg コマンドで実行させます。

エラーが表示された・・・
# mrtg /etc/mrtg/mrtg.cfg
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
variable LANG is set to UTF-8. Please run mrtg in an environment
where this is not the case. Try the following command to start:

env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
-----------------------------------------------------------------------

env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfgで実行

MRTGは過去2回分の採取した情報を比較します。ですので情報がない最初の2回はWARNINGが表示されますが問題ないです。

# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_2
Rateup WARNING: /usr/bin/rateup The backup log file for localhost_2 was invalid as well
Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file
Rateup WARNING: /usr/bin/rateup Can't rename localhost_2.log to localhost_2.old updating log file
# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file
# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

動作確認

アクセス制限設定

mrtgをインストールした初期状態では、apacheの設定によりローカルホストからしかアクセスできません。 ですので、/etc/httpd/conf.d/mrtg.conf の設定変更を行います。これを変更しないとローカルホストからの アクセス以外はForbiddenのエラーとなってしまいます。

# cp -p /etc/httpd/conf.d/mrtg.conf /etc/httpd/conf.d/mrtg.conf_org
# vi /etc/httpd/conf.d/mrtg.conf
変更箇所
#
# This configuration file maps the mrtg output (generated daily)
# into the URL space. By default these results are only accessible
# from the local host.
#
Alias /mrtg /var/www/mrtg

<Location /mrtg>
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.0 ←閲覧を許可させたいネットワークを追加
Allow from ALL ←どこからでも閲覧を許可させたい場合
Allow from ::1
# Allow from .example.com
</Location>

index.htmlの作成

indexmaker /etc/mrtg/mrtg.cfg \
--addhead="<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset = euc-jp\">" \
--output /var/www/mrtg/index.html
ブラウザで確認
ブラウザで以下のURLに接続すると、MRTGが収集した情報をもとにしたグラフが表示されるはずです。
http://サーバのIP/mrtg/

文字化け対策

httpd.conf編集

ブラウザで表示したけど文字化けが・・・

Apache2では <META http-equiv=Content-Type content="text/html; charset = euc-jp">といったように META タグで上記のように各ページごとに「charset=」指定してもhttpd.confにて AddDefaultCharset項目でセットされているCharsetが優先されてしまうらしい・・多分。 そこでMETA タグでのcharsetを反映させたい場合、 Apache2.0の設定ファイル「/etc/httpd/conf/httpd.conf」を次のように編集すればよいらしいです。

# vi /etc/httpd/conf/httpd.conf
#AddDefaultCharset UTF-8     ←コメント化
AddDefaultCharset off offを指定する

言語の優先度でjaを一番にする
#LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
LanguagePriority ja en ca cs da de el eo es et fr he hr it ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
設定の再読み込み
# /etc/init.d/httpd reload
これで多分文字化けしなくなるはずです。再度ブラウザで確認してみてください。

MRTG起動

yum でのインストールだと /etc/cron.d/mrtg に自動的に作成されている。 なので、5分ごとに自動的に起動されるようになっています。

 # cat /etc/cron.d/mrtg
*/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok

おまけ

MRTG設定時にはまった箇所

私が失敗した件について
cfgmaker を起動してもdoes not seem to support itのように表示されて上手く設定ファイルが作成されない場合は 以下のことを確認してください。

snmpの設定ファイルであるsnmpd.confでアクセス許可がされているか?
情報を収集するサーバが別セグメントにある場合はsnmpd.confの設定を見直してみてください、ついつい設定するのを忘れていることがあります。

cfgmaker失敗の図
# cfgmaker public@192.168.153.128 --output /etc/mrtg/mrtg.cfg
--base: Get Device Info on public@192.168.153.128:
--base: Vendor Id:
--base: Populating confcache
--snpo: Skipping ifName scanning because public@192.168.153.128: does not seem to support it
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Walking ifSpeed
失敗作のmrtg.cfg
# Created by
# /usr/bin/cfgmaker public@192.168.153.128


### Global Config Options

# for UNIX
# WorkDir: /home/http/mrtg

# or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

# to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no

######################################################################
# System: luna
# Description: Linux luna 2.4.21-20.EL #1 SMP Wed Aug 18 20:34:58 EDT 2004 x86_64
# Contact: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
# Location: Unknown (edit /etc/snmp/snmpd.conf)
######################################################################
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: