CentOS 7.5 にて epel から入れた munin-2.0.40 で色々面倒な事に

Linux
この記事は約10分で読めます。
この記事は最終更新日より 1 年以上経過しています。
画像やリンクが無効になっている可能性もあるのでご了承下さい。

 サーバーの動作状況などは Munin を用いた監視としているが、Web サーバーとして Nginx を使用している場合はグラフ拡大などを行う部分の設定が色々と面倒な物で。
 昨晩あたりに munin-2.0.39 から yum で update したら途端にアレこれおかしくなったのでイライラしながら対処した。

2.0.40 へアップデート後の挙動

 cron で定期的にステータスを読んで rrd に収集していくという基本的な動作には問題は無かった。
 しかしブラウザで Munin を開いてグラフをクリック。細かく見るためにグラフを拡大したりグラフ上の範囲を指定してみたり出来る所にグラフが表示されないようになってしまった。
 パッケージには munin-cgi-{graph,html}.service といった 2 つの systemd の unit ファイルがインストールされ、既存の munin-fcgi-{graph,html}.service は削除されていた。
 それならばと spawn-fcgi を叩かない munin-cgi-{graph,html}.service を起動させてみるも生成されたソケットに接続出来ずグラフの表示が出来ない。Nginx 側は Connection refused とエラーを吐いていたので繋がっていない。

グラフの拡大表示をさせる対処

 Nginx と Munin のグラフ周りで使用される CGI を FastCGI で使うための設定を改めて行った。

 先ず Nginx で Munin を表示させるホストの設定。

server {
    # Example configuration! Change this to suit your needs.
    # Access munin at http://localhost/munin/
    # NOTE - Do not remove this file, otherwise munin package upgrade
    # recreates this.

    listen       80;
    server_name  munin.example.com;
    root /var/www/html/munin;
    index index.html;

    location / {
        allow 192.168.1.0/24;
        allow 127.0.0.1;
        deny all;
    }

    # redirect server error pages to the static page /40x.html
    #
    error_page  404              /404.html;
    location = /40x.html {
        root   /usr/local/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/local/nginx/html;
    }

    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/ {
        fastcgi_split_path_info ^(/munin)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/munin-cgi-html.sock;
        include fastcgi_params;
    }

}

 次に munin-cgi-graph と munin-cgi-html の 2 つを起動して unix ソケット経由で listen させる sytemd の unit ファイルを作成する。
 作成後に設置するパスは cat の引数通り /lib/systemd/system/ 以下となる。設置後は systemctl daemon-reload をしておく事。

cat /lib/systemd/system/munin-fcgi-graph.service
[Unit]
Description=Munin FastCGI Graph
Documentation=man:spawn-fcgi

[Service]
Type=forking
PIDFile=/run/munin/fcgi-graph.pid
ExecStart=/usr/bin/spawn-fcgi -s /run/munin/munin-cgi-graph.sock -U nginx -u nginx -g nginx /var/www/html/munin/cgi/munin-cgi-graph -P /run/munin/fcgi-graph.pid

[Install]
WantedBy=multi-user.target
cat /lib/systemd/system/munin-fcgi-html.service
[Unit]
Description=Munin FastCGI HTML
Documentation=man:spawn-fcgi

[Service]
Type=forking
PIDFile=/run/munin/fcgi-html.pid
ExecStart=/usr/bin/spawn-fcgi -s /run/munin/munin-cgi-html.sock -U nginx -u nginx -g nginx /var/www/html/munin/cgi/munin-cgi-html -P /run/munin/fcgi-html.pid

[Install]
WantedBy=multi-user.target

 unit ファイルを作成、設置したら有効化しておく。

systemctl daemon-relaod
systemctl enable munin-fcgi-graph munin-fcgi-html
# socket のゴミが "残っていたら" 削除
rm /var/run/munin/munin-*.sock
systemctl start munin-fcgi-graph munin-fcgi-html

