サーバー監視ツールの導入 (Munin)

サーバーの各リソース使用状況を時系列でグラフにして見ることが可能なサーバー監視ツールの導入を行います。
本サイトでは、MRTGcacti と比べてインストールも設定も圧倒的に簡単な Munin を導入する手順を説明します。

インストール

1. Munin をインストールします。
※インストール後 Cron により 5 分毎に Munin が起動し統計情報が /var/www/html/munin に出力されます。

# yum -y install munin munin-node
Loading "fastestmirror" plugin
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
Excluding Packages in global exclude list
Finished
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for munin to pack into transaction set.
munin-1.2.5-2.fc6.noarch. 100% |=========================|  11 kB    00:00
---> Package munin.noarch 0:1.2.5-2.fc6 set to be updated
---> Downloading header for munin-node to pack into transaction set.
munin-node-1.2.5-2.fc6.no 100% |=========================|  23 kB    00:00
---> Package munin-node.noarch 0:1.2.5-2.fc6 set to be updated
--> Running transaction check
--> Processing Dependency: fedora-usermgmt >= 0.7 for package: munin
--> Processing Dependency: rrdtool for package: munin
--> Processing Dependency: perl-HTML-Template for package: munin
--> Processing Dependency: fedora-usermgmt >= 0.7 for package: munin-node
--> Processing Dependency: perl-Net-Server for package: munin-node
--> Processing Dependency: perl-Net-Server for package: munin
--> Processing Dependency: sysstat for package: munin-node
--> Processing Dependency: perl(RRDs) for package: munin
--> Processing Dependency: perl(Date::Manip) for package: munin
--> Processing Dependency: perl-Net-SNMP for package: munin
--> Processing Dependency: perl(Net::Server::Fork) for package: munin-node
--> Processing Dependency: perl(HTML::Template) for package: munin
--> Processing Dependency: perl(Net::SNMP) for package: munin-node
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-Net-Server to pack into transaction set.
perl-Net-Server-0.94-2.fc 100% |=========================| 9.2 kB    00:00
---> Package perl-Net-Server.noarch 0:0.94-2.fc6 set to be updated
---> Downloading header for rrdtool-perl to pack into transaction set.
rrdtool-perl-1.2.23-3.fc6 100% |=========================| 8.4 kB    00:00
---> Package rrdtool-perl.i386 0:1.2.23-3.fc6 set to be updated
---> Downloading header for perl-Net-SNMP to pack into transaction set.
perl-Net-SNMP-5.2.0-1.fc6 100% |=========================| 7.2 kB    00:00
---> Package perl-Net-SNMP.noarch 0:5.2.0-1.fc6 set to be updated
---> Downloading header for rrdtool to pack into transaction set.
rrdtool-1.2.23-3.fc6.i386 100% |=========================|  12 kB    00:00
---> Package rrdtool.i386 0:1.2.23-3.fc6 set to be updated
---> Downloading header for fedora-usermgmt to pack into transaction set.
fedora-usermgmt-0.9-2.fc6 100% |=========================| 5.5 kB    00:00
---> Package fedora-usermgmt.noarch 0:0.9-2.fc6 set to be updated
---> Downloading header for perl-DateManip to pack into transaction set.
perl-DateManip-5.44-2.fc6 100% |=========================| 3.6 kB    00:00
---> Package perl-DateManip.noarch 0:5.44-2.fc6 set to be updated
---> Downloading header for sysstat to pack into transaction set.
sysstat-7.0.0-4.fc6.i386. 100% |=========================|  14 kB    00:00
---> Package sysstat.i386 0:7.0.0-4.fc6 set to be updated
---> Downloading header for perl-HTML-Template to pack into transaction set.
perl-HTML-Template-2.8-3. 100% |=========================| 4.4 kB    00:00
---> Package perl-HTML-Template.noarch 0:2.8-3.fc6 set to be updated
--> Running transaction check
--> Processing Dependency: perl(IO::Multiplex) for package: perl-Net-Server
--> Processing Dependency: perl(Crypt::DES) for package: perl-Net-SNMP
--> Processing Dependency: setup(fedora-usermgmt) for package: fedora-usermgmt
--> Processing Dependency: fedora-usermgmt-core = 0.9-2.fc6 for package: fedora-usermgmt
--> Processing Dependency: instance(fedora-usermgmt) for package: fedora-usermgmt
--> Processing Dependency: libart_lgpl_2.so.2 for package: rrdtool
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for fedora-usermgmt-shadow-utils to pack into transaction set.
fedora-usermgmt-shadow-ut 100% |=========================| 7.0 kB    00:00
---> Package fedora-usermgmt-shadow-utils.noarch 0:0.9-2.fc6 set to be updated
---> Downloading header for fedora-usermgmt-default-fedora-setup to pack into transaction set.
fedora-usermgmt-default-f 100% |=========================| 6.3 kB    00:00
---> Package fedora-usermgmt-default-fedora-setup.noarch 0:0.9-2.fc6 set to be updated
---> Downloading header for perl-IO-Multiplex to pack into transaction set.
perl-IO-Multiplex-1.08-5. 100% |=========================| 3.3 kB    00:00
---> Package perl-IO-Multiplex.noarch 0:1.08-5.fc6 set to be updated
---> Downloading header for perl-Crypt-DES to pack into transaction set.
perl-Crypt-DES-2.05-3.fc6 100% |=========================| 3.8 kB    00:00
---> Package perl-Crypt-DES.i386 0:2.05-3.fc6 set to be updated
---> Downloading header for fedora-usermgmt-core to pack into transaction set.
fedora-usermgmt-core-0.9- 100% |=========================| 6.1 kB    00:00
---> Package fedora-usermgmt-core.noarch 0:0.9-2.fc6 set to be updated
---> Downloading header for libart_lgpl to pack into transaction set.
libart_lgpl-2.3.17-4.i386 100% |=========================| 5.1 kB    00:00
---> Package libart_lgpl.i386 0:2.3.17-4 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 munin                   noarch     1.2.5-2.fc6      extras            130 k
 munin-node              noarch     1.2.5-2.fc6      extras            172 k
