Muninのインストール

Muninはリソースをモニタリングするツールです。
各リソースをグラフ化して見ることができます。
ここでは、CentOS6にインストールします。

1. rrdtoolのインストール

rrdtoolがインストールされていない場合にはインストールします。
# yum install rrdtool rrdtool-devel

2. Muninのインストール

(1) Muninのインストール
「munin」および「munin-node」をパッケージでインストールします。
epelリポジトリにありますので、もしepelリポジトリを追加登録していない場合には、先にyumのリポジトリの追加登録方法(CentOS 6)を実行して下さい。
# yum --enablerepo=epel install munin munin-node

ここで、プログラムファイルの他に
HTML関連ファイル /var/www/html/numin
CGIファイル /var/www/cgi-bin
Apache用Munin設定ファイル /etc/httpd/conf.d/munin.conf
にインストールされます。
ドキュメントルートが異なる場合等、環境に合わせてディレクトリ・ファイルを移動したり、Apacheで設定を行って下さい。

(2) munin.confの編集
「/etc/munin/munin.conf」がMuninのサーバの設定ファイルです。
環境に合わせて設定を行います。
# vi /etc/munin/munin.conf

■htmldir
MuninのWEBサイトのディレクトリ名です。
htmldir /var/www/html/munin
■cgiurl_graph
Muninのグラフを出力するCGIのURLです。
cgiurl_graph /munin-cgi/munin-cgi-graph



3. Apacheの設定

(1) munin.confの編集
「/etc/httpd/conf.d/munin.conf」にApacheの設定ファイルがインストールされています。

# 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/www/html/munin) must have "AllowOverride all" or something close
# to that set.
#
# As a config file enclose it in <directory> like so:
#
<directory /var/www/html/munin>
 
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
require valid-user
 
# This next part requires mod_expires to be enabled.
#
# We could use <IfModule mod_expires> around here, but I want it to be
# as evident as possible that you either have to load mod_expires _or_
# you coment out/remove these lines.

# Set the default expiery time for files 5 minutes 10 seconds from
# their creation (modification) time.  There are probably new files by
# that time.

ExpiresActive On
ExpiresDefault M310
 
</directory>
ScriptAlias /munin-cgi/munin-cgi-graph /var/www/cgi-bin/munin-cgi-graph

■ドキュメントルートやCGIディレクトリを変更する場合
【例】ドキュメントルートおよびCGIディレクトリを「/usr/local/munin」に変更する場合
Alias /munin "/usr/local/munin"
<directory /usr/local/munin>
 
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from xx.xx.xx.xx
 
・・・・
 
</directory>
ScriptAlias /munin-cgi/munin-cgi-graph /usr/local/munin/munin-cgi-graph
※上記では、不特定多数からMuninのWEBサイトを見られることを防ぐため
Allow from xx.xx.xx.xx
でIP制限をしています。

■Basic認証の設定
munin.confではが以下のように設定されています。
AuthUserFile /etc/munin/munin-htpasswd
AuthName "Munin"
AuthType Basic
require valid-user

パスワードファイルは「/etc/munin/munin-htpasswd」ですので、ここにユーザ名およびパスワードを書き込みます。
ユーザ名は任意ですが、ここでは「muninadmin」としておきます。
# /usr/bin/htpasswd -bcm /etc/munin/munin-htpasswd muninadmin (パスワード)

(2) httpd.confの編集
「/etc/httpd/conf/httpd.conf」の編集を行います。
■mod_status
コメントされている場合はコメントを外します。
LoadModule status_module modules/mod_status.so

■mod_expires
コメントされている場合はコメントを外します。
LoadModule expires_module modules/mod_expires.so

■ExtendedStatus
有効にします。
ExtendedStatus On

■server-status
コメントを外してローカルホストのみアクセスを許可します。
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    #Allow from .example.com
    Allow from 127.0.0.1
</Location>

(3) Apacheの再起動
変更を反映させます。
# service httpd restart

4. Muninの監視項目の追加

(1) Apacheプラグイン
(a)シンボリックリンクを追加します。
# ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/
# ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/
# ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/

(2) MySQLプラグイン
(a)シンボリックリンクを追加します。
# ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
# ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/mysql_queries
# ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/mysql_slowqueries
# ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_threads
# ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_innodb
(b)DBおよびユーザの作成
MySQLにログインします。
# mysql -u root -p

DBおよびユーザを作成します。
mysql>
CREATE DATABASE munin;
GRANT SELECT ON munin.* TO munin@localhost IDENTIFIED BY '(password)';
exit
(c)munin-nodeの編集
「/etc/munin/plugin-conf.d/munin-node」を編集します。
# vi /etc/munin/plugin-conf.d/munin-node

以下の設定を追加します。
[mysql*]
env.mysqlconnection DBI:mysql:munin;host=localhost;port=3306
env.mysqluser munin
env.mysqlpassword (Password)
※(Password)にユーザ「munin」のパスワードを記載して下さい。

(3) シンボリックリンクの自動設定
ちなみに、以下のコマンドを実行すると、有効となっているプラグインに対して自動的にシンボリックリンクが作成されます。
/usr/sbin/munin-node-configure --shell | sh

4. munin-nodeの設定

muninの監視対象のクライアントの設定を行います。

(1) munin-node.confの編集
「/etc/munin/munin-node.conf」を編集します。
# vi /etc/munin/munin-node.conf

■host_name
監視対象のクライアントのホスト名を指定します。
#host_name localhost.localdomain
host_name www.xxxxxxx.jp

■allow
監視対象のIPアドレスを正規表現で指定します。
デフォルトはローカルホストです。
allow ^127\.0\.0\.1$
他に監視対象があれば、同様にIPアドレスを追加します。

(2) munin-nodeの起動
「munin-node」を起動します。
# /etc/init.d/munin-node start
5~10分位するとグラフが表示されてきます。

※すぐにグラフを作成させる場合には、以下のコマンドを実行します。
# su - munin --shell=/usr/bin/munin-cron

また、サーバ起動時に自動起動設定を行います。
# cd /etc/init.d
# chkconfig munin-node on

(3) 監視対象のpluginの状況確認
プラグインの状況を確認します。
# /usr/sbin/munin-node-configure --suggest

これで、組み込まれているプラグインやエラー等が出ていないかどうかを確認して下さい。


5. グラフの表示

http://(サーバのドメイン名)/munin/
※munin-nodeを起動してすぐに実行すると、404エラーが表示される場合があります。その場合にはしばらく待って再度実行して下さい。


最終更新:2014年04月28日 17:12