|
This document assumes you used
http://www200.pair.com/mecham/spam/fc5-maia.html to install Maia. Navigate to where your Bayes data is currently stored: cd /var/amavisd/.spamassassinAs the 'amavis' user (or the user that currently own the Bayes data), we need to create a backup file of our Bayes data that will later be restored to our SQL database. This process may take a while: su amavis -c 'sa-learn --sync --force-expire'
There are two files we need to grab from the source code: wget http://svn.apache.org/repos/asf/spamassassin/branches/3.1/tools/convert_awl_dbm_to_sql
Now we will configure SpamAssassin to use MySQL. Once we do this, don't restart amavisd-new
until we are completely finished. If you have to restart amavisd-new before the process is complete,
set local.cf back the way it was.cp /etc/mail/spamassassin/local.cf /etc/mail/spamassassin/local.cf-pre-sqlvi /etc/mail/spamassassin/local.cfInsert the text below: bayes_store_module Mail::SpamAssassin::BayesStore::SQL bayes_sql_dsn DBI:mysql:maia:localhost bayes_sql_username amavis bayes_sql_password passwd # change ::SQL to ::MySQL if SpamAssassin >= 3.1.0 and MySQL >= 4.1 bayes_sql_override_username amavis auto_whitelist_factory Mail::SpamAssassin::SQLBasedAddrList user_awl_dsn DBI:mysql:maia:localhost user_awl_sql_username amavis user_awl_sql_password passwd |
It is required we initialize the database by learing a message.su amavis -c 'sa-learn --spam gtube.txt'We are now going to load in the data from our old auto-whitelist file. Run these commands to show what arguments are required to run the special program convert_awl_dbm_to_sql. You should still be in the
/var/amavisd/.spamassassin directory where we downloaded this script:
chmod +x convert_awl_dbm_to_sql
Now that you have read and understood what is needed, you may run the program. Edit if necessary; make sure you select, copy and paste the entire text: ./convert_awl_dbm_to_sql --username amavis --dsn DBI:mysql:maia:localhost --dbautowhitelist /var/amavisd/.spamassassin/auto-whitelist --sqlusername amavis --sqlpassword passwd --okNow log in to MySQL and issue these commands so we can see if it worked: mysql -u root -p
USE maia;Assuming you have been using auto-whitelist for at least a little while, you should see some data. Make a note of how many rows are in the set. Now we can quit: quitOK, now let's load in the Bayes data; this may take 5 minutes, or more than an hour and don't be surprised if your CPU load increases substantially during this process:
su amavis -c 'sa-learn --restore backup.txt'
On a healthy system that has been in use for a while there will be between 100,000 and 150,000 rows of data in the Bayes data tables. If you would like to view our progress, open another PuTTY session, log into MySQL, and monitor the progress:
mysql -u root -pYou can use the [up-arrow] to recall commands. While you wait, commands that provide interesting data: SHOW DATABASES;(should show 'amavis') If everything went well, we can quit: quit
And check the database: su amavis -c 'sa-learn --dump magic'
|
The data conversion is complete, now we can test amavisd-new:
amavisd stopSend a test mail through, and observe. You should see: debug: bayes: Database connection established debug: bayes: found bayes db version 3 and if use_auto_whitelist is enabled (rather, is not disabled): debug: SQL Based AWL: Connected to DBI:mysql:maia:localhost ... debug: Post AWL score: 0.0520000000000005 If everything looks OK, stop debugging with [Ctrl]+c and start amavisd-new: amavisd start |
Now we will create a script to keep our auto-whitelist data trim. If you
are currently using my /etc/cron.weekly/trim_whitelist_weekly script, it will need
to be replaced. First let's create a new script:
vi /usr/sbin/trim-awl
and insert (always make sure you hit [Enter] at the end of the last line):
#!/bin/sh
Save and exit the file, then make the script executable:chmod +x /usr/sbin/trim-awl
Now create a file that the script will use for input:
vi /etc/trim-awl.sql
and insert:
USE maia;Save and exit, then create a cron job to run the script: cd /etc/cron.weeklyrm trim_whitelist_weeklyvi trim-sql-awl-weeklyand insert (please verify the paths of the files listed here):
#!/bin/sh
#
# Weekly maintenance of auto-whitelist for Fedora with amavisd-new and
# SpamAssassin using MySQL
test -e /usr/sbin/trim-awl && test -e /usr/sbin/amavisd && {
su - amavis /usr/sbin/trim-awl >/dev/null
}
exit 0
Save and exit, then make it executable:chmod +x trim-sql-awl-weekly
Then, to test it, run it: ./trim-sql-awl-weekly
Assuming you have been using auto_whitelist at least for a few days, log back in to MySQL, and note how many rows of data are in the awl table, compare it to the number I asked you to make a note of earlier. There should be less if the script is working (unless you previously did not have any entries with a 'count' of '1'):
mysql -u root -p
Do you have any free memory?free
Is this maybe an opportunity to reboot? |
|
Optional: If you would like finer control of auto-whitelist maintenance: Log in to mysql and add a new field "lastupdate" to the awl database, and then populate it (initialize it) with today's date: mysql -u root -p
Now, edit the trim-awl.sql file:
vi /etc/trim-awl.sql
and replace the simple-minded:
DELETE FROM awl WHERE count = 1;
with more sophisticated statements:
DELETE FROM awl WHERE lastupdate <= DATE_SUB(SYSDATE(), INTERVAL 6 MONTH);Feel free to modify the time intervals as you see fit. Each time a record is created or modified, the lastupdate field will reflect the current date and time. These statements not only get rid of "single hit" records 15 days or older, but also records with 6 months or more of inactivity. |
Last minute notes: If you upgrade to SpamAssassin 3.1 (does not apply to earler versions), and use MySQL >= 4.1, change:
Mail::SpamAssassin::BayesStore::SQLto:
Mail::SpamAssassin::BayesStore::MySQL
If you would like to make a backup of the Bayes data:
cd /var/amavisd/.spamassassinIf you would like to see how many messages have been learned and how many tokens are in the database: su amavis -c 'sa-learn --dump magic' |