(dv) 4.0 - Making It Better :: Installing Munin
- This page was last modified on March 28, 2012, at 09:37.
From (mt) Community Wiki
This is part of the (dv) 4.0 - Making It Better series. Please see the parent article for related articles and information on downloading the script that includes options to automate the instructions included in this article. This series of articles is not directly supported by (mt) Media Temple.
Munin is popular monitoring software that logs all types of server performance and presents and graphed information. It can be a very handy tool for diagnosing "what just happened" situations. The end result of this guide will be to install a basic Munin configuration that has graphical representations of more core performance metrics.
Munin is, essentially, just the messenger. It may or may not produce the exact red flags necessary for troubleshooting any single issue. As with any monitoring service, it should be considered a tool, and not an answer.
-
The first thing we'll do is perform the install. Because the default repository does not include what we need, that needs updated before yum knows what to do:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum -y install munin munin-node
-
Now, we just have to set about configuring what has been installed. First off, we'll make a backup of the original config file (in case you'd like to refer to it later) and create one specific to how this will be set up:
mv /etc/munin/munin.conf /etc/munin/munin.conf-original
cat <<EOF > /etc/munin/munin.conf dbdir /var/lib/munin htmldir /var/www/munin logdir /var/log/munin rundir /var/run/munin tmpldir /etc/munin/templates [localhost] address 127.0.0.1 use_node_name yes EOF
-
Munin comes armed with an incredible number of plug-ins. And it has a user base that add more for custom use every day. The yum installation we used automatically enables monitoring of a number of core system processes; however, there are a few others turned off by default that are specifically for Apache and MySQL, which means they are useful for the (dv) Dedicated-Virtual server environment. This command turns them on by linking into the plugins directory:
for i in apache_accesses apache_processes apache_volume mysql_ mysql_innodb mysql_isam_space_ mysql_queries mysql_slowqueries mysql_threads; do ln -s /usr/share/munin/plugins/$i /etc/munin/plugins/; done
-
In order to make use of all the graphs Munin puts together, there needs to be a directory the data lives in:
mkdir -p /var/www/munin
chown -R munin:munin /var/www/munin
-
In order to make this data web accessible, we add a new apache configuration that aliases to it:
cat <<EOF > /etc/httpd/conf.d/munin.conf Alias /.munin /var/www/munin <Directory /var/www/munin> AuthType Basic AuthName "Munin Login" AuthUserFile /var/www/munin/.htpasswd require valid-user </Directory> EOF
-
And now, login credentials need set. The command below will cause Munin to use Plesk's admin credentials. If you would prefer to use a different username and/or password, simply replace the latter two flags for this command, which are username and password respectively:
htpasswd -bc /var/www/munin/.htpasswd admin $(cat /etc/psa/.psa.shadow)
-
We want Munin's password to stay up to date in case Plesk is ever updated. If you did not want to use Plesk's credentials in the previous command, skip this step.
cat <<EOF > /usr/local/psa/admin/sbin/munin_password_change.sh #!/bin/bash passCheck="$(md5sum /etc/psa/.psa.shadow | awk '{print $1}')" if [[ ! "\$passCheck" = \$(md5sum /etc/psa/.psa.shadow | awk '{print \$1}') ]]; then htpasswd -b /var/www/munin/.htpasswd admin $(cat /etc/psa/.psa.shadow) perl -p -i -e 's/^(passCheck\=\")[^\n]+/passCheck\=\"'\$(md5sum /etc/psa/.psa.shadow | awk '{print \$1}')'\"/' /usr/local/psa/admin/sbin/munin_password_change.sh /etc/init.d/munin-node restart fi EOFecho "* * * * * /usr/local/psa/admin/sbin/munin_password_change.sh" >> /var/spool/cron/root
Unfortunately, Plesk does not currently provide an event handler for the admin password changing, so updating other software with these credentials requires a cron of this nature. -
Make sure that Munin starts on its own on server reboots:
chkconfig --levels 235 munin-node on
-
At this point everything is ready to start. Since both Munin and Apache configurations were updated, both need to restart with the new directives:
/etc/init.d/munin-node restart
/etc/init.d/httpd restart
In order for Munin to gather status for the Apache (httpd) process, you'll need to enable 'ExtendedStatus' by editing the Apache configuration (/etc/httpd/conf/httpd.conf) file. To allow ExtendedStatus,...
enable mod_status.so module if not already enabled
uncomment the following lines:
* Located on line 176 by default
LoadModule status_module modules/mod_status.so
then uncomment the following lines:
* Located on line 217 by default
ExtendedStatus On
* Located on lines 903-908 by default
<Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1 </Location>
In order for Munin to gather status for the MySQL (mysqld) process, you'll need to create a MySQL monitor user.
mysql> CREATE USER 'mysqlmonitor'@'localhost' IDENTIFIED BY '3n9kdS2RzzSB'; mysql> GRANT PROCESS ON *.* TO 'mysqlmonitor'@'localhost'; mysql> FLUSH PRIVILEGES;
Then you will need to edit /etc/munin/plugin-conf.d/munin-node and add the following:
[mysql*] env.mysqlopts -umysqlmonitor -p3n9kdS2RzzSB
Optional: If you have installed Monit using (dv) 4.0 - Making It Better :: Installing Monit you can also add Munin to the list of processes that Monit ensures is running by adding it to Monit's config list:
cat <<EOF > /etc/monit.d/munin.mon check process munin-node with pidfile /var/run/munin/munin-node.pid start program "/etc/init.d/munin-node start" stop program "/etc/init.d/munin-node stop" if cpu > 90% for 5 cycles then restart if 5 restarts within 5 cycles then timeout EOF
You can now view your Munin graphs by browsing to http://your_ip_here/.munin or http://your_domain_here/.munin and logging in with your Plesk admin credentials (*unless you manually chose to use a different username/password). It will take Munin about 5 minutes to start logging data. The homepage will show every graph with the past day and week. Each graph will display a description of what it is displaying by clicking on it, as well as the past month and year.