Munin LAMPサーバ(CentOS6.4)監視設定メモ
サーバ監視は Zabbixを使うことが多いのですが、たまたまMuninを扱うことになったので設定メモ。Muninはサーバ状態のグラフ表示に特化しているので、インストールと簡単な設定をすれば、多種多様なグラフをすぐに見ることができます。
○サーバ構成
監視対象のLAMPサーバ(lamp-sv)に munin-nodeを入れて、Muninサーバからポーリングし、監視データをグラフで表示します。

========== Muninサーバのインストール ==========
・Apacheのインストール
yum -y install httpd-devel
・EPELリポジトリの追加(munin関連のインストール用)
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
・Muninインストール
yum -y install munin munin-node
・EPELリポジトリの無効化
vi /etc/yum.repos.d/epel.repo
---(下記を変更)---------------------------
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
↓
enabled = 0
------------------------------
・動作確認用に telnet を入れておきます
yum -y install telnet
========== Muninサーバのポーリング設定 ==========
・監視対象の設定
vi /etc/munin/munin.conf
---(下記を変更)---------------------------
[localhost]
address 127.0.0.1
use_node_name yes
↓
# Muninサーバ
[Munin;munin-sv]
address 192.168.56.101
use_node_name yes
# LAMPサーバ
[LAMP;lamp-sv]
address 192.168.56.102
use_node_name yes
------------------------------
========== Muninサーバの munin-node 設定 ==========
※Muninサーバ自身も監視するため設定しておきます。
vi /etc/munin/munin-node.conf
---(下記を変更)---------------------------
allow ^127\.0\.0\.1$
allow ^::1$
↓
allow ^192\.168\.56\.101$
#allow ^::1$
------------------------------
・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
・起動
service munin-node start
・確認
service munin-node status
---(下記表示があればOKです)---------------------------
munin-node (pid XXXX) is running...
------------------------------
・自動起動の設定
sudo chkconfig munin-node on
・確認
sudo chkconfig --list munin-node
---(下記表示があればOKです)---------------------------
munin-node 0:off 1:off 2:on 3:on 4:on 5:on 6:off
------------------------------
========== Muninサーバの Apache 設定 ==========
・ホスト名エラー回避用
vi /etc/httpd/conf/httpd.conf
---(下記を変更)---------------------------
#ServerName www.example.com:80
↓
ServerName localhost:80
------------------------------
・Basic認証ユーザの作成(ユーザ名はお好みで)
htpasswd /etc/munin/munin-htpasswd munin
------------------------------
New password: <パスワード>
Re-type new password: <パスワード>
------------------------------
・Apacheの監視に server-statusページを使うので設定しておきます。
PHPのフレームワークなどで、全てのアクセスを特定のファイルにリダイレクトしていると、server-statusのデータが取れません。そこで Aliasでリダイレクトを回避しつつ、ローカルホストからのみアクセス可能なバーチャルホストにしておきます。
vi /etc/httpd/conf/httpd.conf
---(下記を最終行に追加)---------------------------
ExtendedStatus On
Alias /server-status /server-status
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName 127.0.0.1
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
------------------------------
・Apacheの起動
service httpd start
・Apacheの自動起動設定
chkconfig httpd on
・下記コマンドで server-statuのデータがとれることを確認
curl http://127.0.0.1/server-status
========== munin-nodeの動作確認 ==========
10分ほどしたらブラウザで下記にアクセスしてMuninが表示できることを確認(先に設定したBasic認証のパスワードが必要です)
http://192.168.56.101/munin/

