All posts by yorch

Resolving troubleshooting with Munin

This are some problems that you may encounter after installing Munin:

Apache modules are not tracking, so they are not showing statistics, you may want to check Munin logs (specifically /var/log/munin/munin-node.log) to see what is going on.

If you got something like Can’t locate object method “new” via package “LWP::UserAgent”, you need to install the package libwww-perl which contains the LWP::UserAgent required. Thanks to Crowdway.

If you already have installed the libwww-perl package, but Munin is still not showing data, you may need to enable and configure the status module on Apache. Make sure you allow localhost (and the name of the server as well) to access the location server-status on apache2.conf or status.conf. Also, this plugins need the ExtendedStatus flag to be On.

You should have something like:

<IfModule mod_status.c>
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Uncomment and change the "" to allow
# access from other hosts.
ExtendedStatus On
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost ip6-localhost
    Allow from
    #Allow from

Sometimes you can get permission errors on your logs, so the best way to get rid of them is to ensure that all involved files in Munin process are own by munin user and group. We can run as root:

 $ chown -R munin.munin /var/lib/munin /var/log/munin /var/www/munin

There are some plugins that require a parameter to work. For example, those that refer to networking (if_, if_err_, ip_) needs the network interface we want to track. In my case (VPS), this is venet0, but on a usual box it can be eth0.

We can list the available interfaces by running the command:

$ ifconfig

Then, to correctly enable this modules, we need to append the name of the interface:

$ ln -s /usr/share/munin/plugins/if_ /etc/munin/plugins/if_venet0

A convenient way to see the result of each module, we can run them independently:

$ munin-run apache_processes
busy80.value 7
idle80.value 1
$ munin-run if_venet0
down.value 7721322
up.value 37550800

By this command, we can ensure that the plugin is working fine and getting results.

Install Munin on Ubuntu Server

Munin is a small tool for monitoring resources on servers. I think it is very useful, specially on small VPS, that needs to save resources. Reports are written as HTML files, so we will need a Web Server like Apache to see this reports.

First, we install it and add some extra plugins:

$ sudo apt-get install munin munin-plugins-extra

Now, we can make some changes to the default configuration, located at /etc/munin/munin.conf. For example, we can change any of the paths where Munin works:

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

Specially, the htmldir path, where all the reports are written to see through Apache or the one you are using. Remember to move the directory /var/www/munin to where you wanted if you change that configuration line. We can protect this directory with an htaccess file to only give access to some users.

We can configure email notifications if a change occur (like from a OK situation to a WARNING). To do this, we just need to uncomment or add the following line:

contact.someuser.command mail -s "Munin notification"

By default, Munin will monitor localhost, but we can add other boxes (clients), these machines will only need to install munin-node package.

Then, we can enable some plugins (more plugins can be found here and here). To do this, we need to create a symbolic link per each plugin we want to activate. I’m going to enable apache and mysql modules, but you are free to enable the modules you need:

$ cd /etc/munin/plugins
$ sudo ln -s /usr/share/munin/plugins/apache_* .
$ sudo ln -s /usr/share/munin/plugins/mysql_* .

Each time a module is enable or disable, we need to restart the service, so we can do the following:

$ sudo /etc/init.d/munin-node restart

Also, it is recommended to reassign all files on the htmldir to munin user and group by doing:

$ sudo chown munin.munin -R /var/www/munin

And then, to avoid waiting 5 minutes until munin cron runs again, we force it by:

$ sudo /usr/bin/munin-cron --force-root

If we are not completely satisfied with the default template, we can modify it, they are HTML files (with some minor special template tags). Anyone with some knowledge of HTML and CSS can do that. We can even download other already created templates (I have found some errors on that template’s JavaScript, I hope I’ll get some time to post the modified template, in the meanwhile, if anyone need it, please drop me a line to send you the files).

Finally, as this post is not as complete as I would like, I leave some links that may help:

Install VirtualBox Guest Additions on Ubuntu Server

