LoginSignup
2
2

More than 5 years have passed since last update.

suEXEC バーチャルホスト環境で Munin(+MySQL,Redis)

Last updated at Posted at 2013-12-28

この環境で Munin をセットアップ

Scientific Linux 6 で PHP5.4 Webホスティングサーバ構築
http://qiita.com/sukobuto/items/b44bd94bbd084a27878b

やったことメモなので殴り書きです。

  • munin ユーザアカウントを追加 (最初にやること!)
  • munin インストール
  • suEXEC 環境に対応させる
  • munin 初期設定
  • apache 設定追加
  • サービス起動
  • プラグインの追加 (MySQL, Redis)
  • サービス再起動

munin ユーザアカウントを追加

上記記事 - ホスティングユーザの環境整備 (半自動化) にて作成したスクリプトを使用します。

[root@host ~]# ./hostinguseradd.sh munin munin.example.com

なぜ munin ユーザを自分で作るのか

munin をインストールすると、自動的に munin ユーザ(munin の実行とmuninページの更新を行うユーザ)が作成されます。

ここで通常ユーザとして munin ユーザを作成しておく理由は、suEXEC 環境でも munin を動かすことができるようにするためです。

もし先に munin ユーザを作成しなかった場合、UID が 500 より小さい値になってしまいます。suEXEC のデフォルトでは UID が 500 より小さいユーザは CGI の実行が抑止されてしまいます。

必ず munin インストールよりも先に munin ユーザを作成しておきましょう。

yum で Munin をインストール

epel リポジトリ利用

yum install munin munin-node

suEXEC 環境に対応させる

ほかのユーザアカウントと同じ構造にします。

ドキュメントルート移動したりなんだり
cd /home/munin
cp /var/www/cgi-bin/munin-cgi-* cgi-bin/
chown munin:munin cgi-bin/munin-cgi-*
chmod 710 cgi-bin/munin-cgi-*
rmdir public_html
ln -s /var/www/html/munin public_html
chmod 710 public_html

munin 初期設定

/etc/munin/munin.conf
ホスト名を変更

/etc/munin/munin.conf
[example.com]
    address 127.0.0.1
    use_node_name yes

/etc/munin/munin-node.conf
ホスト名を変更

/etc/munin/munin-node.conf
host_name example.com

apache 設定追加

/etc/httpd/conf.d/munin.conf
munin をインストールすると自動的に追加される Apache 設定ファイル

  • ディレクトリパスを変更
  • ダイジェスト認証に変更(任意)
  • ScriptAlias の参照先パスを変更
/etc/httpd/conf.d/munin.conf
# 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 /home/munin/public_html/>
AllowOverride None
AuthUserFile /etc/munin/munin-htpasswd
AuthName "munin"
AuthType Digest
AuthDigestDomain /
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 /home/munin/cgi-bin/munin-cgi-graph

munin-htpasswd にユーザ追加

cd /etc/munin/
htdigest munin-htpasswd "munin" munin

サービス起動

[root@host ~]# service httpd restart
[root@host ~]# service munin-node start
[root@host ~]# chkconfig munin-node on

これで munin.example.com (例) にアクセスし、Munin ページが表示されれば成功です。

プラグイン追加

munin 楽々インストールでMySQLを監視する!
Munin で Redis のリソース監視

# MySQL 監視導入
yum install perl-IPC-ShareLite perl-Cache-Cache perl-Cache perl-DBD-MySQL
cd /etc/munin/plugins
ln -s /usr/share/munin/plugins/mysql_ mysql_commands
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_bpool
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_io
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_log
ln -s /usr/share/munin/plugins/mysql_ mysql_innodb_tnx
ln -s /usr/share/munin/plugins/mysql_ mysql_select_types
ln -s /usr/share/munin/plugins/mysql_ mysql_table_locks
ln -s /usr/share/munin/plugins/mysql_ mysql_connections
ln -s /usr/share/munin/plugins/mysql_ mysql_slow
ln -s /usr/share/munin/plugins/mysql_ mysql_myisam_indexes
ln -s /usr/share/munin/plugins/mysql_ mysql_network_traffic
ln -s /usr/share/munin/plugins/mysql_ mysql_qcache
ln -s /usr/share/munin/plugins/mysql_ mysql_qcache_mem

# Redis 監視導入
cd /usr/share/munin/plugins/
wget https://raw.github.com/bpineau/redis-munin/master/redis_
chmod +x redis_
ln -s /usr/share/munin/plugins/redis_ /etc/munin/plugins/redis_127.0.0.1_6379

プラグインの munin-node 設定ファイルに追記

/etc/munin/plugin-conf.d/munin-node
[mysql*]
env.mysqlconnection DBI:mysql:mysql;host=localhost;port=3306
env.mysqluser mysqluserid
env.mysqlpassword mysqlpasswd
[redis*]
env.password redispasswd ;パスワード設定してないなら不要

munin-node 再起動

service munin-node restart
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2