Installing SpamAssassin on a DirectAdmin server

DirectAdmin Support

Administrator
Staff member
Joined
Feb 27, 2003
Messages
9,158
Hello,

To install SpamAssassin on a DirectAdmin server, follow this guide:
http://help.directadmin.com/item.php?id=36

Note the change to use the:
Code:
/etc/exim.spamassassin.conf
via .include_if_exists in the exim.conf, versus the older way of manually uncommenting the spamcheck_director section.

John
 
I followed the guide from http://help.directadmin.com/item.php?id=36 and started with step 2.
My OS is CentOS 7.

2) Use CustomBuild 2.0 to install SpamAssassin:

cd /usr/local/directadmin/custombuild
./build set spamassassin yes
./build spamassassin

Then checked if spamd was running with step 4.
[root@host custombuild]# ps ax |grep spamd
10782 pts/1 S+ 0:00 grep --color=auto spamd
[root@host custombuild]# service spamd start
Redirecting to /bin/systemctl start spamd.service
Failed to start spamd.service: Unit spamd.service failed to load: No such file or directory.
[root@host custombuild]# ps ax |grep spamd
11899 pts/1 S+ 0:00 grep --color=auto spamd

Any one can help me set this up correctly?

chmod 755 /usr/share/spamassassin
Enabling spamassassin in systemd...
Created symlink from /etc/systemd/system/multi-user.target.wants/spamassassin.service to /etc/systemd/system/spamassassin.service.
It's recommended to have sa_update set to daily in the options.conf file to get SpamAssassin rules updated every day.
Running sa-update.
Starting SpamAssassin.
Job for spamassassin.service failed because the control process exited with error code. See "systemctl status spamassassin.service" and "journalctl -xe" for details.
Restarting exim.

[root@host custombuild]# ps ax |grep spamd
10782 pts/1 S+ 0:00 grep --color=auto spamd
[root@host custombuild]# service spamd start
Redirecting to /bin/systemctl start spamd.service
Failed to start spamd.service: Unit spamd.service failed to load: No such file or directory.
[root@host custombuild]# ps ax |grep spamd
11899 pts/1 S+ 0:00 grep --color=auto spamd

[root@host custombuild]# systemctl status spamassassin.service
spamassassin.service - Spamassassin daemon
Loaded: loaded (/etc/systemd/system/spamassassin.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Wed 2016-05-04 12:52:48 CEST; 21min ago
Process: 32686 ExecStart=/usr/bin/spamd --pidfile /var/run/spamd.pid -d -c -m 15 --ipv4 (code=exited, status=2)

May 04 12:52:48 host.abc.nl systemd[1]: Failed to start Spamassassin daemon.
May 04 12:52:48 host.abc.nl systemd[1]: Unit spamassassin.service entered failed state.
May 04 12:52:48 host.abc.nl systemd[1]: spamassassin.service failed.
May 04 12:52:48 host.abc.nl systemd[1]: spamassassin.service holdoff time over, scheduling restart.
May 04 12:52:48 host.abc.nl systemd[1]: start request repeated too quickly for spamassassin.service
May 04 12:52:48 host.abc.nl systemd[1]: Failed to start Spamassassin daemon.
May 04 12:52:48 host.abc.nl systemd[1]: Unit spamassassin.service entered failed state.
May 04 12:52:48 host.abc.nl systemd[1]: spamassassin.service failed.
 
and started with step 2.
You should have started with step 1.
Code:
yum -y install perl-ExtUtils-MakeMaker perl-Digest-SHA perl-Net-DNS perl-NetAddr-IP perl-Archive-Tar perl-IO-Zlib perl-Digest-SHA perl-Mail-SPF \
perl-IP-Country perl-Razor2 perl-Net-Ident perl-IO-Socket-INET6 perl-IO-Socket-SSL perl-Mail-DKIM perl-DBI perl-Encode-Detect perl-HTML-Parser \
perl-HTML-Tagset perl-Time-HiRes perl-libwww-perl perl-Sys-Syslog
there is a step 1 for a reason. ;)
 
