Install and configure Munin master on Ubuntu 17.04

Munin master

Introduction

Munin is a monitoring tool that can help analyze resource trends, presenting information in graphs through a web interface. The installation come with a high number of plugins already at your fingertips.

As stated on the official Munin web page, ‘using Munin, you can easily monitor the performance of your computers, networks, SANs, applications, weather measurements and whatever comes to mind. It makes it easy to determine “what’s different today” when a performance problem crops up. It makes it easy to see how you’re doing capacity-wise on any resources.’

Munin is designed around the client-server architecture and can be configured to monitor the machine it’s installed on, called the Munin master, and/or any number of clients, also known as the Munin nodes.

This tutorial explains how to install and configure a Munin master on an Ubuntu 17.04 server.

Getting Started

Install Apache Web Server

First of all, we need a running web server. Munin can run with many web servers, like Nginx and Lighttpd, but, by default, it is written to run with Apache. Today, we will install and use Apache. Apache is available in the Ubuntu repositories, so execute the following apt command to access it:

# apt-get install -y apache2 apache2-utils

The good thing about Munin is that it displays information in graphic format. Those who want the ability to zoom into generated graphs must ensure that the dynazoom functionality works correctly. This means that we need to install the following packages:

# apt-get install -y libcgi-fast-perl libapache2-mod-fcgid

Once the installation process is complete, we must ensure that the fcgid module is enabled. Check using the following command:

$ /usr/sbin/apachectl -M | grep -i cgi

The output should look like this:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

fcgid_module (shared)

The first line is just a warning. You can ignore that message. In fact, Apache will work with Munin even with that “problem”.

If you don’t see the fcgid_module (shared) part, it means that the module is disabled, so, enable it by executing:

# a2enmod fcgid

Install and configure Munin

Apache is correctly installed and running. You can check its status with systemctl:

# systemctl status apache2

apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: 
  Drop-In: /lib/systemd/system/apache2.service.d
           apache2-systemd.conf
   Active: active (running) 

Install Munin

Now, it’s time to install and configure Munin on the Munin master. We will install the version available in the Ubuntu repositories, by executing apt:

# apt-get install munin

Configure Munin

Munin configuration files are stored in the /etc/munin directory. Open the main configuration file (munin.conf) with a text editor:

# $EDITOR /etc/munin/munin.conf

This file is structured with a global section and one (or more, it depends on your configuration) host sections. Search the following lines:

#dbdir  /var/lib/munin
#htmldir /var/cache/munin/www
#logdir /var/log/munin
#rundir  /var/run/munin

# Where to look for the HTML templates
#
#tmpldir        /etc/munin/templates

Change this lines as follows:

dbdir   /var/lib/munin
htmldir /var/www/munin
logdir /var/log/munin
rundir  /var/run/munin

# Where to look for the HTML templates
#
tmpldir /etc/munin/templates

Save and exit.

Create the /var/www/munin directory, like this:

# mkdir -p /var/www/munin

Change its owner, like this:

# chown munin:munin /var/www/munin/

Re-open the Munin main configuration file, /etc/munin/munin.conf and look for the following lines:

[localhost.localdomain]
    address 127.0.0.1
    use_node_name yes

Replace localhost.localdomain with MasterServerMunin.
Save and exit.

In the /etc/munin directory, edit the apache.conf file:

# $EDITOR /etc/munin/apache.conf

There, edit the first line as follow:

Alias /munin /var/www/munin

Next, search for and edit the following block:

<Directory /var/www/munin>
        #Order allow,deny
        #Allow from localhost 127.0.0.0/8 ::1
        #Options None

        Require all granted
         Options FollowSymLinks SymLinksIfOwnerMatch
.............................................
        
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault M310
    </IfModule>

</Directory>

Next edit the following two location blocks:

<Location /munin-cgi/munin-cgi-graph>
        #Order allow,deny
        #Allow from localhost 127.0.0.0/8 ::1
        # AuthUserFile /etc/munin/munin-htpasswd
        # AuthName "Munin"
        # AuthType Basic
        # require valid-user
        Require all granted
        Options FollowSymLinks SymLinksIfOwnerMatch

        <IfModule mod_fcgid.c>
            SetHandler fcgid-script
        </IfModule>
        <IfModule !mod_fcgid.c>
            SetHandler cgi-script
        </IfModule>
</Location>

ScriptAlias /munin-cgi/munin-cgi-html /usr/lib/munin/cgi/munin-cgi-html
<Location /munin-cgi/munin-cgi-html>
        #Order allow,deny
        #Allow from localhost 127.0.0.0/8 ::1
        # AuthUserFile /etc/munin/munin-htpasswd
        # AuthName "Munin"
        # AuthType Basic
        # require valid-user
        
        Require all granted
        Options FollowSymLinks SymLinksIfOwnerMatch

        <IfModule mod_fcgid.c>
            SetHandler fcgid-script
        </IfModule>
        <IfModule !mod_fcgid.c>
            SetHandler cgi-script
        </IfModule>
</Location>

Save and exit.

Restart Apache and Munin:

# systemctl restart apache2
# systemctl restart munin-node

Now, by going with a web browser to the URL http://your-domain-or-ip-address/munin you can access the Munin web interface.

Conclusion

With Munin, monitoring a system becomes easier, especially thanks to the graphic output system used for showing data. This tutorial demonstrated the installation of a Munin master but, as written in the introduction, it is also possible to add and monitor Munin nodes and monitor remote systems as well.