munin + nginx:没有动态缩放到图表

munin + nginx:没有动态缩放到图表

我无法让 Munin 动态缩放功能正常工作。我确信问题与 Nginx 配置有关。任何生成缩放图的尝试都会在 nginx 日志中触发以下错误条目:

2015/02/22 13:26:01 [error] 4782#0: *2580 open() "/data/munin/usr/share/munin/cgi/munin-cgi-graph/bellaria/antergos1.bellaria/diskstats_latency/AntergosVG_AntergosRoot-pinpoint=1421756527,1424607727.png" failed (2: No such file or directory), client: 10.10.10.25, server: munin, request: "GET /usr/share/munin/cgi/munin-cgi-graph/bellaria/antergos1.bellaria/diskstats_latency/AntergosVG_AntergosRoot-pinpoint=1421756527,1424607727.png?&lower_limit=&upper_limit=&size_x=800&size_y=400 HTTP/1.1", host: "munin.bellaria", referrer: "http://munin.bellaria/static/dynazoom.html?cgiurl_graph=/usr/share/munin/cgi/munin-cgi-graph&plugin_name=bellaria/antergos1.bellaria/diskstats_latency/AntergosVG_AntergosRoot&size_x=800&size_y=400&start_epoch=1421756527&stop_epoch=1424607727"

具体来说,我怀疑 fastCGI 参数有问题。有没有人能帮我看一下我的 Munin 虚拟服务器(见下文)并向我解释一下哪里出了问题?这简直让我抓狂 - 但我有预感任何专家都能在几分之一秒内找出问题所在...

# Munin server
server {
       listen 80;
    server_name munin munin.bellaria;
    root /data/munin;
    allow all;
    access_log logs/munin.access.log;
    error_log logs/munin.error.log;

    location / {
        index index.html index.htm index.php;
        }

    location ~ \.(php|html|html|cgi)$ {
        fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param   AUTH_USER $remote_user;
        fastcgi_param   REMOTE_USER $remote_user;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_index  index.php;
        include        fastcgi.conf;
        }


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

   }

答案1

我在寻找问题解决方案时发现了这个,真是个好消息!我解决了我的问题。我希望这也能帮助你让 munin 在你的设置上工作。

