Muninのインストール

サーバリソースを監視しないとなぁということで、パフォーマンスモニタツールを検討してみた。

「Muninが導入楽らしいよ」

ということで、今回は複数ノードを監視するわけでもないし、
ビギナーな自分にぴったりのMuninを入れてみることにした。

Muninのいいところ
  • インストールが楽。
  • プラグインがたくさんある。
  • プラグインのインストールも楽。ダウンロードしてシンボリック作るだけ。
  • デフォルトではSNMPいらず。(/procの下の値を取得してデータをまとめておき、グラフの表示は静的なHTMLを表示するだけらしい。)
Muninのちょっとイケてないとこ
  • 日時を指定してグラフを表示できない。1時間ごと、日ごと、週ごと、月ごとのグラフのみ。これではサーバが落ちる直前とか、ある特定の数分間とか見ることはできない。
スクリーンショット

できあがりはこんな感じ。

  • トップ画面。今はlocalshot一つだけだけど、ノードを増やせば一覧は増える。

  • 1つのノードの情報が1画面にズラっと並ぶ。


  • 一覧からMemory usageをクリックしてメモリの情報のみ1時間ごと、日ごと、週ごと、月ごとのグラフを出したところ。

CentOS4にインストール

Muninは、サーバの情報を集めるノードと、ノードから集めた情報をWebで見れるようにするサーバに分かれている。
今回は両方同じサーバに入れる。

ApachePerlは既に入れている状態で進めていった。ちなみにApacheはソースから入れた。/user/local/apache2。
Munin自体はPerlでできていて、Perlが必要らしい。でもPerlはだいたいデフォルトで入っている、ハズ。

yumにRPMforgeリポジトリを追加する

# wget http://dag.wieers.com/packages/rpmforge-release/rpmforge-release-0.3.6-1.el4.rf.i386.rpm
# rpm -Uhv rpmforge-release-0.3.6-1.el4.rf.i386.rpm

yumコマンドを使うとき、デフォルトではこのリポジトリを有効にしないように設定。

# vi /etc/yum.repos.d/rpmforge.repo
enabled = 0

Muninインストール

 # /usr/sbin/groupadd -g 4949 munin
 # /usr/sbin/useradd -u 4949 -g munin -m -s /bin/false munin
 # yum --enablerepo=rpmforge install munin munin-node
 .....

 =============================================================================
  Package                 Arch       Version          Repository        Size 
 =============================================================================
 Installing:
  munin                   noarch     1.2.5-1rhel4     sakura            120 k
  munin-node              noarch     1.2.5-1rhel4     sakura            152 k
 Installing for dependencies:
  perl-Crypt-DES          i386       2.05-3.2.el4.rf  rpmforge           19 k
  perl-DateManip          noarch     5.42a-3          base              135 k
  perl-HTML-Template      noarch     2.9-1.el4.rf     rpmforge           62 k
  perl-Net-SNMP           noarch     5.2.0-1.2.el4.rf  rpmforge           95 k
  perl-Net-Server         noarch     0.97-1.el4.rf    rpmforge          154 k
  perl-Socket6            i386       0.20-1.el4.rf    rpmforge           48 k
  perl-rrdtool            i386       1.2.23-1.el4.rf  rpmforge           49 k
  rrdtool                 i386       1.2.23-1.el4.rf  rpmforge          917 k
 
 Transaction Summary
 =============================================================================
 Install     10 Package(s)         
 Update       0 Package(s)         
 Remove       0 Package(s)         
 Total download size: 1.7 M
 Is this ok [y/N]: y

ノード起動&自動起動設定

# /etc/init.d/munin-node start
# /sbin/chkconfig munin-node on

ノードの設定

一通りやってから、/var/log/munin/配下のログを確認し、エラーがないようであればログレベルを0にしとくのもよし。
ちなみにログのローテーションは勝手にしてくれるので設定必要なし(しかもtar.gzにしてくれてる親切さ!)。

# vi /etc/munin/munin-node.conf


log_level 0

サーバの設定

# vi /etc/munin/munin.conf

 
#htmldir        /var/www/html/munin
htmldir /home/htdocs/munin

Apacheはパッケージから入れてないので、パッケージデフォルトの場所からMuninのcgiとかcssとかを移動。

# mv /var/www/html/munin /home/htdocs/

munin.confで設定したグループ名でディレクトリを作っておいてあげる必要がある。

# mkdir /home/htdocs/munin/localhost/
# chown -R munin.webgroup /home/htdocs/munin

