A method of dynamically generating graphics files using Munin CGI in Linux

Source: Internet
Author: User

Today, I got some munin and found some pictures out of the way.
Http://xxxxxx.com/static/dynazoom.html?cgiurl_graph=/munin-cgi/munin-cgi-graph&plugin_name=xxxxxx
The place where the picture was loaded reported 404 errors.

1, install Munin

Please refer to: Linux munin Server Monitor installation configuration

2, install Munin-nginx

# yum Install Munin-nginx spawn-fcgi
After the installation, in 4 places, will produce important documents

[Root@node1 www]# ll/etc/nginx/conf.d/|grep munin
-rw-r--r--1 root 1427 December 14:11 munin.conf//nginx configuration file

[Root@node1 www]# ll/var/www/cgi-bin/
Total Dosage 24
-rwxr-xr-x 1 root munin 14530 November 03:37 munin-cgi-graph//perl CGI program
-rwxr-xr-x 1 root munin 4245 November 03:37 munin-cgi-html

[Root@node1 www]# ll/etc/init.d/|grep munin-fcgi
-rwxr-xr-x 1 root 1123 December 19:22 munin-fcgi-graph//Call Munin-cgi-graph system script
-rwxr-xr-x 1 root 1037 December 15:59 munin-fcgi-html

[Root@node1 www]# whereis spawn-fcgi//perl program's hosting device
SPAWN-FCGI:/usr/bin/spawn-fcgi/usr/share/man/man1/spawn-fcgi.1.gz
Notice here,/etc/init.d/munin-fcgi-graph, this file starts Munin-cgi-graph, always has a problem, so found the startup script from the official website.

3, modify the munin.conf primary configuration file
 
[root@node1 munin]# cat munin.conf |awk ' {if ($!~/^$/&&am P $!~/#/) {print $}} '  
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& nbsp
Graph_strategy cgi      //change cron here to cgi 
cgiurl_graph/munin-cgi/ munin-cgi-graph 
Html_strategy cron 
[munin] 
 address 127.0.0.1 
 use _node_name yes 

4, modify the Nginx munin virtual machine

[Root@node1 www]# cat/etc/nginx/conf.d/munin.conf |awk ' {if ($!~/^$/&& $!~/#/) {print $}} '
server {
Listen 80;
server_name munin.51yip.com; Custom
Root/var/www/html/munin; root directory of Munin HTML
Index index.html index.htm;

Location ^~/munin-cgi/munin-cgi-graph/{
Fastcgi_split_path_info ^ (/munin-cgi/munin-cgi-graph) (. *);
Fastcgi_param path_info $fastcgi _path_info;
Fastcgi_pass Unix:/var/run/munin/spawn-fcgi-munin-graph.sock;
Include Fastcgi_params;
}
}

5, startup script

[Root@node1 www]# cat/etc/init.d/spawn-fcgi-munin-graph |awk ' {if ($!~/^$/&& $!~/#/) {print $}} '
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 Startup user
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/mu Nin-cgi-graph "
if [!-X $DAEMON]; Then
echo "File not found or are not executable: $DAEMON!"
Exit 0
Fi
Status () {
if [!-R $PID _file]; Then
Return 1
Fi

For Fcgi_pid in ' cat $PID _file '; Todo
If [-Z "${fcgi_pid}"]; Then
Return 1
Fi

Fcgi_running= ' Ps-p ${fcgi_pid} | grep ${fcgi_pid} '
If [-Z "${fcgi_running}"]; Then
Return 1
Fi
Done

return 0
}

Start () {
if status; Then
echo "fcgi is already running!"
Exit 1
Else
$DAEMON $DAEMON _opts
Fi
}
Stop () {
if! Status Then
echo "No pid-file at $PID _file found or PID does not valid. Maybe not Running "
Exit 1
Fi

For pid_running in ' cat $PID _file '; Todo
Kill-9 $PID _running
Done

Rm-f $PID _file

Rm-f $SOCK _file
}
Case "$" 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
if status; Then
echo "fcgi is RUNNING"
Else
echo "fcgi is not RUNNING"
Fi
;;

*)
echo "Usage: $ {Start|stop|force-reload|restart|status}"
Exit 1
;;
Esac
Exit 0
Note that the above script is actually written around the following commands, or that the script above is equivalent to the following command.

# spawn-fcgi-s/var/run/munin/spawn-fcgi-munin-graph.sock-f 2-u tank-u munin-g munin/var/www/cgi-bin/munin-cgi-graph

6, permission settings

# chown Tank:munin-r/var/www/cgi-bin///tank start user for Nginx
This step, very very important, this step does not do, the picture does not come out, Nginx will report the following error, because this small problem, cost me several hours.
2014/12/29 18:20:56 [ERROR] 12263#0: *1 connect () to Unix:/var/run/munin/spawn-fcgi-munin-graph.sock failed (111: Connection refused) while connecting to upstream,

7, restart related services

#/etc/init.d/nginx Restart

#/etc/init.d/munin-node Restart

# chmod +x/etc/init.d/spawn-fcgi-munin-graph

#/etc/init.d/spawn-fcgi-munin-graph Start

Wait a while, after a long absence of pictures come out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.