Tuesday, July 31, 2012

munin 2.0.x on centos 6 ( rhel 6 ) nginx


As there's no munin 2.0.x rpm package available for centos, I've to compile it from source.
I've used nginx as the web server and here is the procedure :

yum groupinstall 'development tools' -y
yum remove munin munin-node -y
mv /etc/munin /etc/munin-old
yum-builddep munin
yum install perl-CGI perl-FCGI perl-File-Copy-Recursive perl-Module-Build perl-Cache-Cache git -y
cd /usr/src
wget http://sourceforge.net/projects/munin/files/stable/2.0.4/munin-2.0.17.tar.gz
tar -zxf munin-2.0.17.tar.gz
cd munin-2.0.17
cd dists/redhat
git clone git://pkgs.fedoraproject.org/munin.git


sed -i Makefile -e 's,CONFIG = Makefile.config,CONFIG = dists/redhat/munin/Makefile.config-dist,g'
chown -R nobody /usr/src
sudo -u nobody make
make install
cp dists/redhat/munin/munin-node.rc /etc/init.d/munin-node
chmod a+x /etc/init.d/munin-node
cp dists/redhat/munin/munin.cron.d /etc/cron.d
service crond restart
service munin-node restart
chkconfig munin-node on
chown -R munin /var/www/html/munin/cgi
chown -R munin /var/lib/munin/cgi-tmp
chown -R munin /var/lib/munin/spool
chown -R nobody /var/lib/munin/plugin-state
chmod 775 /var/lib/munin/plugin-state
chmod 666 /var/log/munin/munin-cgi-graph.log
chmod 666 /var/log/munin/munin-cgi-html.log
groupadd munin
useradd munin -g munin -s /sbin/nologin -d /var/www/html/munin

You might test all enabled plugins using the following commads :

cd /etc/munin/plugins
files=`ls -l  | awk '{print $9}'`;for file in $files; do echo -e "**********\n$file :\n"; munin-run $file;done &> ../result


#########################
## nginx configuration ##
#########################
yum install spawn-fcgi -y
cd /etc/init.d
wget http://files.julienschmidt.com/public/cfg/munin/spawn-fcgi-munin-html
wget http://files.julienschmidt.com/public/cfg/munin/spawn-fcgi-munin-graph
sed -i spawn-fcgi-munin-graph -e 's,www-data,apache,g'
sed -i spawn-fcgi-munin-html -e 's,www-data,apache,g'
sed -i spawn-fcgi-munin-graph -e 's,/usr/lib/cgi-bin/munin-cgi-graph,/var/www/html/munin/cgi/munin-cgi-graph,g'
sed -i spawn-fcgi-munin-html -e 's,/usr/lib/cgi-bin/munin-cgi-html,/var/www/html/munin/cgi/munin-cgi-html,g'
chmod a+x spawn-fcgi-munin-html
chmod a+x spawn-fcgi-munin-graph
########
### Before starting the service, try to fix permission errors reported in the munin check
########
munin-check
service spawn-fcgi-munin-html start
service spawn-fcgi-munin-html status
chkconfig spawn-fcgi-munin-html on
service spawn-fcgi-munin-graph start
service spawn-fcgi-munin-graph status
chkconfig spawn-fcgi-munin-graph on
########
## configure /etc/munin/munin.conf
## graph_strategy cgi
## html_strategy cgi
## enable plugins
## cd /etc/munin/plugins
## ln -s /usr/share/munin/plugins/load
########
### nginx rewrites
########
        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;
        }

        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/fcgi-html.sock;
        }
#######
### run the cron and test the stack
#######
sudo -u munin munin-cron

No comments:

Post a Comment