サーバー監視 · 2 min read · Oct 15, 2025
Debian Wheezy における munin と monit を使用したサーバー監視
Debian Wheezy における munin と monit を使用したサーバー監視
Version 1.0
Author: Falko Timme
Follow me on Twitter
この記事では、Debian Wheezy サーバーを munin と monit で監視する方法を説明します。munin は、サーバーのほぼすべての側面(負荷平均、メモリ使用量、CPU 使用量、MySQL スループット、eth0 トラフィックなど)に関する素晴らしいグラフィックスを、あまり設定せずに生成します。一方、monit は Apache、MySQL、Postfix などのサービスの可用性をチェックし、サービスが期待通りに動作していない場合は再起動などの適切なアクションを取ります。この二つの組み合わせにより、現在または今後の問題(「すぐにより大きなサーバーが必要です。負荷平均が急速に増加しています。」)を認識できるグラフィックスと、監視対象サービスの可用性を確保する watchdog が得られます。
munin は複数のサーバーを監視できますが、ここではインストールされているシステムの監視についてのみ説明します。
このチュートリアルは Debian Wheezy 用に書かれましたが、設定は他のディストリビューションにも少しの変更で適用できるはずです。
まず最初に、これはそのようなシステムを設定する唯一の方法ではないことを言いたいです。この目標を達成する方法はたくさんありますが、これは私が取る方法です。これがあなたにとって機能することを保証するものではありません!
1 予備ノート
私たちのシステムのホスト名は server1.example.com で、ドキュメントルート /var/www/www.example.com/web を持つウェブサイト www.example.com がそれにあります。
2 munin のインストールと設定
Debian Wheezy に munin をインストールするには、次のようにします:
apt-get install munin munin-node munin-plugins-extraいくつかの追加の munin プラグインを有効にします:
cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/mysql_ mysql_
ln -s /usr/share/munin/plugins/mysql_bytes mysql_bytes
ln -s /usr/share/munin/plugins/mysql_innodb mysql_innodb
ln -s /usr/share/munin/plugins/mysql_isam_space_ mysql_isam_space_
ln -s /usr/share/munin/plugins/mysql_queries mysql_queries
ln -s /usr/share/munin/plugins/mysql_slowqueries mysql_slowqueries
ln -s /usr/share/munin/plugins/mysql_threads mysql_threads次に、munin 設定ファイル /etc/munin/munin.conf を編集する必要があります。dbdir、htmldir、logdir、rundir、tmpldir の行のコメントを外します(デフォルト値は問題ありません)。munin に HTML 出力で localhost.localdomain の代わりに server1.example.com を使用させたいので、シンプルなホストツリーセクションで 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 # Where to look for the static www files # #staticdir /etc/munin/static # temporary cgi files are here. note that it has to be writable by # the cgi user (usually nobody or httpd). # # cgitmpdir /var/lib/munin/cgi-tmp # (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)。
localhost 127.0.0.0/8 ::1 からのアクセスを許可する行をコメントアウトし、代わりに Allow from all を追加してください(そうしないと、localhost からのみ munin 出力にアクセスできるようになります):
vi /etc/apache2/conf.d/munin| # Enable this for template generation Alias /munin /var/cache/munin/www # Enable this for cgi-based templates #Alias /munin-cgi/static /var/cache/munin/www/static #ScriptAlias /munin-cgi /usr/lib/munin/cgi/munin-cgi-html # |
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 adminadmin のパスワードを入力します。次に、再度 /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新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。