要求:

  • spawnfcgi:

    1. 从 https://github.com/lighttpd/spawn-fcgi 克隆或下载 zip
    2. 准备:
      自动重新配置-v-i
    3. 编译并安装:
      ./配置&& 制作&& sudo 制作安装

  • 初始化脚本(我不做 systemd 所以弄清楚如何创建服务):

    /bin/sh #!/bin/sh
    ### 开始初始化信息
    # 提供:munin-fastcgi
    # 必需启动:$remote_fs $network
    # 必需停止:$remote_fs $network
    # 默认开始: 2 3 4 5
    # 默认停止: 0 1 6
    # 简短描述:启动 munin-fastcgi
    # 描述:生成 Munin FCGI 套接字以进行 Web 访问
    ### 结束初始化信息
    
    #
    # munin-fastcgi Munin CGI 服务的启动脚本
    #
    # chkconfig: - 84 15
    #描述:使用 spawn-cgi 加载 Munin CGI 服务
    # HTML 文件和 CGI​​。
    #
    # 作者:Ryan Norbauer
    # 修改:Geoffrey Grosenbach http://topfunky.com
    # 修改:David Krmpotic http://davidhq.com
    #修改:坤熙 http://kunxi.org
    # 修改于:http://drumcoder.co.uk/
    # 修改于:http://uname.pingveno.net/
    # 修改:the_architecht http://iwbyt.com/
    PATH=/usr/local/bin/:/usr/local/sbin:$PATH
    DAEMON=$(生成-fcgi)
    FCGI_GRAPH_SOCK=/var/运行/munin/fastcgi-munin-graph.sock
    FCGI_HTML_SOCK=/var/运行/munin/fastcgi-munin-html.sock
    WWW_USER=www-数据
    FCGI_USER=www-数据
    FCGI_GROUP=www-数据
    FCGI_SPAWN_GRAPH=/usr/lib/munin/cgi/munin-cgi-graph
    FCGI_SPAWN_HTML=/usr/lib/munin/cgi/munin-cgi-html
    PIDFILE_GRAPH = /var/运行/munin/fastcgi-munin-graph.pid
    PIDFILE_HTML = / var /运行/ munin / fastcgi-munin-html.pid
    DESC="Munin FCGI 用于图形和 HTML"
    
    # 如果软件包已被删除,则正常退出。
    测试 -x $DAEMON || 退出 0
    测试 -x $FCGI_SPAWN_GRAPH || 退出 0
    测试 -x $FCGI_SPAWN_HTML || 退出 0
    
    开始() {
      $DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH 2> /dev/null || echo "图表已运行"
      $DAEMON -s $FCGI_HTML_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML 2> /dev/null || echo "HTML 已运行"
    }
    
    停止() {
      kill -QUIT `cat $PIDFILE_GRAPH` || echo "图表未运行"
      kill -QUIT `cat $PIDFILE_HTML` || echo "HTML 未运行"
    }
    
    重新开始() {
      kill -HUP `cat $PIDFILE_GRAPH` || echo "无法重新加载图表"
      kill -HUP `cat $PIDFILE_HTML` || echo "无法重新加载 HTML"
    }
    
    案例“$1”
      开始)
        echo "起始 $DESC: "
        开始
      ;;
      停止)
        echo "停止 $DESC: "
        停止
      ;;
      重启|重新加载)
        echo "重新启动 $DESC:"
        停止
        # 一秒钟可能不足以让守护进程停止,
        # 如果发生这种情况,d_start 将失败(并且 dpkg 也会中断,如果
        # 软件包正在升级)。如果需要,请更改超时时间
        # 或者将 d_stop 更改为让 start-stop-daemon 使用--retry。
        # 请注意,使用--retry会稍微减慢关机过程。
        睡眠 1
        开始
      ;;
      *)
        echo "用法:$SCRIPTNAME {start|stop|restart|reload}" >&2
        出口 3
      ;;
    埃萨克
    
    退出 $?
    

    /etc/init.d/munin-fcgi在具有权限的情况下安装上述内容755

  • 在您的 vhost 中,例如/etc/nginx/conf.d/example.com.conf,在块中添加此内容server { }。您可以更改允许的 IP 块以适合您的设置。我在本地服务器上执行了此操作,并希望 munin 图表仅在本地可用。

    位置 /munin {
    #别名/var/cache/munin/www;
        索引 索引.html;
    #包括/etc/nginx/php.conf;
    #访问日志关闭;
        允许 127.0.0.1;
        允许 192.168.0.0/16;
        全部否认;                                
    }
    
    位置 ^~ /munin-cgi/munin-cgi-graph/ {
    # 如果 ($uri ~ /munin-cgi/munin-cgi-graph/([^/]*)) { 设置 $path $1; }
        fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/fastcgi-munin-graph.sock;
        包括 fastcgi_params;
    }
    位置 ^~ /munin-cgi/munin-cgi-html/ {
    # 如果 ($uri ~ /munin-cgi/munin-cgi-html/([^/]*)) { 设置 $path $1; }
        fastcgi_split_path_info ^(/munin-cgi/munin-cgi-html)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/fastcgi-munin-html.sock;
        包括 fastcgi_params;
    }
    

  • 启动/etc/init.d/munin-fcgi start并重新加载 nginx,然后您就可以开始了。
  • ps 我确实将 munin 的 html 文件夹链接到我的 vhost 的文件夹:ln -s /var/cache/munin/www/ /var/www/example.com/munin -v

    答案2

    这听起来像是 中的定义有问题static/dynazoom.html。在我们的安装中,我们有

    form.cgiurl_graph.value = qs.get("cgiurl_graph", "/munin-cgi/munin-cgi-graph");
    

    我怀疑你有

    form.cgiurl_graph.value = qs.get("cgiurl_graph", "/usr/share/munin/cgi/munin-cgi-graph");
    

    虽然应该如此

    form.cgiurl_graph.value = qs.get("cgiurl_graph", "/cgi-bin/munin-cgi-graph");
    

    我仍然确信问题大致就在这里。只要缩放图表的请求以 开头,nginx 配置看起来就正确/cgi-bin/munin-cgi-graph。我不明白/data/munin/...它来自哪里。

    尝试在可以监视浏览器(fiddler、chrome dev tools)发送的请求的环境中运行,并查看实际发送的内容。

    您确定您编辑的是 dynazoom 的正确副本吗?尝试进行一些微小的可见更改以验证这一点。

    答案3

    我在 ubuntu 12.04 上遇到了类似的问题,使用的是 munin 2.0.21。
    检查 dynazoom 尝试查找 munin-cgi-graph 的位置。
    Munin 的 wiki 上说你应该配置你的 nginx fcgi-graph

    location ^~ /cgi-bin/munin-cgi-graph/
    

    在我使用 Chrome 开发者工具(网络选项卡)检查页面时,我发现 dynazoom 正在尝试从中获取 munin-cgi-graph/munin-cgi/munin-cgi-graph/不是来自/cgi-bin/munin-cgi-graph/并且它得到 404 错误而不是图表

    所以我刚刚在 nginx 配置中改变了这个位置:

        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/fcgi-graph.sock;
            include fastcgi_params;
     }
    

    看起来您遇到了同样的问题,您的 munin-cgi-graph 位置不正确,因此浏览器请求root /data/munin正如错误所说的那样。

    答案4

    我想在这次谈话中补充一些内容。the_architecht 提供的信息非常有价值,但至少对我来说缺少了一些东西。


    这里使用 CentOS 6.8:

    -

    1) CGI 文件的路径已更改,可以通过定位找到它们:

    /var/www/cgi-bin/munin-cgi-graph
    /var/www/cgi-bin/munin-cgi-html
    

    我必须在启动脚本中逐行比较位置,并分解守护进程启动行以查看哪里出了问题,这样我就可以追踪文件路径的差异。

    -

    2) 日志的权限被设置为“munin”用户,这导致了某种无提示错误。为了解决这个问题,我将 www-data 用户添加到 munin 组,并将日志文件 chmod 664:

    -rw-rw-r-- 1 munin munin 0 Apr 27 20:35 /var/log/munin/munin-cgi-graph.log
    -rw-rw-r-- 1 munin munin 0 Apr 27 20:35 /var/log/munin/munin-cgi-html.log
    

    文件权限的泄露涉及Munin 维基在 spawn-fcgi 进程启动结束时添加 -n,然后 strace -s1024 出现错误

    写入(2,“[2017 年 4 月 27 日星期四 21:47:35] munin-cgi-html:无法打开 /var/log/munin/munin-cgi-html.log(权限被拒绝)位于 /usr/share/perl5/vendor_perl/Log/Log4perl/Appender/File.pm 第 103 行。\n”,180 [2017 年 4 月 27 日星期四 21:47:35] munin-cgi-html:无法打开 /var/log/munin/munin-cgi-html.log(权限被拒绝)位于 /usr/share/perl5/vendor_perl/Log/Log4perl/Appender/File.pm 第 103 行。


    我的最终 Nginx 和 spawn-fcgi 以及我的修改如下:

    server {
    
            listen $IP;
            server_name $host.example.com;
    
                    access_log      /var/log/nginx/domlogs/munin-access.log;
                    error_log       /var/log/nginx/domlogs/munin-error.log;
    
        root /var/www/html/munin/;
        index   index.html;
    
    
    location / {
            auth_basic            "Restricted";
           # Create the htpasswd file with the htpasswd tool.
            auth_basic_user_file  /etc/nginx/htpasswd/munin;
    
    }
    
    location ^~ /munin-cgi/munin-cgi-graph/ {
    #   if ($uri ~ /munin-cgi/munin-cgi-graph/([^/]*)) { set $path $1; }
        fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/fastcgi-munin-graph.sock;
        include fastcgi_params;
    }
    location  ^~ /munin-cgi/munin-cgi-html/ {
    #   if ($uri ~ /munin-cgi/munin-cgi-html/([^/]*)) { set $path $1; }
        fastcgi_split_path_info ^(/munin-cgi/munin-cgi-html)(.*);
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/var/run/munin/fastcgi-munin-html.sock;
        include fastcgi_params;
    }
    
    }
    

    #! /bin/bash
    ### BEGIN INIT INFO
    # Provides:          munin-fastcgi
    # Required-Start:    $remote_fs $network
    # Required-Stop:     $remote_fs $network
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts munin-fastcgi
    # Description:       Spawn Munin FCGI sockets for Web access
    ### END INIT INFO
    
    #
    # munin-fastcgi     Startup script for Munin CGI services
    #
    # chkconfig: - 84 15
    # description: Loading Munin CGI services using spawn-cgi
    #              HTML files and CGI.
    #
    # Author:  Ryan Norbauer 
    # Modified:     Geoffrey Grosenbach http://topfunky.com
    # Modified:     David Krmpotic http://davidhq.com
    # Modified:     Kun Xi http://kunxi.org
    # Modified:     http://drumcoder.co.uk/
    # Modified:     http://uname.pingveno.net/
    # Modified:     the_architecht http://iwbyt.com/
    # Modified:     Jame Scott - NeCr0mStR
    
    DESC="Munin FCGI for Graph and HTML"
    
    SCRIPTNAME="$(tput setaf 1)Munin-FastCGI$(tput sgr0)"
    
    PATH=/usr/local/bin/:/usr/local/sbin:$PATH
    DAEMON=$(which spawn-fcgi)
    FCGI_GRAPH_SOCK=/var/run/munin/fastcgi-munin-graph.sock
    FCGI_HTML_SOCK=/var/run/munin/fastcgi-munin-html.sock
    WWW_USER=www-data
    FCGI_USER=www-data
    FCGI_GROUP=www-data
    FCGI_SPAWN_GRAPH=/var/www/cgi-bin/munin-cgi-graph
    FCGI_SPAWN_HTML=/var/www/cgi-bin/munin-cgi-html
    PIDFILE_GRAPH=/var/run/munin/fastcgi-munin-graph.pid
    PIDFILE_HTML=/var/run/munin/fastcgi-munin-html.pid
    
    # Gracefully exit if the package has been removed.
    
        test -x $DAEMON || exit 0
        test -x $FCGI_SPAWN_GRAPH || exit 0
        test -x $FCGI_SPAWN_HTML || exit 0
    
    
    start_graph() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}') ]];then
            local   RUNNING_PID_GRAPH=$(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}')
        fi
    
    
        if [[ -s ${PIDFILE_GRAPH} && ${RUNNING_PID_GRAPH} = $(cat ${PIDFILE_GRAPH}) ]];then
            echo -e "\nMunin-Graph already running"
        elif [[ -n ${RUNNING_PID_GRAPH} && ${RUNNING_PID_GRAPH} != $(cat ${PIDFILE_GRAPH}) && -S ${FCGI_GRAPH_SOCK} ]];then
            echo -e "\nMunin-Graph PID mismatch :: Cleaning up and starting Munin-Graph"
            kill -QUIT ${RUNNING_PID_GRAPH}
            sleep 1
                $DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH > /dev/null 2>&1
        else     
                $DAEMON -s $FCGI_GRAPH_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_GRAPH $FCGI_SPAWN_GRAPH > /dev/null 2>&1
                echo -e "Starting Munin-Graph\n"
        fi
    }
    
    start_html() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}') ]];then
            local   RUNNING_PID_HTML=$(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}')
        fi
    
    
        if [[ -s ${PIDFILE_HTML} && ${RUNNING_PID_HTML} = $(cat ${PIDFILE_HTML}) ]];then
            echo -e "\nMunin-HTML already running"
        elif [[ -n ${RUNNING_PID_HTML} && ${RUNNING_PID_HTML} != $(cat ${PIDFILE_HTML}) && -S ${FCGI_HTML_SOCK} ]];then
                echo -e "\nMunin-HTML PID mismatch :: Cleaning up and starting Munin-HTML"
                kill -QUIT ${RUNNING_PID_HTML}
                    sleep 1
                    $DAEMON -s $FCGI_HTML_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML > /dev/null 2>&1
        else       
                    $DAEMON -s $FCGI_HTML_SOCK -U $WWW_USER -u $FCGI_USER -g $FCGI_GROUP -P $PIDFILE_HTML $FCGI_SPAWN_HTML > /dev/null 2>&1
                    echo -e "Starting Munin-HTML\n"
        fi
    }
    
    stop_graph() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}') ]];then
            local   RUNNING_PID_GRAPH=$(/bin/ps ax | awk '/munin-cgi-graph$/ {print $1}')
        fi
    
        if [[ -s ${PIDFILE_GRAPH} && $(cat ${PIDFILE_GRAPH}) = ${RUNNING_PID_GRAPH} ]];then
            kill -QUIT $(cat ${PIDFILE_GRAPH})
                echo -e "\nMunin-Graph stopped"
            elif [[ -z ${RUNNING_PID_GRAPH} && -s ${PIDFILE_GRAPH} ]];then
                    echo -e "\nGraph PID not found :: Cleaning up PID file"
                    rm ${PIDFILE_GRAPH}
            elif [[ -s ${PIDFILE_GRAPH} && $(cat ${PIDFILE_GRAPH}) != ${RUNNING_PID_GRAPH} ]];then
                    kill -QUIT ${RUNNING_PID_GRAPH}
                    rm ${PIDFILE_GRAPH}
                    echo -e "\nMunin-Graph stopped :: Cleaning up PID file"
        else 
                    echo -e "\nNo Munin-Graph process found"
        fi
    }
    
    stop_html() {
        if [[ $(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}') ]];then
            local   RUNNING_PID_HTML=$(/bin/ps ax | awk '/munin-cgi-html$/ {print $1}')
        fi
    
        if [[ -s ${PIDFILE_HTML} && $(cat ${PIDFILE_HTML}) = ${RUNNING_PID_HTML} ]];then
            kill -QUIT $(cat ${PIDFILE_HTML})
                echo -e "\nMunin-HTML stopped"
            elif [[ -z ${RUNNING_PID_HTML} && -s ${PIDFILE_HTML} ]];then
                echo -e "\nHTML PID not found :: Cleaning up PID file"
                    rm ${PIDFILE_HTML}
            elif [[ -s ${PIDFILE_HTML} && $(cat ${PIDFILE_HTML}) != ${RUNNING_PID_HTML} ]];then
                    kill -QUIT ${RUNNING_PID_HTML}
                    rm ${PIDFILE_HTML}
                    echo -e "\nMunin-HTML stopped :: Cleaning up PID file"
            else 
                    echo -e "\nNo Munin-HTML process found"
        fi
    }
    
    
    case "$1" in
        start)
            echo "Starting $DESC: "
            start_graph
            start_html
            ;;
        start_graph)
            echo "Starting Munin-Graph"
            start_graph
            ;;
        start_html)
            echo "Starting Munin-HTML"
            start_html
            ;;
        stop_graph)
            echo "Stopping Munin_Graph"
            stop_graph
            ;;
        stop_html)
            echo "Stopping Munin-HTML"
            stop_html
            ;;
        stop)
            echo "Stopping $DESC: "
            stop_graph
            stop_html
            ;; 
        restart|reload)
            echo "Restarting $DESC: "
            stop_html
            stop_graph
    
    # One second might not be time enough for a daemon to stop,
    # if this happens, d_start will fail (and dpkg will break if
    # the package is being upgraded). Change the timeout if needed
    # be, or change d_stop to have start-stop-daemon use --retry.
    # Notice that using --retry slows down the shutdown process somewhat.
    
            sleep 5
            start_graph
            start_html
            ;;
        *)
            echo "$(tput setaf 2)Usage: $SCRIPTNAME $(tput setaf 7)$(tput setab 0){start_graph|start_html|stop_graph|stop_html|start|stop|restart|reload}$(tput sgr0) " >&2
            exit 3
            ;;
    esac
    
    exit $?
    

    相关内容