動作確認をする

 先ずは正しくプロセスが起動している事とプロセスの owner も確認し、sock ファイルの owner やらもしっかり確認する。

ps -ef | grep cgi
nginx    29966     1  0 19:23 ?        00:00:00 /usr/bin/perl -T /var/www/html/munin/cgi/munin-cgi-graph
nginx    29968     1  0 19:23 ?        00:00:00 /usr/bin/perl -T /var/www/html/munin/cgi/munin-cgi-html
ls -l /var/run/munin/
合計 12
-rw-r--r-- 1 root  root  5  9月 14 19:23 fcgi-graph.pid
-rw-r--r-- 1 root  root  5  9月 14 19:23 fcgi-html.pid
srwxr-xr-x 1 nginx nginx 0  9月 14 19:23 munin-cgi-graph.sock
srwxr-xr-x 1 nginx nginx 0  9月 14 19:23 munin-cgi-html.sock
-rw-r--r-- 1 root  root  6  9月 14 04:26 munin-node.pid

 そして何より拡大出来るグラフ表示とクリックして拡大する動作を直接確認する事。

おわりに

 筆者のサーバーでは epel より munin 関連パッケージは次の 5 つを入れて居る。

rpm -qa | grep munin
munin-common-2.0.40-2.el7.noarch
munin-nginx-2.0.40-2.el7.noarch
munin-cgi-2.0.40-2.el7.noarch
munin-2.0.40-2.el7.noarch
munin-node-2.0.40-2.el7.noarch

 にもかかわらず一部ディレクトリ (/var/lib/munin/cgi-tmp) の owner が apache になっていたりしたし munin-cgi 周りでは CGI の設置パスも変更されていたり。
 systemd の Unit ファイルも munin-cgi-html.service 等と言う様に fcgi から変更されている物のそのままでは動作できない。もちろん今まで使っていた munin-fcgi-{graph,html}.service の 2 ファイルは削除されてたり。
 メジャーバージョンの変更なら分かるけど 39 から 40 にビルドバージョンが変わるだけでここまでデカイ変化もあるもんだなと。

 ちょっとばかり munin のパッケージは癖が強すぎてバージョンアップ前にバックアップは欠かせない感じだ。

munin-2.0.40-4 が配信されたので追記

 2018/10/04 になって yum check-update してみたらまた Munin のパッケージが更新されたようで、今度は何が起こるのかなと不安だったのでチェックしてみた。

===============================================================================
  munin-2.0.40-4.el7
===============================================================================
  Update ID : FEDORA-EPEL-2018-673f52b139
    Release : Fedora EPEL 7
       Type : enhancement
     Status : testing
     Issued : 2018-09-17 18:50:39
    Updated : 2018-10-03 14:09:44       Bugs : 1628390 - munin-node requires perl-Getopt-Long but package does not require it
            : 1629438 - The 2.0.40-2 release of munin packages on Aug 25th 2018 is broken.
            : 1327512 - munin-limits not reporting actual state of variable to NSCA
Description : Improve upgrade path from old 2.0.33 to 2.0.40: save old apache
            : config files as %ghost.
            : 
            : Improve first install experience by automatically
            : creating localhost-config and better example
            : httpd/nginx config files.
   Severity : None

 こんな感じで Changelog を見てみると「The 2.0.40-2 release of munin packages on Aug 25th 2018 is broken.」との一文が。
 はぁ、そうですかーって事で今回は大丈夫なんだろうねーって更新したら本記事で弄った部分が消されたり等せずにそのまま動作してくれたので良かった。

著者プロフィール
ぶっち

本格的に PC へ触れ始めてたのは 1990 年位から。
興味は PC 全般。OS は Windows と Linux などを嗜む。
プログラマやネットワークエンジニアを経てフリーに活動している 2 児の父な 40 代半ばのおじさんです。

ぶっちをフォローする

コメント

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.