サーバー監視 · 1 min read · Oct 15, 2025

Debian Squeezeでのmuninとmonitによるサーバー監視

Debian Squeezeでのmuninとmonitによるサーバー監視

バージョン 1.0
著者: Falko Timme
Twitterでフォローしてください

この記事では、Debian Squeezeサーバーをmuninとmonitで監視する方法を説明します。muninは、サーバーのほぼすべての側面(負荷平均、メモリ使用量、CPU使用量、MySQLスループット、eth0トラフィックなど)について、あまり設定をせずに素晴らしいグラフィックを生成します。一方、monitはApache、MySQL、Postfixなどのサービスの可用性をチェックし、サービスが期待通りに動作していない場合は再起動などの適切なアクションを取ります。この2つの組み合わせにより、現在または今後の問題を認識できるグラフィック(「すぐに大きなサーバーが必要です、負荷平均が急速に増加しています。」など)と、監視されたサービスの可用性を確保するウォッチドッグが得られます。

muninは複数のサーバーを監視できますが、ここではインストールされているシステムの監視についてのみ説明します。

このチュートリアルはDebian Squeeze用に書かれましたが、設定は他のディストリビューションにも少しの変更で適用できるはずです。

まず最初に、これはそのようなシステムを設定する唯一の方法ではないことを言いたいです。この目標を達成する方法はたくさんありますが、これは私が取る方法です。これがあなたにとって機能するという保証はありません!

1 前提条件

私たちのシステムのホスト名はserver1.example.comであり、ドキュメントルートが/var/www/www.example.com/webのウェブサイトwww.example.comがあります。

2 muninのインストールと設定

Debian Squeezeにmuninをインストールするには、次のようにします:

apt-get install munin munin-node munin-plugins-extra

次に、muninの設定ファイル/etc/munin/munin.confを編集する必要があります。dbdir、htmldir、logdir、rundir、tmpldirの行のコメントを外します(デフォルト値は問題ありません)。HTML出力でlocalhost.localdomainの代わりにserver1.example.comを使用するようにmuninに指示するため、シンプルなホストツリーセクションでlocalhost.localdomainをserver1.example.comに置き換えます。コメントを外した後、変更されたファイルは次のようになります:

vi /etc/munin/munin.conf

| # Example configuration file for Munin, generated by 'make build' # The next three variables specifies where the location of the RRD # databases, the HTML output, logs and the lock/pid files. They all # must be writable by the user running munin-cron. They are all # defaulted to the values you see here. # dbdir /var/lib/munin htmldir /var/cache/munin/www logdir /var/log/munin rundir /var/run/munin # # Where to look for the HTML templates tmpldir /etc/munin/templates # (Exactly one) directory to include all files from. # includedir /etc/munin/munin-conf.d [...] # a simple host tree [server1.example.com] address 127.0.0.1 use_node_name yes [...] |

muninのためのApache設定ファイル/etc/apache2/conf.d/munin(実際には/etc/munin/apache.confへのシンボリックリンク)を見つける必要があります。これは、muninのHTML出力ディレクトリ/var/cache/munin/wwwにmuninというエイリアスを定義しており、これによりこのサーバー上のすべてのウェブサイトから相対パス/munin(例:http://www.example.com/munin)を使用してmuninにアクセスできます。

localhost 127.0.0.0/8 ::1からのAllowの行をコメントアウトし、代わりにすべてのAllowを使用するようにしてください(そうしないと、localhostからのみmuninの出力にアクセスできるようになります):

vi /etc/apache2/conf.d/munin

| Alias /munin /var/cache/munin/www Order allow,deny Allow from all #Allow from localhost 127.0.0.0/8 ::1 Options None # This file can be used as a .htaccess file, or a part of your apache # config file. # # For the .htaccess file option to work the munin www directory # (/var/cache/munin/www) must have "AllowOverride all" or something # close to that set. # # AuthUserFile /etc/munin/munin-htpasswd # AuthName "Munin" # AuthType Basic # require valid-user # This next part requires mod_expires to be enabled. # # Set the default expiration time for files to 5 minutes 10 seconds from # their creation (modification) time. There are probably new files by # that time. # ExpiresActive On ExpiresDefault M310 |

Apacheを再起動します:

/etc/init.d/apache2 restart

次に、muninを再起動します:

/etc/init.d/munin-node restart

数分待って、muninが最初の出力を生成できるようにし、その後ブラウザでhttp://www.example.com/munin/にアクセスすると、最初の統計が表示されます。数日後には、次のように見えるかもしれません:

(これはmuninが生成する多くのグラフィックの小さな抜粋に過ぎません…)

3 munin出力ディレクトリのパスワード保護(オプション)

すべての人がサーバーのすべての小さな統計を見られるようにしたくない場合は、munin出力ディレクトリをパスワードで保護することをお勧めします。

これを行うには、パスワードファイル/etc/munin/munin-htpasswdを作成する必要があります。ユーザー名adminでログインしたいので、次のようにします:

htpasswd -c /etc/munin/munin-htpasswd admin

adminのパスワードを入力します。次に、再度/etc/apache2/conf.d/muninを開きます…

vi /etc/apache2/conf.d/munin

… そして次のセクションのコメントを外します:

| [...] AuthUserFile /etc/munin/munin-htpasswd AuthName "Munin" AuthType Basic require valid-user [...] |

その後、Apacheを再起動します:

/etc/init.d/apache2 restart
Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。