Jan 042013
 

A typical internet web server, either a WordPress blog, or a site running Joomla, Drupal or other kind of Content Management System, requires at least two services that must be continuously running; an apache web server, and a MySQL DBMS.

But even the in most stable server, it may happen that one of these services meets an unexpected condition that forces it to stop working.

For this reason, it is very desirable to have a “service monitor” script to check periodically the status of these critical services, and perform the required actions when it finds that one of them is not running, such as sending an alert by email, and trying to start it again.

In this post a simple script is presented that monitors the status of the apache and mysql services on a linux server. The sample script can easily be extended to monitor other critical services as well.

Continue reading »

 Posted by at 11:42 am
Dec 152012
 

On a production server, the disk usage tends to grow due to the accumulation of historical data in log files, data stored in the database, etc.
The system administrator normally establishes procedures to compress files and backup old data, intended to keep a reasonable amount of disk space free (in most cases, a minimum of 10% disk free is chosen).

But sometimes, the disk usage may grow unexpectedly of other reasons, such as a failure in a mail server that causes outgoing messages to accumulate in the output queue, or a recurring error in the service that makes a large number of error messages being written to the log files, etc.

In this post we will see how to configure an alert that checks periodically the disk usage, and sends an email if one of the filesystems surveyed has a disk usage greater than a configured threshold.

Continue reading »

 Posted by at 1:26 pm
Jul 072012
 

Temporarily stopping the X server

Sometimes we may need to work in our Debian desktop with the X server not running, for instance when we want to install a new graphics driver. To stop the server:

  1. Close the graphical session by selecting “System->Logout” in the top menu.
  2. Press Ctrl+Alt+F1. This shuts down the X server, and we land in an alphanumerical window. However, the windows manager is still running at this point.
  3. Login as root and run the command “/etc/init.d/gdm3 stop” (you may need to replace “gdm3” with the actual name of the script corresponding to the windows manager installed in your system: “gdm”, “kdm”, xdm”,etc…)

Start again the X server

To start again the X server and the windows manager, we use the same command as in step 3 above, passing it the argument “start” instead of “stop”: “/etc/init.d/gdm3 start”

How to prevent the X server from running at boot time

We can disable the execution of  the X server and windows manager at system boot time with the command:

once again, substitute “gdm3” with the name of the windows manager actually installed (“gdm”, “kdm”, “xdm”,… )

To start manually the X server, login as root and execute “/etc/init.d/gdm3 start”

And to configure again the execution of the X server at system boot time:

 Posted by at 9:46 am
Jun 272012
 

As part of the common administration tasks of a server, it is important to implement a procedure to perform the daily backup of the existing databases.

Our recommmendation is to use an open source bash script named automysqlbackup. This script writes into a compressed files a backup of the database given as argument, and perfoms a weekly rotation of the backup files.

Continue reading »

 Posted by at 2:36 pm
Jun 272012
 

Even if you are a Linux system administrator that can start an interactive session as root user, it is not a good practice to do so, because any error in typing a command can have catastrophic consecuences.

It is preferable to connect instead as a non-privileged user, that can perform the most common server administration tasks, and connect as root only when it is really needed.

Besides, in linux distros such as Ubuntu and Debian there is a ‘sudo’ command that used as a prefix of another command allows non-privileged users to run command that require root privileges.

To start using  ‘sudo’ we install first the corresponding package:

The installation creates a file  ‘/etc/sudoers’ that must be edited to allow the use of this utility to specific users. The default content of this file is:

We can grant to the user ‘simpleuser’ permission to run privileged command by means of ‘sudo’ by adding to the end of the ‘sudoers’  file the line:

With the addition of  “NOPASSWD:”, we avoid that the system requests the password of ‘simpleuser’ each time the sudo command is used.

Once our server is configured as explained, the system administrator can connect as ‘simpleuser’ on a regular basis. Whenever a command that requires privileges has to be executed, it is enough to prefix the command with ‘sudo’. For instance:

And that’s it!

Now, the system administrator can work with much less risk of having an unfortunate incident.

 

 Posted by at 2:04 pm
Apr 262012
 

(Leer este artículo en español)

The main purpose of the rsync command in Linux distributions is to copy contents from an origin to a destination, but it can also be used to state the differences between to directory trees. Besides, both origin and destination can be local, or reside in a remote server.

We comprare directoryA and directoryB using two rsync commands:

The basic usage of the rsync command to copy directoryA to directoryB is:

Warning: It is important to end the origin directory name with the ‘/’  character, because otherwise the rsync would create a subdirectory named ‘directoryA’ under the destination directory ‘directoryB’.

The options “–dry-run -v” tell rsync not to perform any actual copy, but just to print the names of the files that it would copy.

Option “-r” tells rsync to execute recursively.

Option “-c” sets that the file comparison is to be performed by computing a checksum of the content of the files, instead of just comparing the date and size of the files.

Finally, option “–delete” tells rsync to remove existing files in the destination directory, that do not exist in the origin directory (but because of  the –dry-run option, it will just print the names of the files that it would delete, with lines like this: “deleting filename“).

The first of the above rsync commands will print:

    • The names of files existing in both directories, having different content.
    • The names of files existing only on directoryB and not in directoryA (as files to be deleted)

The second command will print:

    • The names of files existing in both directories, having different content (these should be the same as those printed by the first command)
    • The names of files existing only on directoryA and not in directoryB (as files to be deleted)

Example:

By comparing to mediawiki installations wikiA and wikiB, we get the the output:

As we see, in this case LocalSettings.php files exist in both directories, but their content differs, and there are also some images existing only under wikiA, and some images existing only under wikiB.

 

 Posted by at 5:06 pm
Apr 212012
 

(Leer este artículo en español)

In an Apache web server installation in Linux, by default accesses are recorded in a file named access.log in the directory /var/log/apache2.

In the same way, errors are recorded in a file named ‘error.log’ under the same directory.

The problem is that these files keep growing, and this makes difficult the management and analysis of the information in them.

To fix this issue, we can configure the web server to create a new file every day.

The apache config file for our virtual server www.openalfa.com is located in the path ‘/etc/apache2/conf/sites_enabled/001-openalfa’.
Inside this file, in the <VirtualHost> section for this server, we add the directives:

As you can see, we make use of the pipe (“|”) character to redirect to the ‘rotatelogs’ utility the logs of accesses and errors .

The first argument of rotatelogs is the name of the destination file. It uses the parameters %Y, %m, etc. to include the date and time of creation as part of the filename.

The second argument (the number 86400) is the number of second in one day (86400 = 24 * 60 * 60).

Once the configuration file has been edited, we only need to restart the web service to force  the apache server to read the new configuration:

 Posted by at 2:33 pm