Installing for dependencies:
 fedora-usermgmt         noarch     0.9-2.fc6        extras            6.9 k
 fedora-usermgmt-core    noarch     0.9-2.fc6        extras            7.9 k
 fedora-usermgmt-default-fedora-setup  noarch     0.9-2.fc6        extras            6.8 k
 fedora-usermgmt-shadow-utils  noarch     0.9-2.fc6        extras            7.7 k
 libart_lgpl             i386       2.3.17-4         core               76 k
 perl-Crypt-DES          i386       2.05-3.fc6       extras             18 k
 perl-DateManip          noarch     5.44-2.fc6       updates           143 k
 perl-HTML-Template      noarch     2.8-3.fc6        extras             70 k
 perl-IO-Multiplex       noarch     1.08-5.fc6       extras             20 k
 perl-Net-SNMP           noarch     5.2.0-1.fc6      extras            108 k
 perl-Net-Server         noarch     0.94-2.fc6       extras            145 k
 rrdtool                 i386       1.2.23-3.fc6     extras            464 k
 rrdtool-perl            i386       1.2.23-3.fc6     extras             33 k
 sysstat                 i386       7.0.0-4.fc6      updates           164 k

Transaction Summary
=============================================================================
Install     16 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/16): fedora-usermgmt-s 100% |=========================| 7.7 kB    00:00
(2/16): fedora-usermgmt-d 100% |=========================| 6.8 kB    00:00
(3/16): perl-IO-Multiplex 100% |=========================|  20 kB    00:00
(4/16): perl-Net-Server-0 100% |=========================| 145 kB    00:00
(5/16): rrdtool-perl-1.2. 100% |=========================|  33 kB    00:00
(6/16): perl-Net-SNMP-5.2 100% |=========================| 108 kB    00:00
(7/16): rrdtool-1.2.23-3. 100% |=========================| 464 kB    00:00
(8/16): perl-Crypt-DES-2. 100% |=========================|  18 kB    00:00
(9/16): fedora-usermgmt-0 100% |=========================| 6.9 kB    00:00
(10/16): perl-DateManip-5 100% |=========================| 143 kB    00:00
(11/16): munin-node-1.2.5 100% |=========================| 172 kB    00:00
(12/16): fedora-usermgmt- 100% |=========================| 7.9 kB    00:00
(13/16): sysstat-7.0.0-4. 100% |=========================| 164 kB    00:00
(14/16): munin-1.2.5-2.fc 100% |=========================| 130 kB    00:00
(15/16): libart_lgpl-2.3. 100% |=========================|  76 kB    00:00
(16/16): perl-HTML-Templa 100% |=========================|  70 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: perl-HTML-Template           ####################### [ 1/16]
  Installing: libart_lgpl                  ####################### [ 2/16]
  Installing: rrdtool                      ####################### [ 3/16]
  Installing: rrdtool-perl                 ####################### [ 4/16]
  Installing: sysstat                      ####################### [ 5/16]
  Installing: perl-DateManip               ####################### [ 6/16]
  Installing: perl-Crypt-DES               ####################### [ 7/16]
  Installing: perl-Net-SNMP                ####################### [ 8/16]
  Installing: perl-IO-Multiplex            ####################### [ 9/16]
  Installing: perl-Net-Server              ####################### [10/16]
  Installing: fedora-usermgmt-default-fedo ####################### [11/16]
  Installing: fedora-usermgmt-core         ####################### [12/16]
  Installing: fedora-usermgmt-shadow-utils ####################### [13/16]
  Installing: fedora-usermgmt              ####################### [14/16]
  Installing: munin-node                   ####################### [15/16]
  Installing: munin                        ####################### [16/16]