On my work, I have a box with WinXP, running Virtual Box as a host, and a Ubuntu Server 9.10 box as a guest. My problem is that the firewall on the corporate network does not allow Ubuntu to update the date and time against any NTP server (like or So, I need a way to keep the hour updated on the guest. Fortunately, VirtualBox has the ability to synchronize it from the host, the only thing I need to do was to install the Guest Additions package.

To do this, first, we need to click on Devices/Install Guest Additions (from the VirtualBox menu).

Then, on the Ubuntu Server, we install some pre-requisites:

$ aptitude install build-essential linux-headers-$(uname -r) -y

Now, we will mount the virtual CD-ROM (where the Guest Additions are):

$ mount /dev/cdrom /mnt/

And then, run the installer script (there is a 32-bit and 64-bit versions). For 32-bit (which is the most probable, as VirtualBox Open Source only supports 32-bit guests):

$ /mnt/

Or for 64-bit guest:

$ /mnt/

It should install the available modules (like timesync), and drop a fail message saying that X server
was not found, which is OK as we are working with a server without GUI.

Finally, we umount the CD-ROM:

$ umount /mnt/

Now, the guest box time should be sync with the host, so we have one less thing to worry about.

Configuring a Linux Server – Part 1: Sudoer user and SSH

This will be a series of posts about configuring a Linux server (I’m working with Ubuntu, but should work with minor changes with other distributions), mainly because I have done this several times now by reviewing different websites and blogs, so I wanted to do a guide that works for me (and maybe for others too).

First, we create a user to avoid the use of root (in case you are not using the default Ubuntu installation, that asks you to create a user):

$ adduser myuser
Adding user 'myuser' ...
Adding new group 'myuser' (1000) ...
Adding new user 'myuser' (1000) with group 'myuser' ...
Creating home directory '/home/myuser' ...
Copying files from '/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for myuser
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

It is also possible to use the command useradd (that is a linux command itself, not that user-friendly) instead of useradd (this one is a perl script that makes a little more easy user creation).

We need to assign add this user to the sudoers (users that are able to use the sudo command to make changes to the system).

$ visudo

And add the following line:

myuser  ALL=(ALL) ALL

Then, we need to hardening SSH server (be very careful about this modifications because if SSH is the only way you have to configure your server, any error may left you lock out of your box).

Before making any change, we better make a backup of our original config file:

$ cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bk

Then, we need to change the following parameters on /etc/ssh/sshd_config:

  • Port Number: Change it to any random port number, try to use one that any known service uses, see the list of services in here.
  • Listen Address: Instead of listen to every interface on your server, just listen to the main IP address.
  • Protocol: Make sure that this parameter is set to 2 (instead of 2, 1).
  • If possible, avoid root login by disabling PermitRootLogin. All root operations can be done using sudo command (at least on Debian/Ubuntu based distributions). Make sure you have created other users on your box, and add them to the allow list of users to log through SSH (AllowUsers [username1] [username2] parameter).
  • Disable X11Forwarding.
  • Replace password authentication with Public/Private Keys. To do this, make sure your users have their Private Keys and the Public Keys are configured on the server. Then, disable PasswordAuthentication and UsePAM parameters. Make sure that RSAAuthentication and Pubkeyauthentication parameters are enabled.
  • If you have noticed that OpenSSH server may take a while from the moment you enter your username and the password prompt, it is because it tries to make some DNS resolves. You can avoid this by disabling UseDNS parameter.

You should end with a file like this:

ListenAddress XXX.XXX.XXX.XXX
PermitRootLogin no
RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication no
X11Forwarding no
UsePAM no
UseDNS no
AllowUsers myuser user2

Then, we need to restart the SSH server by doing:

$ /etc/init.d/ssh restart

Do not close your current session, just open another to your box using the new port, this way we make sure we are not locked out of it.

On the next post I will be configuring IPTables as a firewall for our box.

UPDATE 17/Apr/2010: Parameter PasswordAuthentication included for disabling keyboard-interactive authentication.

In this link you can find a very good explanation about the main options on SSH config file.

Nullmailer keeps trying to send unsuccessful mails on Ubuntu

I have noticed that my Ubuntu box is lately always trying to reach a SMTP server (detected through Wireshark tool). After reviewing the list of running processes that contains the word mail (running ps aux | grep mail on console), I found a couple of them called Nullmailer that seems the responsible of that and indeed, it was.

So a Google search led me to this thread, where in that case, Nullmailer registered entries on Syslog (which possible happened on my computer also). The messages that Nullmailer was trying to send were related to Cron jobs output. So, the solution was to delete the queue of messages of this program, located on /var/spool/nullmailer/queue/.

Configure Clientexec to send mail using Google Apps

If you use Clientexec as your hosting company’s management and support web application, and Google Apps for your emailing (or even just GMail), then, it is possible to configure Clientexec to send mails through Google SMTP server.

Unfortunately, it is not straightforward because the default Clientexec SMTP mailer (at least until 3.2.3 version of this software) can not handle SSL/TLS as Google required. You will need to manually modify the PHPMailer that is embedded on Clientexec.

The steps are not difficult, here they are:

First, open the file /{clientexec-directory}/newedge/classes/PHPMailer.php

Comment out the following part of the code (around line 537):

if(strstr($hosts[$index], ":"))
  list($host, $port) = explode(":", $hosts[$index]);

And just bellow those line, add the following:

    list($protocol,$hostPort) = explode("://",$hosts[$index]) ;
if(strstr($hostPort, ":"))
    list($host, $port) = explode(":", $hostPort);

Then, on EMail Settings inside Clientexec, use:

User: your-address@your-google-apps-domain

Password: your-google-apps-password

Host: ssl://

Port: 465

Now, Clientexec should be sending mails without problems through your Google Apps email account, and all sent emails will be stored on that account.

Instalar nuevos locales en Ubuntu

Durante la migración de la web de DeChalaca desde el servicio Grid-Service de MediaTemple hacia un nuevo VPS, el último punto que quedó por resolver fue que las fechas en la web se mostraban en inglés (aunque el Joomla estaba configurado para que lo hagan en español). El problema era que el servidor, un flamante Ubuntu 8.04, no tenía instalado las locales del español. La solución fue muy sencilla (como root):

$ cd /usr/share/locales
$ ./install-language-pack es_ES
$ ./install-language-pack es_PE

Para ver la lista de locales que están instalados en el sistema, se utiliza el siguiente comando:

$ locale -a

Convertir un IList en un Array

Existen algunas formas de hacerlo, acá les dejo un par.

Primera forma:

//list es del tipo IList
ArrayList arr = new ArrayList(list);
Item[] items = (Item[])arr.ToArray(typeof(Item));

Otra forma:

Item[] items = new Item[list.Count];
list.CopyTo(items, 0);

Determinar la versión exacta del SQL Server

Para determinar cuál es la versión exacta de un servidor SQL Server (ya sea 2000, 2005 ó 2008), basta con ejecutar la siguiente consulta:

SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')

En mi caso, la consulta me devuelve algo como esto:

9.00.3080.00 SP2 Developer Edition

Para versiones anteriores de SQL Server, podemos utilizar esta otra consulta:


Vía: Microsoft Support