・telnetで 4949ポートにアクセスして確認することもできます
telnet <ホスト名> 4949
------------------------------
list(使用できるパラメータ覧取得)
apache_accesses apache_processes apache_volume cpu df df_inode entropy forks fw_packets if_err_eth0 if_err_eth1 if_eth0 if_eth1 interrupts irqstats load memory netstat ntp_133.243.238.163 ntp_133.243.238.164 ntp_133.243.238.243 ntp_kernel_err ntp_kernel_pll_freq ntp_kernel_pll_off ntp_offset ntp_states open_files open_inodes postfix_mailqueue postfix_mailvolume proc_pri processes swap threads uptime users vmstat
list swap
fetch cpu(パラメータ値取得)
.
fetch cpu
user.value 1251
nice.value 2181
system.value 911
idle.value 128553
iowait.value 264
irq.value 57
softirq.value 46
steal.value 0
guest.value 0
.
quit(終了)
------------------------------
========== LAMPサーバの munin-node 設定 ==========
ミドルウェアは Apache、MySQLに加えて Memcachedを監視してみます。
・EPELリポジトリの追加(munin関連のインストール用)
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
・Muninインストール
yum -y install munin-node
・EPELリポジトリの無効化
vi /etc/yum.repos.d/epel.repo
---(下記を変更)---------------------------
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
↓
enabled = 0
------------------------------
vi /etc/munin/munin-node.conf
---(下記を変更)---------------------------
allow ^127\.0\.0\.1$
allow ^::1$
↓
allow ^192\.168\.56\.101$
#allow ^::1$
------------------------------
・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
・MySQL監視プラグインの追加
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
・Memcached監視プラグインの追加
ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_rates
ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_bytes
ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_counters
・Perl用のMemcachedモジュールのインストール
yum -y install perl-Cache-Memcached.noarch
・Apache監視設定
vi /etc/httpd/conf/httpd.conf
---(下記を最終行に追加)---------------------------
ExtendedStatus On
Alias /server-status /server-status
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName 127.0.0.1
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
------------------------------
・Apacheの再起動
sudo service httpd graceful
・MySQL監視用設定
sudo vi /etc/munin/plugin-conf.d/munin-node
---(下記を最終行に追加)---------------------------
[mysql*]
env.mysqlopts -u root -p<DBのパスワード>
------------------------------
・パスワードを書いているのでパーミッション変更
sudo chmod 600 /etc/munin/plugin-conf.d/munin-node
・起動
service munin-node start
・自動起動の設定
sudo chkconfig munin-node on
しばらくするとLAMPサーバが追加されます

以上です。
○サーバ構成
監視対象のLAMPサーバ(lamp-sv)に munin-nodeを入れて、Muninサーバからポーリングし、監視データをグラフで表示します。

========== Muninサーバのインストール ==========
・Apacheのインストール
yum -y install httpd-devel
・EPELリポジトリの追加(munin関連のインストール用)
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
・Muninインストール
yum -y install munin munin-node
・EPELリポジトリの無効化
vi /etc/yum.repos.d/epel.repo
---(下記を変更)---------------------------
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
↓
enabled = 0
------------------------------
・動作確認用に telnet を入れておきます
yum -y install telnet
========== Muninサーバのポーリング設定 ==========
・監視対象の設定
vi /etc/munin/munin.conf
---(下記を変更)---------------------------
[localhost]
address 127.0.0.1
use_node_name yes
↓
# Muninサーバ
[Munin;munin-sv]
address 192.168.56.101
use_node_name yes
# LAMPサーバ
[LAMP;lamp-sv]
address 192.168.56.102
use_node_name yes
------------------------------
========== Muninサーバの munin-node 設定 ==========
※Muninサーバ自身も監視するため設定しておきます。
vi /etc/munin/munin-node.conf
---(下記を変更)---------------------------
allow ^127\.0\.0\.1$
allow ^::1$
↓
allow ^192\.168\.56\.101$
#allow ^::1$
------------------------------
・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
・起動
service munin-node start
・確認
service munin-node status
---(下記表示があればOKです)---------------------------
munin-node (pid XXXX) is running...
------------------------------
・自動起動の設定
sudo chkconfig munin-node on
・確認
sudo chkconfig --list munin-node
---(下記表示があればOKです)---------------------------
munin-node 0:off 1:off 2:on 3:on 4:on 5:on 6:off
------------------------------
========== Muninサーバの Apache 設定 ==========
・ホスト名エラー回避用
vi /etc/httpd/conf/httpd.conf
---(下記を変更)---------------------------
#ServerName www.example.com:80
↓
ServerName localhost:80
------------------------------
・Basic認証ユーザの作成(ユーザ名はお好みで)
htpasswd /etc/munin/munin-htpasswd munin
------------------------------
New password: <パスワード>
Re-type new password: <パスワード>
------------------------------
・Apacheの監視に server-statusページを使うので設定しておきます。
PHPのフレームワークなどで、全てのアクセスを特定のファイルにリダイレクトしていると、server-statusのデータが取れません。そこで Aliasでリダイレクトを回避しつつ、ローカルホストからのみアクセス可能なバーチャルホストにしておきます。
vi /etc/httpd/conf/httpd.conf
---(下記を最終行に追加)---------------------------
Alias /server-status /server-status
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName 127.0.0.1
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
・Apacheの起動
service httpd start
・Apacheの自動起動設定
chkconfig httpd on
・下記コマンドで server-statuのデータがとれることを確認
curl http://127.0.0.1/server-status
========== munin-nodeの動作確認 ==========
10分ほどしたらブラウザで下記にアクセスしてMuninが表示できることを確認(先に設定したBasic認証のパスワードが必要です)
http://192.168.56.101/munin/

