オープンソースこねこね

Webプログラミングなどについてあれこれ。

CentOS7でmunin + nginxを設定する

久しぶりにmuninのインストールと設定などを行ったら、いろいろやり方が変わっていたのでやったことのメモを残します。nginxのインストールは済んでいるものとします。

インストール

yum install munin munin-cgi munin-nginx

設定ファイル

/etc/munin/munin.conf

単純なサーバー統計を監視するだけなら、デフォルトのままでOK。特に書き換える必要なし。

/etc/munin/conf.d/

この配下にインクルードされる設定ファイルを配置する。監視対象のサーバー定義など。

例: /etc/munin/conf.d/servers.conf

[your-node-1]
    address 192.168.0.2
    use_node_name yes
[your-node-2]
    address 192.168.0.3
    use_node_name yes

nginxの設定

munin用にバーチャルホストを設定する部分のみを抜粋。大体こんな感じ。

server {
    listen       80;
    server_name  your-server-name.xxx.com;
    root /var/www/html;
    index index.html;

    location / {
        allow 127.0.0.1;
        deny all;
    }

    location ^~ /munin-cgi/munin-cgi-graph/ {
        access_log off;
        fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/munin-cgi-graph.sock;
        include fastcgi_params;
    }

    location /munin/static/ {
        alias /etc/munin/static/;
    }

    location /munin/ {
        alias /var/www/html/munin/;
    }
}

この設定はhttp://your-server-name.xxx.com/muninでアクセスするための設定。サブディレクトリの配置をなくしたい場合は、rootのパスなどを適宜いじる。

サービスの起動

グラフはFastCGIで描画されるのでFastCGIサーバーを起動する。

systemctl start munin-cgi-graph.service

以上。

munin-node

監視対象サーバーに設定するmunin-nodeは割愛。yumでインストールしてsystemdで起動、ファイアウォールにport4949を許可するなどする。

公式ドキュメント

わからないことはドキュメントを読む。

https://munin.readthedocs.io/en/latest/index.html

メモ

  • (グラフだけでなく)HTMLも動的生成するためのFastCGIがある。が、うまく設定できなかったので保留。ドキュメント
  • FastCGIを使わずにmunin組み込みのhtttpdでグラフとHTMLを描画する機能もある。が、うまく設定できなかったので保留。ドキュメント