Installed: munin.noarch 0:1.2.5-2.fc6 munin-node.noarch 0:1.2.5-2.fc6
Dependency Installed: fedora-usermgmt.noarch 0:0.9-2.fc6 fedora-usermgmt-core.noarch 0:0.9-2.fc6 fedora-use
rmgmt-default-fedora-setup.noarch 0:0.9-2.fc6 fedora-usermgmt-shadow-utils.noarch 0:0.9-2.fc6 libart_lgpl.i
386 0:2.3.17-4 perl-Crypt-DES.i386 0:2.05-3.fc6 perl-DateManip.noarch 0:5.44-2.fc6 perl-HTML-Template.noarc
h 0:2.8-3.fc6 perl-IO-Multiplex.noarch 0:1.08-5.fc6 perl-Net-SNMP.noarch 0:5.2.0-1.fc6 perl-Net-Server.noar
ch 0:0.94-2.fc6 rrdtool.i386 0:1.2.23-3.fc6 rrdtool-perl.i386 0:1.2.23-3.fc6 sysstat.i386 0:7.0.0-4.fc6
Complete!

設定

2. デフォルトだと誰でも Munin の統計情報にアクセスできてしまうので、Munin 用の Apache 設定ファイルを作成して、LAN 環境からのみアクセス可能とします。

# vi /etc/httpd/conf.d/munin.conf
<Directory /var/www/html/munin>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 192.168.11
</Directory>

3. Apache の設定変更に間違いがないか検証します。

# apachectl configtest
Syntax OK

4. Apache 設定を再読み込みします。

# service httpd reload
Reloading httpd:                                           [  OK  ]

5. Munin を起動します。

# service munin-node start
Starting Munin Node:                                       [  OK  ]

6. Munin の自動起動を有効にします。

# chkconfig munin-node on

7. http://サーバー名/munin/ で Munin の統計情報へアクセスできます。

プラグインの追加と削除

