Monday, November 23, 2020

[Howto] Install and configure Munin on Centos 8

Install munin first:

yum install epel-release -y

yum install munin munin-cgi munin-node munin-apache munin-common munin-plugins-ruby -y


Check the services that munin has installed in systemd:

systemctl list-unit-files | grep -i munin

Enable all available munin plugins:

munin-node-configure --shell --families=contrib,auto | sh -x

Start and enable munin-node which collects data on the system, we restrict this service to localhost:

sed -i /etc/munin/munin-node.conf -e "s,^host \*,#host \*,g"

sed -i /etc/munin/munin-node.conf -e "s,^#host 127.0.0.1,host 127.0.0.1,g"

systemctl enable munin-node --now

Enable munin in systemd timer:

sed -i /etc/munin/munin.conf -e "s,#graph_strategy cron,graph_strategy cron,g"

sed -i /etc/munin/munin.conf -e "s,#html_strategy cron,html_strategy cron,g"

sed -i /etc/munin/munin.conf -e "s,#htmldir,htmldir,g"

systemctl enable munin.timer --now


check if munin timer is running properly

systemctl list-timers --all


and finally add a virtualhost to apache or nginx to show the graphs. Check the examples here (Periodically generate graphs and HTML pages).

For apache: 

<VirtualHost _IP_:80>

    ServerName _IP_

    DocumentRoot /var/www/html

    Alias /munin/static/ /etc/munin/static/

    <Directory /etc/munin/static>

        Require all granted

    </Directory>

    # Disabling caching

    RewriteEngine On

    <FilesMatch "\.(html|htm|jpg|png)$">

      FileETag None

      <IfModule mod_headers.c>

        Header unset ETag

        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"

        Header set Pragma "no-cache"

        Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"

      </IfModule>

    </FilesMatch>

    # Password protect the folder

    <Directory /var/www/html>

AuthType Basic

AuthName "restricted area"

AuthUserFile /var/www/.htpasswd

require valid-user

    </Directory>

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

    # ScriptAlias /munin /var/www/html/munin/cgi/munin-cgi-html

    <Directory /var/www/html/munin/cgi>

        Require valid-user

        AuthName "restricted area"

            AuthUserFile /var/www/.htpasswd

        <IfModule mod_fcgid.c>

            SetHandler fcgid-script

        </IfModule>

        <IfModule !mod_fcgid.c>

            SetHandler cgi-script

        </IfModule>

    </Directory>

    CustomLog /var/log/httpd/munin-access.log combined

    ErrorLog  /var/log/httpd/munin-error.log

</VirtualHost>

Create your .htpasswd file :

htpasswd -c /var/www/.htpasswd monit

and reload apache.

for nginx add the following to your monit vhost: 

location = / {

    rewrite ^/$ munin/ redirect; break;

}

location /munin/static/ {

    alias /etc/munin/static/;

    expires modified +1w;

}


location /munin/ {

    auth_basic            "Restricted";

    auth_basic_user_file  /var/www/.htpasswd;

    alias /var/www/html/munin/;

    expires modified +310s;

}

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

    auth_basic            "Restricted";

    auth_basic_user_file  /var/www/.htpasswd;

    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;

}

then run

service nginx reload

systemctl enable munin-cgi-graph.socket --now

How to disable Debian 12 sleep on production servers

 Debian 12 has power saver enabled by default which causes your server to go to sleep if there is no mouse / keyboard interaction. To resolv...