Monday, November 1, 2010

Updating SpamAssassin

SpamAssassin is a popular anti-spam program, that uses content-matching rules to scan email and filter out potential spam. For it to remain effective, it's best to make sure you're running the latest version, and that the rule definitions are updated regularly.

The current version, at time of writing, is 3.3.1 - assuming you're running an older version, let's look at how you would update it:

Note: This example assumes a 64-bit rpm based operating system (i.e. Red Hat or CentOS). If you're running Debian, or a 32-bit OS, please consult the official SpamAssassin website and adjust the instructions accordingly.

First, check which version of SpamAssassin is currently installed by running:

rpm -qa | grep spamassassin

Next, backup the main config file and directories. It's unlikely there will be any problems, but it's always best to make backups before upgrading - just in case...

Make a backup of local.cf and tar up a copy of the spamassassin directory by running:

cp -p /etc/mail/spamassassin/local.cf /etc/mail/spamassassin/BAK-local.cf
cd /usr/share
tar czvf BAK-spamassassin.tar.gz spamassassin/

Once this is done, download the latest tarball into the /usr/src directory:

cd /usr/src
wget http://www.mirrorservice.org/sites/ftp.apache.org//spamassassin/source/Mail-SpamAssassin-3.3.1.tar.gz

You can then use the tarball to build the installation rpms by running:

rpmbuild -tb Mail-SpamAssassin-3.3.1.tar.gz

This will create two rpm files in /usr/src/redhat/RPMS/x86_64/, which can be installed by running:

cd /usr/src/redhat/RPMS/x86_64/
rpm -Uvh perl-Mail-SpamAssassin-3.3.1-1.x86_64.rpm spamassassin-3.3.1-1.x86_64.rpm

Note: Remember to choose the correct path and rpm's for your build. The 64-bit ones are shown in the example.

The new version of SpamAssassin is now installed. Next, you need to update the rules by downloading and unpacking the latest ruleset:

cd /usr/share/spamassassin
wget http://mirror.ox.ac.uk/sites/rsync.apache.org//spamassassin/source/Mail-SpamAssassin-rules-3.3.1.r923114.tgz
tar -xzvf Mail-SpamAssassin-rules-3.3.1.r923114.tgz

This will unpack the new rules into the /usr/share/spamassassin directory.

Next run the SpamAssassin update tool - sa-update - to make sure everything is completely up-to-date. It's often useful to run it with the -D switch (debug mode), as this will display a list of everything that it's updating:

sa-update -D

The updates will be uploaded into the /usr/share/spamassassin/ directory. This directory includes a config file that contains 'Includes' for these new rules, which can be viewed by running:

less /var/lib/spamassassin//updates_spamassassin_org.cf

Next, stop sendmail, or MailScanner (if installed), and make sure that no processes are running before attempting a restart - using 'killall sendmail', if necessary. Then restart sendmail/MailScanner and tail your maillogs to make sure there are no errors.

To make sure the rules are update regularly, you can setup a cronjob to run sa-update each night. Here's an example of what you might add:

0 3 * * * /usr/bin/sa-update &> /dev/null; /etc/init.d/spamd restart

This will run sa-update at 3am every morning, piping any output produced to dev/null, and then restart spamd (the SpamAssassin daemon) to load the new rules.

For more information see: http://spamassassin.apache.org

0 comments:

Post a Comment