linux中使用munin cgi 动态生成图形文件的方法
2019/10/10/17:46:03 阅读:1979 来源:谷歌SEO算法 标签:
微信公众号
今天有点时间搞了一下munin cgi了,下面我们来看小编整理的一篇关于linux中使用munin cgi 动态生成图形文件的例子,希望对各位有帮助.
今天又弄了一下munin,发现有些图片出不来.
http://phpfensi.com/static/dynazoom.html?cgiurl_graph=/munin-cgi/munin-cgi-graph&plugin_name=xxxxxx 加载图片的地方报404错误.
1,安装munin
请参考:linux munin 服务器监控 安装配置
2,安装munin-nginx
# yum install munin-nginx spawn-fcgi
安装完了以后,在4个地方,会产生重要文件.
- [root@node1www]#ll/etc/nginx/conf.d/|grepmunin
- -rw-r--r--1rootroot142712月3014:11munin.conf//nginx的配置文件
- [root@node1www]#ll/var/www/cgi-bin/
- 总用量24
- -rwxr-xr-x1rootmunin1453011月2703:37munin-cgi-graph//perlcgi程序
- -rwxr-xr-x1rootmunin424511月2703:37munin-cgi-html
- [root@node1www]#ll/etc/init.d/|grepmunin-fcgi
- -rwxr-xr-x1rootroot112312月3019:22munin-fcgi-graph//调用munin-cgi-graph的系统脚本
- -rwxr-xr-x1rootroot103712月2915:59munin-fcgi-html
- [root@node1www]#whereisspawn-fcgi//perl程序的承载器
spawn-fcgi:/usr/bin/spawn-fcgi /usr/share/man/man1/spawn-fcgi.1.gz
在这里注意,/etc/init.d/munin-fcgi-graph,这个文件启动munin-cgi-graph,老是有问题,所以从官方网站找到了启动脚本.
3,修改munin.conf的主配置文件
- [root@node1munin]#catmunin.conf|awk'{if($0!~/^$/&&$0!~/#/){print$0}}'
- dbdir/var/lib/munin
- htmldir/var/www/html/munin
- logdir/var/log/munin
- rundir/var/run/munin
- tmpldir/etc/munin/templates
- includedir/etc/munin/conf.d
- graph_strategycgi//在此处将cron改为cgi
- cgiurl_graph/munin-cgi/munin-cgi-graph
- html_strategycron
- [munin]
- address127.0.0.1
- use_node_nameyes
4,修改nginx的munin虚拟机
- [root@node1www]#cat/etc/nginx/conf.d/munin.conf|awk'{if($0!~/^$/&&$0!~/#/){print$0}}'
- server{
- listen80;
- server_namemunin.51yip.com;//自定义
- root/var/www/html/munin;//muninhtml的根目录
- indexindex.htmlindex.htm;
- location^~/munin-cgi/munin-cgi-graph/{
- fastcgi_split_path_info^(/munin-cgi/munin-cgi-graph)(.*);
- fastcgi_paramPATH_INFO$fastcgi_path_info;
- fastcgi_passunix:/var/run/munin/spawn-fcgi-munin-graph.sock;
- includefastcgi_params;
- }
- }
5,启动脚本
- [root@node1www]#cat/etc/init.d/spawn-fcgi-munin-graph|awk'{if($0!~/^$/&&$0!~/#/){print$0}}'
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- NAME=spawn-fcgi-munin-graph
- PID_FILE=/var/run/munin/$NAME.pid
- SOCK_FILE=/var/run/munin/$NAME.sock
- SOCK_USER=tank//nginx的启动用户
- FCGI_USER=munin
- FCGI_GROUP=munin
- FCGI_WORKERS=2
- DAEMON=/usr/bin/spawn-fcgi
- DAEMON_OPTS="-s$SOCK_FILE-F$FCGI_WORKERS-U$SOCK_USER-u$FCGI_USER-g$FCGI_GROUP-P$PID_FILE--/var/www/cgi-bin/munin-cgi-graph"
- if[!-x$DAEMON];then
- echo"Filenotfoundorisnotexecutable:$DAEMON!"
- exit0
- fi
- status(){
- if[!-r$PID_FILE];then
- return1
- fi
- forFCGI_PIDin`cat$PID_FILE`;do
- if[-z"${FCGI_PID}"];then
- return1
- fi
- FCGI_RUNNING=`ps-p${FCGI_PID}|grep${FCGI_PID}`
- if[-z"${FCGI_RUNNING}"];then
- return1
- fi
- done;
- return0
- }
- start(){
- ifstatus;then
- echo"FCGIisalreadyrunning!"
- exit1
- else
- $DAEMON$DAEMON_OPTS
- fi
- }
- stop(){
- if!status;then
- echo"NoPID-fileat$PID_FILEfoundorPIDnotvalid.Maybenotrunning"
- exit1
- fi
- forPID_RUNNINGin`cat$PID_FILE`;do
- kill-9$PID_RUNNING
- done
- rm-f$PID_FILE
- rm-f$SOCK_FILE
- }
- case"$1"in
- start)
- echo"Starting$NAME:"
- start
- echo"...DONE"
- ;;
- stop)
- echo"Stopping$NAME:"
- stop
- echo"...DONE"
- ;;
- force-reload|restart)
- echo"Stopping$NAME:"
- stop
- echo"Starting$NAME:"
- start
- echo"...DONE"
- ;;
- status)
- ifstatus;then
- echo"FCGIisRUNNING"
- else
- echo"FCGIisNOTRUNNING"
- fi
- ;;
- *)
- echo"Usage:$0{start|stop|force-reload|restart|status}"
- exit1
- ;;
- esac
- exit0
注意:其实上述脚本就是围绕以下命令写的,也可以说上述脚本与以下命令等同.
- #spawn-fcgi-s/var/run/munin/spawn-fcgi-munin-graph.sock-F2-Utank-umunin-gmunin/var/www/cgi-bin/munin-cgi-graph
6,权限设置
# chown tank:munin -R /var/www/cgi-bin/ //tank为nginx启动用户
这一步,非常非常重要,这一步不做的话,图片出不来,nginx会报以下错误,因为这个小问题,费了我好几个小时.
- 2014/12/2918:20:56[error]12263#0:*1connect()tounix:/var/run/munin/spawn-fcgi-munin-graph.sockfailed(111:Connectionrefused)whileconnectingtoupstream,
7,重启相关服务
- #/etc/init.d/nginxrestart
- #/etc/init.d/munin-noderestart
- #chmod+x/etc/init.d/spawn-fcgi-munin-graph
- #/etc/init.d/spawn-fcgi-munin-graphstart
等一会后,久违的图片出来.
热门评论