Silly me, I thought custombuild would take care of that.:confused:
It seems only perl-Sys-Syslog was missing.
Also some packages could not be found. Hope they are not vital. (No package perl-IP-Country available. No package perl-Razor2 available. No package perl-Net-Ident available.)


Now spamd is running. Thanks/bedankt for the assistance.
Will now try to set it up/enable in DA.

Code:
[root@host custombuild]# ps ax |grep spamd
15270 ?        Ss     0:01 /usr/bin/spamd --pidfile /var/run/spamd.pid -d -c -m 15 --ipv4
15271 ?        S      0:00 spamd child
15272 ?        S      0:00 spamd child
15804 pts/1    R+     0:00 grep --color=auto spamd
[root@host custombuild]# systemctl status spamassassin.service
● spamassassin.service - Spamassassin daemon
   Loaded: loaded (/etc/systemd/system/spamassassin.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2016-05-04 15:19:21 CEST; 35s ago
  Process: 15268 ExecStart=/usr/bin/spamd --pidfile /var/run/spamd.pid -d -c -m 15 --ipv4 (code=exited, status=0/SUCCESS)
 Main PID: 15270 (/usr/bin/spamd )
   CGroup: /system.slice/spamassassin.service
           ├─15270 /usr/bin/spamd --pidfile /var/run/spamd.pid -d -c -m 15 --ipv4
           ├─15271 spamd child
           └─15272 spamd child

Code:
[root@host ~]# yum -y install perl-ExtUtils-MakeMaker perl-Digest-SHA perl-Net-DNS perl-NetAddr-IP perl-Archive-Tar perl-IO-Zlib perl-Digest-SHA perl-Mail-SPF \
> perl-IP-Country perl-Razor2 perl-Net-Ident perl-IO-Socket-INET6 perl-IO-Socket-SSL perl-Mail-DKIM perl-DBI perl-Encode-Detect perl-HTML-Parser \
> perl-HTML-Tagset perl-Time-HiRes perl-libwww-perl perl-Sys-Syslog
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.denit.net
 * extras: mirror.yourwebhoster.eu
 * updates: mirror.nl.leaseweb.net
Package perl-ExtUtils-MakeMaker-6.68-3.el7.noarch already installed and latest version
Package 1:perl-Digest-SHA-5.85-3.el7.x86_64 already installed and latest version
Package perl-Net-DNS-0.72-5.el7.x86_64 already installed and latest version
Package perl-NetAddr-IP-4.069-3.el7.x86_64 already installed and latest version
Package perl-Archive-Tar-1.92-2.el7.noarch already installed and latest version
Package 1:perl-IO-Zlib-1.10-286.el7.noarch already installed and latest version
Package 1:perl-Digest-SHA-5.85-3.el7.x86_64 already installed and latest version
Package perl-Mail-SPF-2.8.0-4.el7.noarch already installed and latest version
No package perl-IP-Country available.
No package perl-Razor2 available.
No package perl-Net-Ident available.
Package perl-IO-Socket-INET6-2.69-5.el7.noarch already installed and latest version
Package perl-IO-Socket-SSL-1.94-3.el7.noarch already installed and latest version
Package perl-Mail-DKIM-0.39-8.el7.noarch already installed and latest version
Package perl-DBI-1.627-4.el7.x86_64 already installed and latest version
Package perl-Encode-Detect-1.01-13.el7.x86_64 already installed and latest version
Package perl-HTML-Parser-3.71-4.el7.x86_64 already installed and latest version
Package perl-HTML-Tagset-3.20-15.el7.noarch already installed and latest version
Package 4:perl-Time-HiRes-1.9725-3.el7.x86_64 already installed and latest version
Package perl-libwww-perl-6.05-2.el7.noarch already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package perl-Sys-Syslog.x86_64 0:0.33-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                    Arch                              Version                                  Repository                       Size
=============================================================================================================================================================
Installing:
 perl-Sys-Syslog                            x86_64                            0.33-3.el7                               base                             42 k

Transaction Summary
=============================================================================================================================================================
Install  1 Package

Total download size: 42 k
Installed size: 93 k
Downloading packages:
perl-Sys-Syslog-0.33-3.el7.x86_64.rpm                                                                                                 |  42 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : perl-Sys-Syslog-0.33-3.el7.x86_64                                                                                                         1/1
  Verifying  : perl-Sys-Syslog-0.33-3.el7.x86_64                                                                                                         1/1

Installed:
  perl-Sys-Syslog.x86_64 0:0.33-3.el7

Complete!
 
lso some packages could not be found. Hope they are not vital.
Not sure but I don't think so. Just to be sure I always use the cpan stuff.
But that's also because I use additions to be able to use Razor2.
 
Thanks. Installed the missing packages with cpan.
Do you know if centos yum and cpan install the packages in the same location? Are the binaries the same and interchangeable?
 
They install in different locations. But if you only installed the missing ones it normally should not give any issues if you took care of the dependencies needed in cpan.
 
You can also install the EPEL repo;

Code:
yum install epel-release

Now you are able to install the remaining packages such as Razor2. You can check with sa-update -D if all the packages are installed.
 
I know, that's what I was talking about when I said I used some additions to use razor2. :)
Another one I use is the Rule2XSBody plugin next to razor2.
You have to activate this line in the v320pre of spamassassin:
Code:
loadplugin Mail::SpamAssassin::Plugin::Rule2XSBody

The rpmforge release can be used for that too. I now use the epel release because I also use munin nowadays.
 
Last edited:
Enabled epel and activated loadplugin Mail::SpamAssassin::plugin::Rule2XSBody
Thanks for the info.

Installed spamassassin on two servers.
One server notified me tonight by mail: "/bin/sh: /usr/share/spamassassin/sa-update.cron: No such file or directory"
Same message found in "/var/log/sa-update.log"

Checked the other server for /var/log/sa-update.log and found simular output when running sa-update -D manually. So here is the update working ok. But there is no /usr/share/spamassassin/sa-update.cron to be found. Strange!

The setting on the server with the fail message did not had the setting "sa_update=daily" in options.conf. (perhaps this should be added to the tutorial if it isn't set automatically)
After correcting this I ran ./build spamassassin again. Lets hope this corrects the problem.

Below a part of the installation that I am puzzled about. I can't find sa-update.sh in the custombuild dir.
Whereis gives me:
Code:
whereis sa-update.sh
sa-update: /usr/bin/sa-update /usr/share/man/man1/sa-update.1
So I guess it's ok.


Code:
Saving to: '/usr/local/directadmin/custombuild/sa-update.sh'

100%[===================================================================================================================>] 1,254       --.-K/s   in 0s

2016-05-06 11:39:21 (149 MB/s) - '/usr/local/directadmin/custombuild/sa-update.sh' saved [1254/1254]
 
To be honest it took me more work then that.
I made a complete automated system. I don't have a sa-update.sh in /usr/local/directadmin/custombuild either. I'm using CB 2.0.

I changed the update in options.conf to weekly. Then if all is correct it should make a sa-update (without .sh) in /etc/cron.weekly if not I make it myself. So yours should be in /etc/cron.daily. Like this:
Code:
#!/bin/sh
#VERSION=1.0

#Place this into a cron location, such as:
#/etc/cron.weekly/sa-update.sh
#and chmod to 700

LOG=/var/log/sa-udpate.log

if [ -s ${LOG} ]; then
        if [ -e ${LOG}.2 ]; then
                rm -f ${LOG}.2
        fi
        if [ -e ${LOG}.1 ]; then
                mv -f ${LOG}.1 ${LOG}.2
        fi
        mv -f ${LOG} ${LOG}.1
fi 

/usr/bin/sa-update -D --nogpg > ${LOG} 2>&1

RET=$?

if [ "$RET" -ge 4 ]; then
        echo "Error updating SpamAssassin Rules. Code=$RET";
        echo "";
        cat $LOG
else
        killall -9 spamd >/dev/null 2>&1
        /usr/bin/spamd -d -c -m 15 --ipv4 >> ${LOG} 2>&1
fi

exit $RET;

The I take 1 domain and setup the spam settings in there, for example like this (in short):
Delete spam (I don't use spambox by default)
Score on 7.5
Delete on 15
Change header.

Change those values to what you want to have as default values for new users and new domains.

Then I make a directory somewhere, for example I make /root/spamsetting and start copying files made for this 1 domain/user.
Code:
cp /home/user/.spamassassin/user_prefs /root/spamsetting
cp /etc/virtual/domein/filter /root/spamsetting
cp /etc/virtual/domein/filter.conf /root/spamsetting

Now I've got those default settings, I can implement them for any new domain I make automatically by using the custom build scripts domain_create_post and user_create_post.
This is my domain_create_post.sh:
Code:
cp -f /root/spamsetting/filter /etc/virtual/$domain/filter >/dev/null 2>&1
cp -f /root/spamsetting/filter.conf /etc/virtual/$domain/filter.conf >/dev/null 2>&1
chown mail:mail /etc/virtual/$domain/filter
chown mail:mail /etc/virtual/$domain/filter.conf
chmod 640 /etc/virtual/$domain/filter
chmod 600 /etc/virtual/$domain/filter.conf

And the user_create_post.sh
Code:
#!/bin/sh
if [ "$spam" = "ON" ]; then
   DIR=/home/$username/.spamassassin
   mkdir  $DIR
   cp -f /root/spamsetting/user_prefs $DIR/user_prefs         #or this is where you'd copy  the default user_prefs you want them to have, instead of touch".
   chown  ${username}:mail $DIR
   chmod 771 $DIR
   chown $username:$username  $DIR/user_prefs
   chmod 755 $DIR/user_prefs
   touch $DIR/spam
   chown  mail:$username $DIR/spam
   chmod 660 $DIR/spam
fi
exit 0;

By the way, I do "locate spamupdate" and I also find /usr/bin/sa-update next to /etc/cron.weekly/sa-update and the manual and some other stuff.
 
Last edited:
Thanks for your extensive info.
I did find a sa-update in /etc/crond.d, but this obvious is not going to work as there is no /usr/share/spamassassin/sa-update.cron file.

I'm puzzled. I check tomorrow if I get a fail message again. If so then I'll try your cron.

Code:
# *** DO NOT MODIFY THIS FILE ***
### Spamassassin Rules Updates ###
#
# http://wiki.apache.org/spamassassin/RuleUpdates
#
# sa-update automatically updates your rules once per day if a spam daemon like
# spamd or amavisd are running.  You can force sa-update to run in
# /etc/sysconfig/sa-update
#
# /var/log/sa-update.log contains a history log of sa-update runs

10 4 * * * root /usr/share/spamassassin/sa-update.cron 2>&1 | tee -a /var/log/sa-update.log

I think an DA admin needs to look into this. Installing spamassassin and sa updater (custombuild 2.0) are not behaving as expected! :(
 
10 4 * * * root /usr/share/spamassassin/sa-update.cron 2>&1 | tee -a /var/log/sa-update.log
This is quite a difference.
It looks like it's quite different on Centos 7, because if I'm correct you're on Centos 7?

Dit you do a ./build update and ./build spamassassin again after installing the other stuff? Maybe there were some errors during compiling.
 
Yes I'm on CentOS 7.
Today received another fail message about the cron job.
But var/log/sa-update.log now contains also simular output to sa-update -D, so the update has ran.

So sa-update in /etc/crond.d is not necessary. Cron is handled elsewhere.

Here is what I think has happened.
First server installed SpamAssassin version 3.4.1, because it is on files1.
Second server installed SpamAssassin version 3.4.0, because it is on files6 and was not up to date.
Second server did not had sa-update enabled in options.conf.
Couple of hours later I updated SpamAssassin version 3.4.0 to SpamAssassin version 3.4.1 because the CB plugin showed this new version.
So apparently there are differences in setup in 3.4.0 and 3.4.1., that explains the redundant cron job in etc/crond.d
I'll remove this cronjob.

I'll watch everything for a couple of days to see if it is behaving as expected.
I'll report back with my findings.
 
That could well be the case. Looks indeed as if it's installed in another place in Centos 7 and the update is called another way. Good to know that!
 
Well I think everything is working fine now.
Time to fine tune spamassassin.

Does any body know a good thread/guide about it?
 
Back
Top