Munin でグラフの種類を増やすにはプラグインを追加することで増やすことができます。
Munin のプラグイン本体は /usr/share/munin/plugins/ にあり、 プラグインのシンボリックリンクを /etc/munin/plugins/ へ追加・削除することによって、 プラグインの追加・削除を行うことができます。
Munin プラグインは Apache や MySQL、Sendmail、Postfix などのプラグインも収録されているので必要により有効化することが可能です。 また、MuninExchange のサイトでは、更に多くの拡張プラグインが提供されています。

Apache プラグインの追加

1. Munin の Apache プラグインを使用する場合は、Apache の mod_status モジュールの設定が必要なので Apache 設定ファイルを編集します。

# vi /etc/httpd/conf/httpd.conf
#
# This is the main Apache server configuration file.
#

(中略)

#
# Dynamic Shared Object (DSO) Support
#

(中略)

mod_status モジュールを有効にします。
LoadModule status_module modules/mod_status.so

(中略)

#
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
ExtendedStatus On

(中略)

#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 192.168.11
</Location>

(以下略)

2. Apache の設定変更に間違いがないか検証します。

# apachectl configtest
Syntax OK

4. Apache 設定を再読み込みします。

# service httpd reload
Reloading httpd:                                           [  OK  ]

5. Apache 関係のプラグインを追加します。

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

6. プラグインを有効にするため Munin を再起動します。

# service munin-node restart
Stopping Munin Node agents:                                [  OK  ]
Starting Munin Node:                                       [  OK  ]

MySQL プラグインの追加

1. プラグインが MySQL Admin の場所を知っている必要があるので、MySQL Admin のインストレーションパスを検索します。

# which mysqladmin
/usr/bin/mysqladmin

2. プラグインの設定ファイルに MySQL Admin の場所を追加します。

# vi /etc/munin/plugin-conf.d/munin-node
#
# This file contains configuration options for the plugins. Three
# options are understood by munin-node itself:
#
#       user <user>         # Set the user to run the plugin as
#       group <group>       # Set the group to run the plugin as
#       command <command>   # Run <command> instead of the plugin. %c
#                             expands to what would normally be run.
#   env.<variable>      # Sets <variable> in the plugin's environment, see the
#                         individual plugins to find out which variables they
#                         care about.
#
#

[mysql*]
#env.mysqlopts -u someuser
env.mysqladmin /usr/bin/mysqladmin

[exim*]
group mail

[cps*]
user root

[apt]
user root

[vlan*]
user root

[postfix*]
user root

3. 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

4. プラグインを有効にするため Munin を再起動します。

# service munin-node restart
Stopping Munin Node agents:                                [  OK  ]
Starting Munin Node:                                       [  OK  ]

PostgreSQL プラグインの追加

1. PostgreSQL プラグインをダウンロードしインストールします。

PostgreSQL 接続数プラグインをダウンロードします
# wget http://munin.projects.linpro.no/attachment/wiki/plugin-pg_conn/pg_conn?format=raw
--19:24:07--  http://munin.projects.linpro.no/attachment/wiki/plugin-pg_conn/pg_conn?format=raw
Resolving munin.projects.linpro.no... 213.236.139.168
Connecting to munin.projects.linpro.no|213.236.139.168|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1384 (1.4K) [application/x-sh]
Saving to: `pg_conn'

100%[======================================================================>] 1,384       --.-K/s   in 0s

19:24:09 (5.53 MB/s) - `pg_conn' saved [1384/1384]

プラグイン収録ディレクトリへ移動させます
# mv pg_conn /usr/share/munin/plugins/
PostgreSQL 接続数プラグインに実行権を付与します
# chmod 755 /usr/share/munin/plugins/pg_conn

2. PostgreSQL 関係のプラグインを追加します。

# ln -s /usr/share/munin/plugins/pg_conn /etc/munin/plugins/pg_conn

3. プラグインを有効にするため Munin を再起動します。

# service munin-node restart
Stopping Munin Node agents:                                [  OK  ]
Starting Munin Node:                                       [  OK  ]

Google