LoginSignup
14
11

More than 5 years have passed since last update.

CentOS7.xにMuninをインストール

Last updated at Posted at 2017-04-05

以前CentOS6.x用に書いたものを7.x用に検証・リライト。実行環境はCentOS7.3。すごく適当ですが、随時加筆します。

やりたいこと

  • とりあえず自分自身(ローカルサーバ)の状況を知る

Muninのインストール

epelにあるのでリポジトリをインストール。

sudo yum install epel-release

yumでインストール。

sudo yum install munin --enablerepo=epel

パスワードファイルを作成し、ユーザー名、パスワードを指定する。

sudo htpasswd -c /etc/munin/munin-htpasswd admin

実際はadminとかじゃなくてもっとわかりにくい名前にするほうがいいと思います。

httpdをリスタートさせる。

sudo systemctl restart httpd.service

ノードをスタートさせる。

sudo systemctl start munin-node

ノードを永続化させる。

sudo systemctl enable munin-node

しばらくたって http://servername/munin/ に行くと管理画面が生成されている。

まだ、初回のcronが動いていない場合はForbidden等のエラーとなる。待ちましょう。

Apacheの監視

次にApacheの監視項目を追加します。/usr/share以下から利用したプラグインをコピーするかリンクをはる。

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

munin用の設定を追加。CentOS6.xとはややことなる。/etc/httpd/conf.d以下にstatus.confを作成し、munin用の設定を書く。
拡張情報の取得をOnにするのと、取得先の許可情報を設定。

/etc/httpd/conf.d/status.conf
ExtendedStatus On

<Location /server-status>
  SetHandler server-status
  Require ip 127.0.0.1
</Location>

内容を反映させるためにhttpdをリスタート。

sudo systemctl restart httpd.service

動作確認のためにwgetをインストール。

sudo yum install wget -y

以下のコマンドを実行し、下記のような状態が取得できればOK。

wget -q -O - http://127.0.0.1/server-status/?auto

Total Accesses: 0
Total kBytes: 0
Uptime: 95
ReqPerSec: 0
BytesPerSec: 0
BusyWorkers: 1
IdleWorkers: 4
Scoreboard: W____...........................................................................................................................................................................................................................................................

ここでノードも再起動。

sudo systemctl restart munin-node

それぞれの値が取得できるかチェック。それぞれを実行し、数字が返ってくればOK。Unknownとかだとおかしい。

munin-run apache_accesses
munin-run apache_processes
munin-run apache_volume

認識されるとMuninの管理画面のCategoriesにapacheの項目が追加されます。

MySQLの監視

次にMySQLの監視を設定してみます。まずは、munin用のアカウントを作成します。

mysql> grant all on *.* to 'munin'@'127.0.0.1' identified by 'password';

利用したいプラグインをリンク。

sudo ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/
sudo ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/
sudo ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/
sudo ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/

muninがMySQLにアクセスするための情報を設定ファイルに追加します。/etc/munin/plugin-conf.d/munin-nodeです。

/etc/munin/plugin-conf.d/munin-node
[mysql*]
env.mysqlopts -u munin -ppassword -h 127.0.0.1 --port=3306

SlowQuery監視するためにmy.cnfにログ出力の設定をします。

/etc/my.cnf
slow_query_log=1
slow_query_log_file=/var/log/mysql-slow.log
long_query_time=10

ログファイルをMySQLがいじれるようにアクセス権限を設定。

sudo touch /var/log/mysql-slow.log
sudo chown mysql:mysql /var/log/mysql-slow.log

MySQLとノードを再起動。

sudo systemctl restart mysqld.service
sudo systemctl restart munin-node.service

各値が取得できるかチェック。

munin-run mysql_bytes
munin-run mysql_queries
munin-run mysql_slowqueries
munin-run mysql_threads

負荷をかけてみる

チェックのために負荷ツールを準備。

CPU (stress)

CentOS6.xではepelからインストールできたのだけど、できなくなっているのでrpmを取得してインストール。

wget http://ftp.riken.jp/Linux/dag/redhat/el7/en/x86_64/rpmforge/RPMS/stress-1.0.2-1.el7.rf.x86_64.rpm
rpm -ivh stress-1.0.2-1.el7.rf.x86_64.rpm
stress --version

負荷をかけてみる。基本的な書式は下記の通り。値はお好みで。

stress -c 1 --timeout 1m

Apache (ab)

Apacheを入れたら標準で入る。abコマンド。

ab -c 100 -n 1000 http://localhost/

MySQL (mysqlslap)

MySQLに標準で付属するmysqlslapを利用してみます。詳細はGoogle先生に聞く。

mysqlslap -u root -p --auto-generate-sql --concurrency=10

こちらが参考になります。

ひとまず以上。

アラートメール送信

長くなるので別に記述します。

14
11
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
14
11