・telnetで 4949ポートにアクセスして確認することもできます
telnet <ホスト名> 4949
------------------------------
list(使用できるパラメータ覧取得)
apache_accesses apache_processes apache_volume cpu df df_inode entropy forks fw_packets if_err_eth0 if_err_eth1 if_eth0 if_eth1 interrupts irqstats load memory netstat ntp_133.243.238.163 ntp_133.243.238.164 ntp_133.243.238.243 ntp_kernel_err ntp_kernel_pll_freq ntp_kernel_pll_off ntp_offset ntp_states open_files open_inodes postfix_mailqueue postfix_mailvolume proc_pri processes swap threads uptime users vmstat
list swap
fetch cpu(パラメータ値取得)
.
fetch cpu
user.value 1251
nice.value 2181
system.value 911
idle.value 128553
iowait.value 264
irq.value 57
softirq.value 46
steal.value 0
guest.value 0
.
quit(終了)
------------------------------
========== LAMPサーバの munin-node 設定 ==========
ミドルウェアは Apache、MySQLに加えて Memcachedを監視してみます。
・EPELリポジトリの追加(munin関連のインストール用)
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
・Muninインストール
yum -y install munin-node
・EPELリポジトリの無効化
vi /etc/yum.repos.d/epel.repo
---(下記を変更)---------------------------
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
↓
enabled = 0
------------------------------
vi /etc/munin/munin-node.conf
---(下記を変更)---------------------------
allow ^127\.0\.0\.1$
allow ^::1$
↓
allow ^192\.168\.56\.101$
#allow ^::1$
------------------------------
・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
・MySQL監視プラグインの追加
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
・Memcached監視プラグインの追加
ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_rates
ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_bytes
ln -s /usr/share/munin/plugins/memcached_ /etc/munin/plugins/memcached_counters
・Perl用のMemcachedモジュールのインストール
yum -y install perl-Cache-Memcached.noarch
・Apache監視設定
vi /etc/httpd/conf/httpd.conf
---(下記を最終行に追加)---------------------------
Alias /server-status /server-status
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName 127.0.0.1
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
</VirtualHost>
・Apacheの再起動
sudo service httpd graceful
・MySQL監視用設定
sudo vi /etc/munin/plugin-conf.d/munin-node
---(下記を最終行に追加)---------------------------
[mysql*]
env.mysqlopts -u root -p<DBのパスワード>
------------------------------
・パスワードを書いているのでパーミッション変更
sudo chmod 600 /etc/munin/plugin-conf.d/munin-node
・起動
service munin-node start
・自動起動の設定
sudo chkconfig munin-node on
しばらくするとLAMPサーバが追加されます

以上です。
07