* 200412041544-5: This HOWTO is for 2.6x+. If you keep coming up with errors, look at "man Mail::SpamAssassin::Conf" for more info about local.cf configurations.
* 200505011219-4: 2.6x+ "may" not support SQL (depends on the distro you ended up with), but there's no reason, at this point, for anyone to be using 2.6x. Use SA 3.x+
Since a whole bunch of people have asked, and I keep getting pinned in Chat about it ...
1. Create a database called "spamassassin"
If you're having issues doing that, then try:
CODE
mkdir /var/lib/mysql/spamassassin
chown mysql:root /var/lib/mysql/spamassassin
chown mysql:root /var/lib/mysql/spamassassin
2. Open up phpMyAdmin, and go to the "spamassassin" database and run the following as a Query in the SQL tab:
CODE
CREATE TABLE bayes_expire (
id int(11) NOT NULL default '0',
runtime int(11) NOT NULL default '0',
KEY bayes_expire_idx1 (id)
) TYPE=MyISAM;
CREATE TABLE bayes_global_vars (
variable varchar(30) NOT NULL default '',
value varchar(200) NOT NULL default '',
PRIMARY KEY (variable)
) TYPE=MyISAM;
INSERT INTO bayes_global_vars VALUES ('VERSION','3');
CREATE TABLE bayes_seen (
id int(11) NOT NULL default '0',
msgid varchar(200) binary NOT NULL default '',
flag char(1) NOT NULL default '',
PRIMARY KEY (id,msgid)
) TYPE=MyISAM;
CREATE TABLE bayes_token (
id int(11) NOT NULL default '0',
token char(5) NOT NULL default '',
spam_count int(11) NOT NULL default '0',
ham_count int(11) NOT NULL default '0',
atime int(11) NOT NULL default '0',
PRIMARY KEY (id, token)
) TYPE=MyISAM;
CREATE TABLE bayes_vars (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(200) NOT NULL default '',
spam_count int(11) NOT NULL default '0',
ham_count int(11) NOT NULL default '0',
token_count int(11) NOT NULL default '0',
last_expire int(11) NOT NULL default '0',
last_atime_delta int(11) NOT NULL default '0',
last_expire_reduce int(11) NOT NULL default '0',
oldest_token_age int(11) NOT NULL default '2147483647',
newest_token_age int(11) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE bayes_vars_idx1 (username)
) TYPE=MyISAM;
id int(11) NOT NULL default '0',
runtime int(11) NOT NULL default '0',
KEY bayes_expire_idx1 (id)
) TYPE=MyISAM;
CREATE TABLE bayes_global_vars (
variable varchar(30) NOT NULL default '',
value varchar(200) NOT NULL default '',
PRIMARY KEY (variable)
) TYPE=MyISAM;
INSERT INTO bayes_global_vars VALUES ('VERSION','3');
CREATE TABLE bayes_seen (
id int(11) NOT NULL default '0',
msgid varchar(200) binary NOT NULL default '',
flag char(1) NOT NULL default '',
PRIMARY KEY (id,msgid)
) TYPE=MyISAM;
CREATE TABLE bayes_token (
id int(11) NOT NULL default '0',
token char(5) NOT NULL default '',
spam_count int(11) NOT NULL default '0',
ham_count int(11) NOT NULL default '0',
atime int(11) NOT NULL default '0',
PRIMARY KEY (id, token)
) TYPE=MyISAM;
CREATE TABLE bayes_vars (
id int(11) NOT NULL AUTO_INCREMENT,
username varchar(200) NOT NULL default '',
spam_count int(11) NOT NULL default '0',
ham_count int(11) NOT NULL default '0',
token_count int(11) NOT NULL default '0',
last_expire int(11) NOT NULL default '0',
last_atime_delta int(11) NOT NULL default '0',
last_expire_reduce int(11) NOT NULL default '0',
oldest_token_age int(11) NOT NULL default '2147483647',
newest_token_age int(11) NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE bayes_vars_idx1 (username)
) TYPE=MyISAM;
3. Still in phpMyAdmin, click "Home" on the left. Click "Privileges" on the right. Scroll down a bit and click "Add a New User."
CODE
Username: spamassassin
Host: localhost
Password: spamassassin
Host: localhost
Password: spamassassin
Do not assign any privileges, and hit "Go."
On the next screen, under the "Database-specific privileges" section, set:
CODE
Add privileges on the following database: spamassassin
On the next screen, allow "Select, Insert, Update and Delete" only, and click Go.
Now you've created a user "spamassassin" with the password "spamassassin" and the only permissions the "spamassassin" user has are to make entries, changes and deletions in the "spamassassin" database.
4. Next ... edit /etc/mail/spamassassin/local.cf and make the following changes to the Bayes section --- these will be all you'll need:
CODE
# Enable the Bayes system
bayes_store_module Mail::SpamAssassin::BayesStore::SQL
bayes_sql_dsn DBI:mysql:spamassassin:localhost
bayes_sql_username spamassassin
bayes_sql_password spamassassin
use_bayes 1
bayes_auto_learn 1
bayes_store_module Mail::SpamAssassin::BayesStore::SQL
bayes_sql_dsn DBI:mysql:spamassassin:localhost
bayes_sql_username spamassassin
bayes_sql_password spamassassin
use_bayes 1
bayes_auto_learn 1
Make sure you don't have any bayes_path or any other stuff in the local.cf --- this will do perfectly fine.
5. Make the same change in /home/virtual/FILESYSTEMTEMPLATE/spam_filter/etc/mail/spamassassin/local.cf.
6. Type "service spamassassin restart" (or "service spamd restart" if that comes back with an error).
7. Do your Post Maintenance:
CODE
/usr/local/sbin/set_pre_maintenance
/usr/local/sbin/set_maintenance
/usr/local/sbin/set_post_maintenance
/sbin/service webppliance restart
/usr/local/sbin/set_maintenance
/usr/local/sbin/set_post_maintenance
/sbin/service webppliance restart
...and now you have Global Bayes.
Go ahead and import your Spam and Ham with sa-learn, and you're ready to go.
If you wanna use a centralized database on one server, and have all your others connect to it, just repeat Step 3 and use the IP of the other system in place of "localhost."
Of course, you'd have to open the firewall to your other server ... Incoming Rule from the other server's IP address on port 3306. Not a problem.
The only real issue with this is that Domain Users can see the username and password to the Spamassassin database. Its permissions are explicit ... and you can always back it up using "mysqldump -uspamassassin -pspamassassin --add-drop-table -a spamassassin > 2004xxxx-spamassassin.dump" and restore it just as easily. To me, it's a quick and dirty way to get global Bayes, with an acceptable risk that someone on the local system might wanna be a jerk and mess their mail up ... ;-)