Apacheの設定。

# vi /usr/local/apache2/conf/httpd.conf
 Alias /munin "/home/htdocs/munin/"
 <Directory "/home/htdocs/munin/">
     AllowOverride AuthConfig FileInfo Limit
     Order allow,deny
     Allow from all
 </Directory>
# /etc/init.d/apache2 restart


ベーシック認証かけとく。

# /usr/local/apache2/bin/htpasswd -c /home/htdocs/munin/.htpasswd munin
# vi /home/htdocs/munin/.htaccess
 AuthType Basic
 AuthUserFile /home/htdocs/munin/.htpasswd
 AuthGroupFile /dev/null
 AuthName "Please Enter Your Password"
 <Limit POST GET>
     require valid-user
 </Limit>

プラグインでグラフを追加

デフォルトでもサーバリソースの情報は十分わかるが、プラグインでさらにいろいろなグラフが描ける。

  • PluginCat – Munin
  • MuninExchangeIsDown – Munin
    • 「Search」のメニューから、どんなプラグインがどんなグラフを描くのかを見ながら探すことができ、その場でプラグインのダウンロードができる。

Apacheの情報をグラフで描いてみる

Apacheのステータスを取得するプラグインは、Muninにデフォルトで入っているので、それを有効にしてあげる。

# cd /etc/munin/plugins/
# ln -s /usr/share/munin/plugins/apache_accesses apache_accesses
# ln -s /usr/share/munin/plugins/apache_processes apache_processes
# ln -s /usr/share/munin/plugins/apache_volume apache_volume

mod_statusを有効にする。

# vi /usr/local/apache2/conf/httpd.conf
 LoadModule status_module modules/mod_status.so
 Include conf/extra/httpd-info.conf

localhostからのみ、ステータス画面を閲覧できるようにする。
server-infoは特に使わないのでコメントアウト。

# vi /usr/local/apache2/conf/extra/httpd-info.conf
 <Location /server-status>
     SetHandler server-status
     Order deny,allow
     Deny from all
 #    Allow from .example.com
     Allow from 127.0.0.1
     Allow from localhost
 </Location>

 ExtendedStatus On

 #<Location /server-info>
 #    SetHandler server-info
 #    Order deny,allow
 #    Deny from all
 #    Allow from .example.com
 # </Location>

Apacheとmunin-nodeを再起動。

# /etc/init.d/apache2 restart
# /etc/init.d/munin-node restart

MySQLの情報をグラフで描いてみる

 # ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
 # ln -s /usr/share/munin/plugins/mysql_isam_space_ /etc/munin/plugins/mysql_isam_space_
 # 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

mysqladminコマンドにパスが通ってないとグラフが表示されないので、確認。

# which mysqladmin

パスが通ってなかったらパスを通すか、munin-nodeに教えてあげる。
今回は、munin-nodeにmysqladminの場所を教えてあげるように設定した。
[mysql*]セクションに書く。

# vi /etc/munin/plugin-conf.d/munin-node


[mysql*]
env.mysqlopts -u root -p<password>
env.mysqladmin /usr/local/mysql/bin/mysqladmin

munin-nodeを再起動。

# /etc/init.d/munin-node restart
MySQLのは、少しだけうまくいかない模様。。。

mysql_isam_space_ でエラーが出てる。
↓以下、munin-node.logより

 Name "main::field" used only once: possible typo at /etc/munin/plugins/mysql_isam_space_ line 216.
 Name "main::ABSOLUTE" used only once: possible typo at /etc/munin/plugins/mysql_isam_space_ line 221.
 Can't exec "mysqlshow": No such file or directory at /etc/munin/plugins/mysql_isam_space_ line 155.
 readline() on closed filehandle IN at /etc/munin/plugins/mysql_isam_space_ line 158.
 Could not open "/var/lib/munin/plugin-state/plugin-mysql_isam_space.state" for writing: Permission denied at /etc/munin/plugins/mysql_isam_space_ line 184.
 2008/10/21-22:10:08 Plugin "mysql_isam_space_" exited with status 256. ----

「main::hoge という名前は、一回しか使われていません。タイプミスの可能性...」というPerlの警告らしい。なのでいいか。

# touch /var/lib/munin/plugin-state/plugin-mysql_isam_space.state
# chmod 666 /var/lib/munin/plugin-state/plugin-mysql_isam_space.state

したらパーミッションのエラーは出なくなったけど、あいかわらず
MySQL "" isam/myisam table-space usage
のグラフは表示されない。。。